mirror of
https://github.com/solero/houdini.git
synced 2024-11-25 15:07:24 +00:00
New crumbs collections classes for easy crumbs & inventory management
This commit is contained in:
parent
b0f9e2125c
commit
62b9531711
@ -1,4 +1,5 @@
|
|||||||
from Houdini.Data import db
|
from Houdini.Data import db, BaseCrumbsCollection
|
||||||
|
from Houdini.Data.Penguin import PenguinIgloo, PenguinLocation, PenguinFurniture
|
||||||
|
|
||||||
|
|
||||||
class Flooring(db.Model):
|
class Flooring(db.Model):
|
||||||
@ -66,3 +67,30 @@ class Location(db.Model):
|
|||||||
Name = db.Column(db.String(50), nullable=False)
|
Name = db.Column(db.String(50), nullable=False)
|
||||||
Cost = db.Column(db.Integer, nullable=False, server_default=db.text("0"))
|
Cost = db.Column(db.Integer, nullable=False, server_default=db.text("0"))
|
||||||
Patched = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
Patched = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
||||||
|
|
||||||
|
|
||||||
|
class IglooCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Igloo, key='ID', inventory_model=PenguinIgloo,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
|
||||||
|
|
||||||
|
class LocationCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Location, key='ID', inventory_model=PenguinLocation,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
|
||||||
|
|
||||||
|
class FurnitureCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Furniture, key='ID', inventory_model=PenguinFurniture,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
|
||||||
|
|
||||||
|
class FlooringCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(model=Flooring, key='ID')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from Houdini.Data import db
|
from Houdini.Data import db, BaseCrumbsCollection
|
||||||
|
from Houdini.Data.Penguin import PenguinItem
|
||||||
|
|
||||||
|
|
||||||
class Item(db.Model):
|
class Item(db.Model):
|
||||||
@ -14,3 +15,10 @@ class Item(db.Model):
|
|||||||
EPF = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
EPF = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
||||||
Tour = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
Tour = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
||||||
ReleaseDate = db.Column(db.Date, nullable=False, server_default=db.text("now()"))
|
ReleaseDate = db.Column(db.Date, nullable=False, server_default=db.text("now()"))
|
||||||
|
|
||||||
|
|
||||||
|
class ItemCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, model=Item, key='ID', inventory_model=PenguinItem, inventory_id=None):
|
||||||
|
super().__init__(model=model, key=key, inventory_model=inventory_model,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from Houdini.Data import db
|
from Houdini.Data import db, BaseCrumbsCollection
|
||||||
|
from Houdini.Data.Penguin import PenguinPostcard
|
||||||
|
|
||||||
|
|
||||||
class Postcard(db.Model):
|
class Postcard(db.Model):
|
||||||
@ -10,3 +11,8 @@ class Postcard(db.Model):
|
|||||||
Enabled = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
Enabled = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
||||||
|
|
||||||
|
|
||||||
|
class PostcardCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Postcard, key='ID', inventory_model=PenguinPostcard,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from Houdini.Data import db
|
from Houdini.Data import db, BaseCrumbsCollection
|
||||||
|
from Houdini.Data.Penguin import PenguinCard
|
||||||
|
|
||||||
|
|
||||||
class Card(db.Model):
|
class Card(db.Model):
|
||||||
@ -12,3 +13,10 @@ class Card(db.Model):
|
|||||||
Color = db.Column(db.CHAR(1), nullable=False, server_default=db.text("'b'::bpchar"))
|
Color = db.Column(db.CHAR(1), nullable=False, server_default=db.text("'b'::bpchar"))
|
||||||
Value = db.Column(db.SmallInteger, nullable=False, server_default=db.text("2"))
|
Value = db.Column(db.SmallInteger, nullable=False, server_default=db.text("2"))
|
||||||
Description = db.Column(db.String(255), nullable=False, server_default=db.text("''::character varying"))
|
Description = db.Column(db.String(255), nullable=False, server_default=db.text("''::character varying"))
|
||||||
|
|
||||||
|
|
||||||
|
class CardCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Card, key='ID', inventory_model=PenguinCard,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
@ -86,31 +86,31 @@ class PuffleQuest(db.Model):
|
|||||||
CoinsCollected = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
CoinsCollected = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
|
||||||
|
|
||||||
|
|
||||||
t_penguin_igloo = db.Table(
|
class PenguinIgloo(db.Model):
|
||||||
'penguin_igloo', db,
|
__tablename__ = 'penguin_igloo'
|
||||||
db.Column('PenguinID', db.ForeignKey('penguin.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
|
||||||
nullable=False),
|
PenguinID = db.Column(db.ForeignKey('penguin.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
db.Column('IglooID', db.ForeignKey('igloo.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
nullable=False)
|
||||||
nullable=False)
|
IglooID = db.Column(db.ForeignKey('igloo.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
)
|
nullable=False)
|
||||||
|
|
||||||
|
|
||||||
t_penguin_item = db.Table(
|
class PenguinItem(db.Model):
|
||||||
'penguin_item', db,
|
__tablename__ = 'penguin_item'
|
||||||
db.Column('PenguinID', db.ForeignKey('penguin.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
|
||||||
nullable=False),
|
PenguinID = db.Column(db.ForeignKey('penguin.ID', ondelete='CASCADE', onupdate='CASCADE'),
|
||||||
db.Column('ItemID', db.ForeignKey('item.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
primary_key=True, nullable=False)
|
||||||
nullable=False)
|
ItemID = db.Column(db.ForeignKey('item.ID', ondelete='CASCADE', onupdate='CASCADE'),
|
||||||
)
|
primary_key=True, nullable=False)
|
||||||
|
|
||||||
|
|
||||||
t_penguin_location = db.Table(
|
class PenguinLocation(db.Model):
|
||||||
'penguin_location', db,
|
__tablename__ = 'penguin_location'
|
||||||
db.Column('PenguinID', db.ForeignKey('penguin.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
|
||||||
nullable=False),
|
PenguinID = db.Column(db.ForeignKey('penguin.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
db.Column('LocationID', db.ForeignKey('location.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
nullable=False)
|
||||||
nullable=False)
|
LocationID = db.Column(db.ForeignKey('location.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
)
|
nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class PenguinStamp(db.Model):
|
class PenguinStamp(db.Model):
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from Houdini.Data import db
|
from Houdini.Data import db, BaseCrumbsCollection
|
||||||
|
from Houdini.Data.Penguin import PenguinPuffle, PenguinPuffleItem
|
||||||
|
|
||||||
|
|
||||||
class Puffle(db.Model):
|
class Puffle(db.Model):
|
||||||
@ -32,28 +33,42 @@ class PuffleItem(db.Model):
|
|||||||
CleanEffect = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
CleanEffect = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
||||||
|
|
||||||
|
|
||||||
t_puffle_treasure_furniture = db.Table(
|
class PuffleTreasureFurniture(db.Model):
|
||||||
'puffle_treasure_furniture', db,
|
__tablename__ = 'puffle_treasure_furniture'
|
||||||
db.Column('PuffleID', db.ForeignKey('puffle.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
|
||||||
nullable=False),
|
PuffleID = db.Column(db.ForeignKey('puffle.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
db.Column('FurnitureID', db.ForeignKey('furniture.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
nullable=False)
|
||||||
nullable=False)
|
FurnitureID = db.Column(db.ForeignKey('furniture.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
)
|
nullable=False)
|
||||||
|
|
||||||
|
|
||||||
t_puffle_treasure_item = db.Table(
|
class PuffleTreasureItem(db.Model):
|
||||||
'puffle_treasure_item', db,
|
__tablename__ = 'puffle_treasure_item'
|
||||||
db.Column('PuffleID', db.ForeignKey('puffle.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
|
||||||
nullable=False),
|
PuffleID = db.Column(db.ForeignKey('puffle.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
db.Column('ItemID', db.ForeignKey('item.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
nullable=False)
|
||||||
nullable=False)
|
ItemID = db.Column(db.ForeignKey('item.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
)
|
nullable=False)
|
||||||
|
|
||||||
|
|
||||||
t_puffle_treasure_puffle_item = db.Table(
|
class PuffleTreasurePuffleItem(db.Model):
|
||||||
'puffle_treasure_puffle_item', db,
|
__tablename__ = 'puffle_treasure_puffle_item'
|
||||||
db.Column('PuffleID', db.ForeignKey('puffle.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
|
||||||
nullable=False),
|
PuffleID = db.Column(db.ForeignKey('puffle.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
db.Column('PuffleItemID', db.ForeignKey('puffle_item.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
nullable=False)
|
||||||
nullable=False)
|
PuffleItemID = db.Column(db.ForeignKey('puffle_item.ID', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
|
||||||
)
|
nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class PuffleCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Puffle, key='ID', inventory_model=PenguinPuffle,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
|
||||||
|
|
||||||
|
class PuffleItemCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=PuffleItem, key='ID', inventory_model=PenguinPuffleItem,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from Houdini.Data import db
|
from Houdini.Data import db, BaseCrumbsCollection
|
||||||
|
from Houdini.Data.Penguin import PenguinStamp
|
||||||
|
|
||||||
|
|
||||||
class Stamp(db.Model):
|
class Stamp(db.Model):
|
||||||
@ -32,4 +33,11 @@ class CoverStamp(db.Model):
|
|||||||
Y = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
Y = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
||||||
Type = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
Type = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
||||||
Rotation = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
Rotation = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
||||||
Depth = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
Depth = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
|
||||||
|
|
||||||
|
|
||||||
|
class StampCrumbsCollection(BaseCrumbsCollection):
|
||||||
|
|
||||||
|
def __init__(self, inventory_id=None):
|
||||||
|
super().__init__(model=Stamp, key='ID', inventory_model=PenguinStamp,
|
||||||
|
inventory_id=inventory_id)
|
||||||
|
@ -2,3 +2,45 @@ from gino import Gino
|
|||||||
|
|
||||||
db = Gino()
|
db = Gino()
|
||||||
|
|
||||||
|
|
||||||
|
class BaseCrumbsCollection(dict):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self._db = db
|
||||||
|
self._model = kwargs.get('model')
|
||||||
|
self._key = kwargs.get('key')
|
||||||
|
self._inventory_model = kwargs.get('inventory_model')
|
||||||
|
self._inventory_id = kwargs.get('inventory_id')
|
||||||
|
|
||||||
|
self._is_inventory = self._inventory_model is not None and self._inventory_id is not None
|
||||||
|
|
||||||
|
async def get(self, k):
|
||||||
|
if self._is_inventory:
|
||||||
|
return self[k]
|
||||||
|
try:
|
||||||
|
return self[k]
|
||||||
|
except KeyError as e:
|
||||||
|
result = await self._model.query.where(getattr(self._model, self._key) == k).gino.first()
|
||||||
|
if result:
|
||||||
|
self[k] = result
|
||||||
|
return result
|
||||||
|
raise e
|
||||||
|
|
||||||
|
async def __collect(self):
|
||||||
|
query = self._model.load(parent=self._inventory_model).where(
|
||||||
|
self._inventory_model.PenguinID == self._inventory_id
|
||||||
|
) if self._is_inventory else self._model.query
|
||||||
|
|
||||||
|
async with db.transaction():
|
||||||
|
collected = query.gino.iterate()
|
||||||
|
self.update(
|
||||||
|
{getattr(model_instance, self._key): model_instance async for model_instance in collected}
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_collection(cls, *args, **kwargs):
|
||||||
|
cc = cls(*args, **kwargs)
|
||||||
|
await cc.__collect()
|
||||||
|
return cc
|
||||||
|
Loading…
Reference in New Issue
Block a user