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": [
|
"cards": [
|
||||||
{
|
{
|
||||||
"role": "personal",
|
"role": "personal",
|
||||||
@@ -93,7 +67,7 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 3,
|
"amount": 3,
|
||||||
"type": "sacrifice"
|
"effect_type": "sacrifice"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,16 @@
|
|||||||
{
|
{
|
||||||
"effect": "gold",
|
"effect": "gold",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 2,
|
"amount": 2,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -13,17 +13,17 @@
|
|||||||
{
|
{
|
||||||
"effect": "draw",
|
"effect": "draw",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 5,
|
"amount": 5,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 6,
|
"amount": 6,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 6,
|
"amount": 6,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -90,13 +90,13 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 3,
|
"amount": 3,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 4,
|
"amount": 4,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
{
|
{
|
||||||
"effect": "prepare",
|
"effect": "prepare",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -141,17 +141,17 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 2,
|
"amount": 2,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 3,
|
"amount": 3,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "draw",
|
"effect": "draw",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -168,17 +168,17 @@
|
|||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 2,
|
"amount": 2,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "draw",
|
"effect": "draw",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 2,
|
"amount": 2,
|
||||||
"type": "faction_combo",
|
"effect_type": "faction_combo",
|
||||||
"times": "per_champion"
|
"times": "per_champion"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -196,13 +196,13 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 2,
|
"amount": 2,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"times": "per_other_guard",
|
"times": "per_other_guard",
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -219,13 +219,13 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 3,
|
"amount": 3,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"times": "per_other_champion",
|
"times": "per_other_champion",
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -248,7 +248,7 @@
|
|||||||
{
|
{
|
||||||
"effect": "prepare",
|
"effect": "prepare",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -276,7 +276,7 @@
|
|||||||
{
|
{
|
||||||
"effect": "gold",
|
"effect": "gold",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -293,13 +293,13 @@
|
|||||||
{
|
{
|
||||||
"effect": "gold",
|
"effect": "gold",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1,
|
"mutex": 1,
|
||||||
"times": "per_champion"
|
"times": "per_champion"
|
||||||
}
|
}
|
||||||
@@ -320,7 +320,7 @@
|
|||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 6,
|
"amount": 6,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -339,12 +339,12 @@
|
|||||||
{
|
{
|
||||||
"effect": "heal",
|
"effect": "heal",
|
||||||
"amount": 5,
|
"amount": 5,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 5,
|
"amount": 5,
|
||||||
"type": "sacrifice"
|
"effect_type": "sacrifice"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 2,
|
"amount": 2,
|
||||||
"type": "champion_action"
|
"effect_type": "champion_action"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "sacrifice",
|
"effect": "sacrifice",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"sub_effects": [
|
"sub_effects": [
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
@@ -41,21 +41,21 @@
|
|||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "gold",
|
"effect": "gold",
|
||||||
"amount": 1,
|
"amount": 1,
|
||||||
"type": "champion_action",
|
"effect_type": "champion_action",
|
||||||
"mutex": 1
|
"mutex": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"effect": "damage",
|
"effect": "damage",
|
||||||
"amount": 4,
|
"amount": 4,
|
||||||
"type": "faction_combo"
|
"effect_type": "faction_combo"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import asyncio
|
import asyncio
|
||||||
from model import Game
|
|
||||||
|
|
||||||
from netcode.ws_server import WebSocketServerProtocol
|
from netcode.ws_server import WebSocketServerProtocol
|
||||||
from netcode import WSServer
|
from netcode import WSServer
|
||||||
from controller import ClientController, GameController
|
from controller import ClientController, GameController
|
||||||
|
from model import Game
|
||||||
|
|
||||||
gameServer = WSServer()
|
gameServer = WSServer()
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -1,5 +1,14 @@
|
|||||||
from model.serializable import Serializable
|
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.team import Team
|
||||||
from model.player import Player
|
from model.player import Player
|
||||||
from model.game import Game
|
from model.game import Game
|
||||||
|
|||||||
+1
-34
@@ -1,34 +1,4 @@
|
|||||||
from enum import Enum
|
from model import Serializable, CardRole, CardType, CardFaction
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
class Card(Serializable):
|
class Card(Serializable):
|
||||||
@@ -37,7 +7,6 @@ class Card(Serializable):
|
|||||||
object_type = "card"
|
object_type = "card"
|
||||||
sprite: str
|
sprite: str
|
||||||
name: str
|
name: str
|
||||||
text: str
|
|
||||||
cost: int
|
cost: int
|
||||||
role: CardRole
|
role: CardRole
|
||||||
card_type: CardType
|
card_type: CardType
|
||||||
@@ -47,7 +16,6 @@ class Card(Serializable):
|
|||||||
self,
|
self,
|
||||||
sprite: str,
|
sprite: str,
|
||||||
name: str,
|
name: str,
|
||||||
text: str,
|
|
||||||
cost: int,
|
cost: int,
|
||||||
card_type: CardType,
|
card_type: CardType,
|
||||||
faction: CardFaction,
|
faction: CardFaction,
|
||||||
@@ -55,7 +23,6 @@ class Card(Serializable):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.sprite = sprite
|
self.sprite = sprite
|
||||||
self.name = name
|
self.name = name
|
||||||
self.text = text
|
|
||||||
self.cost = cost
|
self.cost = cost
|
||||||
self.card_type = card_type
|
self.card_type = card_type
|
||||||
self.faction = faction
|
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
|
#!/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):
|
class Game(Serializable):
|
||||||
@@ -9,6 +18,7 @@ class Game(Serializable):
|
|||||||
|
|
||||||
object_type = "game"
|
object_type = "game"
|
||||||
|
|
||||||
|
loaded_cards: List[CardParser] = load_cards()
|
||||||
cards: List[Card]
|
cards: List[Card]
|
||||||
market_stack: List[Card]
|
market_stack: List[Card]
|
||||||
market: List[Card]
|
market: List[Card]
|
||||||
@@ -40,7 +50,6 @@ class Game(Serializable):
|
|||||||
faction=CardFaction.BLUE,
|
faction=CardFaction.BLUE,
|
||||||
cost=1,
|
cost=1,
|
||||||
name="test",
|
name="test",
|
||||||
text="testtext",
|
|
||||||
sprite="testsprite",
|
sprite="testsprite",
|
||||||
)
|
)
|
||||||
self.cards.append(card)
|
self.cards.append(card)
|
||||||
@@ -98,6 +107,7 @@ class Game(Serializable):
|
|||||||
|
|
||||||
def serialize_guest(self) -> dict:
|
def serialize_guest(self) -> dict:
|
||||||
return super().serialize_guest() | {
|
return super().serialize_guest() | {
|
||||||
|
"loaded_cards": None,
|
||||||
"cards": [card.uuid for card in self.cards],
|
"cards": [card.uuid for card in self.cards],
|
||||||
"market_stack": [None for card in self.market_stack],
|
"market_stack": [None for card in self.market_stack],
|
||||||
"market": [None if card is None else card.uuid for card in self.market],
|
"market": [None if card is None else card.uuid for card in self.market],
|
||||||
|
|||||||
Reference in New Issue
Block a user