Archived
load cards from json
This commit is contained in:
+1
-27
@@ -1,30 +1,4 @@
|
||||
{
|
||||
"effects": {
|
||||
"gold": {},
|
||||
"damage": {},
|
||||
"heal": {},
|
||||
"prepare": {},
|
||||
"stun": {},
|
||||
"sacrifice": {},
|
||||
"draw": {},
|
||||
"draw_and_discard": {},
|
||||
"discard": {},
|
||||
"restack_discarded_champion": {},
|
||||
"restack_discarded_card": {},
|
||||
"stack_next_action_bought": {},
|
||||
"stack_next_card_bought": {}
|
||||
},
|
||||
"times": {
|
||||
"per_other_champion": {},
|
||||
"per_champion": {},
|
||||
"per_cards_of_same_faction": {},
|
||||
"per_other_guard": {}
|
||||
},
|
||||
"effect_types": {
|
||||
"champion_action": {},
|
||||
"sacrifice": {},
|
||||
"faction_combo": {}
|
||||
},
|
||||
"cards": [
|
||||
{
|
||||
"role": "personal",
|
||||
@@ -93,7 +67,7 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 3,
|
||||
"type": "sacrifice"
|
||||
"effect_type": "sacrifice"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
{
|
||||
"effect": "gold",
|
||||
"amount": 1,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
},
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 2,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -13,17 +13,17 @@
|
||||
{
|
||||
"effect": "draw",
|
||||
"amount": 1,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 5,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 6,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -47,7 +47,7 @@
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 6,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -90,13 +90,13 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 3,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
},
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 4,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
}
|
||||
]
|
||||
@@ -124,7 +124,7 @@
|
||||
{
|
||||
"effect": "prepare",
|
||||
"amount": 1,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -141,17 +141,17 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 2,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 3,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "draw",
|
||||
"amount": 1,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -168,17 +168,17 @@
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 2,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "draw",
|
||||
"amount": 1,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 2,
|
||||
"type": "faction_combo",
|
||||
"effect_type": "faction_combo",
|
||||
"times": "per_champion"
|
||||
}
|
||||
]
|
||||
@@ -196,13 +196,13 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 2,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 1,
|
||||
"times": "per_other_guard",
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -219,13 +219,13 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 3,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 1,
|
||||
"times": "per_other_champion",
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -248,7 +248,7 @@
|
||||
{
|
||||
"effect": "prepare",
|
||||
"amount": 1,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -276,7 +276,7 @@
|
||||
{
|
||||
"effect": "gold",
|
||||
"amount": 1,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -293,13 +293,13 @@
|
||||
{
|
||||
"effect": "gold",
|
||||
"amount": 1,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
},
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 1,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1,
|
||||
"times": "per_champion"
|
||||
}
|
||||
@@ -320,7 +320,7 @@
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 6,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -339,12 +339,12 @@
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 5,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
},
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 5,
|
||||
"type": "sacrifice"
|
||||
"effect_type": "sacrifice"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 2,
|
||||
"type": "champion_action"
|
||||
"effect_type": "champion_action"
|
||||
},
|
||||
{
|
||||
"effect": "sacrifice",
|
||||
"amount": 1,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"sub_effects": [
|
||||
{
|
||||
"effect": "damage",
|
||||
@@ -41,21 +41,21 @@
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 1,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
},
|
||||
{
|
||||
"effect": "gold",
|
||||
"amount": 1,
|
||||
"type": "champion_action",
|
||||
"effect_type": "champion_action",
|
||||
"mutex": 1
|
||||
},
|
||||
{
|
||||
"effect": "damage",
|
||||
"amount": 4,
|
||||
"type": "faction_combo"
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
import asyncio
|
||||
from model import Game
|
||||
|
||||
from netcode.ws_server import WebSocketServerProtocol
|
||||
from netcode import WSServer
|
||||
from controller import ClientController, GameController
|
||||
from model import Game
|
||||
|
||||
gameServer = WSServer()
|
||||
|
||||
|
||||
+10
-1
@@ -1,5 +1,14 @@
|
||||
from model.serializable import Serializable
|
||||
from model.card import Card, CardType, CardFaction
|
||||
|
||||
from model.card_validator import (
|
||||
CardRole,
|
||||
CardEffects,
|
||||
CardType,
|
||||
CardFaction,
|
||||
CardParser,
|
||||
)
|
||||
from model.card_loader import load_cards
|
||||
from model.card import Card
|
||||
from model.team import Team
|
||||
from model.player import Player
|
||||
from model.game import Game
|
||||
|
||||
+1
-34
@@ -1,34 +1,4 @@
|
||||
from enum import Enum
|
||||
from model import Serializable
|
||||
|
||||
|
||||
class CardRole(str, Enum):
|
||||
PERSONAL = "personal"
|
||||
MARKET = "market"
|
||||
FIRE_GEM = "fire_gem"
|
||||
|
||||
|
||||
class CardType(str, Enum):
|
||||
"""Playable card types"""
|
||||
|
||||
HERO = "hero"
|
||||
HERO_ABILITY = "hero_ability"
|
||||
CURRENCY = "currency"
|
||||
WEAPON = "weapon"
|
||||
CHAMPION = "champion"
|
||||
ACTION = "action"
|
||||
ITEM = "item"
|
||||
|
||||
|
||||
class CardFaction(str, Enum):
|
||||
"""Playable card factions"""
|
||||
|
||||
BASE = "base"
|
||||
|
||||
BLUE = "blue"
|
||||
RED = "red"
|
||||
GREEN = "green"
|
||||
YELLOW = "yellow"
|
||||
from model import Serializable, CardRole, CardType, CardFaction
|
||||
|
||||
|
||||
class Card(Serializable):
|
||||
@@ -37,7 +7,6 @@ class Card(Serializable):
|
||||
object_type = "card"
|
||||
sprite: str
|
||||
name: str
|
||||
text: str
|
||||
cost: int
|
||||
role: CardRole
|
||||
card_type: CardType
|
||||
@@ -47,7 +16,6 @@ class Card(Serializable):
|
||||
self,
|
||||
sprite: str,
|
||||
name: str,
|
||||
text: str,
|
||||
cost: int,
|
||||
card_type: CardType,
|
||||
faction: CardFaction,
|
||||
@@ -55,7 +23,6 @@ class Card(Serializable):
|
||||
super().__init__()
|
||||
self.sprite = sprite
|
||||
self.name = name
|
||||
self.text = text
|
||||
self.cost = cost
|
||||
self.card_type = card_type
|
||||
self.faction = faction
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from json import JSONDecodeError
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from typing import List
|
||||
|
||||
from model.card_validator import CardParser
|
||||
|
||||
|
||||
class CardContainerFile(BaseModel):
|
||||
cards: List[CardParser]
|
||||
|
||||
|
||||
def load_cards():
|
||||
cards = []
|
||||
for p in Path("./src/cards").glob("**/*.json"):
|
||||
print("loading " + p.name)
|
||||
with open(p, encoding="UTF-8") as f_in:
|
||||
try:
|
||||
data = CardContainerFile.model_validate_json(f_in.read())
|
||||
for c in data.cards:
|
||||
cards.append(c)
|
||||
except JSONDecodeError as e:
|
||||
print("Not a valid JSON file : " + p.name + " : " + str(e))
|
||||
except ValidationError as e:
|
||||
print("Incorrect or missing JSON data : " + p.name + " : " + str(e))
|
||||
return cards
|
||||
@@ -0,0 +1,82 @@
|
||||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CardRole(str, Enum):
|
||||
PERSONAL = "personal"
|
||||
MARKET = "market"
|
||||
FIRE_GEM = "fire_gem"
|
||||
|
||||
|
||||
class CardType(str, Enum):
|
||||
"""Playable card types"""
|
||||
|
||||
HERO = "hero"
|
||||
HERO_ABILITY = "hero_ability"
|
||||
CURRENCY = "currency"
|
||||
WEAPON = "weapon"
|
||||
CHAMPION = "champion"
|
||||
ACTION = "action"
|
||||
ITEM = "item"
|
||||
|
||||
|
||||
class CardFaction(str, Enum):
|
||||
"""Playable card factions"""
|
||||
|
||||
BASE = "base"
|
||||
|
||||
BLUE = "blue"
|
||||
RED = "red"
|
||||
GREEN = "green"
|
||||
YELLOW = "yellow"
|
||||
|
||||
|
||||
class CardEffects(str, Enum):
|
||||
GOLD = "gold"
|
||||
DAMAGE = "damage"
|
||||
HEAL = "heal"
|
||||
PERPARE = "prepare"
|
||||
STUN = "stun"
|
||||
SACRIFICE = "sacrifice"
|
||||
DRAW = "draw"
|
||||
DRAW_AND_DISCARD = "draw_and_discard"
|
||||
DISCARD = "discard"
|
||||
RESTACK_DISCARDED_CHAMPION = "restack_discarded_champion"
|
||||
RESTACK_DISCARDED_CARD = "restack_discarded_card"
|
||||
STACK_NEXT_ACTION_BOUGHT = "stack_next_action_bought"
|
||||
STACK_NEXT_CARD_BOUGHT = "stack_next_card_bough"
|
||||
|
||||
|
||||
class EffectTimes(str, Enum):
|
||||
PER_CHAMPION = "per_champion"
|
||||
PER_OTHER_CHAMPION = "per_other_champion"
|
||||
PER_OTHER_GUARD = "per_other_guard"
|
||||
PER_CARD_OF_SAME_FACTION = "per_card_of_same_faction"
|
||||
|
||||
|
||||
class EffectType(str, Enum):
|
||||
CHAMPION_ACTION = "champion_action"
|
||||
SACRIFICE = "sacrifice"
|
||||
FACTION_COMBO = "faction_combo"
|
||||
|
||||
|
||||
class Effect(BaseModel):
|
||||
effect: str
|
||||
amount: int
|
||||
effect_type: Optional[EffectType] = None
|
||||
sub_effects: Optional[List["Effect"]] = None
|
||||
mutex: Optional[int] = None
|
||||
|
||||
|
||||
class CardParser(BaseModel):
|
||||
role: CardRole
|
||||
card_type: CardType
|
||||
faction: CardFaction
|
||||
name: str
|
||||
init_amount: int
|
||||
cost: Optional[int] = None
|
||||
defense: Optional[int] = None
|
||||
guard: Optional[bool] = None
|
||||
init_amount: int
|
||||
effects: List[Effect]
|
||||
+13
-3
@@ -1,7 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
from typing import List, Callable, Awaitable, Any
|
||||
from typing import List
|
||||
|
||||
from model import Card, CardType, CardFaction, Player, Team, Serializable
|
||||
from model import (
|
||||
Card,
|
||||
CardType,
|
||||
CardFaction,
|
||||
CardParser,
|
||||
Player,
|
||||
Team,
|
||||
Serializable,
|
||||
load_cards,
|
||||
)
|
||||
|
||||
|
||||
class Game(Serializable):
|
||||
@@ -9,6 +18,7 @@ class Game(Serializable):
|
||||
|
||||
object_type = "game"
|
||||
|
||||
loaded_cards: List[CardParser] = load_cards()
|
||||
cards: List[Card]
|
||||
market_stack: List[Card]
|
||||
market: List[Card]
|
||||
@@ -40,7 +50,6 @@ class Game(Serializable):
|
||||
faction=CardFaction.BLUE,
|
||||
cost=1,
|
||||
name="test",
|
||||
text="testtext",
|
||||
sprite="testsprite",
|
||||
)
|
||||
self.cards.append(card)
|
||||
@@ -98,6 +107,7 @@ class Game(Serializable):
|
||||
|
||||
def serialize_guest(self) -> dict:
|
||||
return super().serialize_guest() | {
|
||||
"loaded_cards": None,
|
||||
"cards": [card.uuid for card in self.cards],
|
||||
"market_stack": [None for card in self.market_stack],
|
||||
"market": [None if card is None else card.uuid for card in self.market],
|
||||
|
||||
Reference in New Issue
Block a user