diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-01-24 00:27:50 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:44 +0100 |
| commit | 73d40903aecad3efcf7c6055c133f0db86558203 (patch) | |
| tree | e9c8f00fb186e270da92f273f570579f2d0b0d95 /go/game/card.go | |
| parent | fbba48698d8f8b83dfd7d914b0e37338e0d4e2ef (diff) | |
| download | muhqs-game-73d40903aecad3efcf7c6055c133f0db86558203.tar.gz muhqs-game-73d40903aecad3efcf7c6055c133f0db86558203.zip | |
intermediate commit
Diffstat (limited to 'go/game/card.go')
| -rw-r--r-- | go/game/card.go | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/go/game/card.go b/go/game/card.go index 8576a29e..87bbe723 100644 --- a/go/game/card.go +++ b/go/game/card.go @@ -5,6 +5,7 @@ import ( "log" "net/http" "path" + "strings" "gopkg.in/yaml.v3" ) @@ -18,7 +19,7 @@ const ( ArtifactType EquipmentType PotionType - ItentionType + IntentionType ) func (ct CardType) String() string { @@ -35,8 +36,8 @@ func (ct CardType) String() string { return "equipment" case PotionType: return "potion" - case ItentionType: - return "itention" + case IntentionType: + return "intention" } log.Panicf("Switch not exhausting %d", ct) return "" @@ -48,14 +49,14 @@ var CardTypes = struct { Artifact CardType Equipment CardType Potion CardType - Itention CardType + Intention CardType }{ Unit: UnitType, Spell: SpellType, Artifact: ArtifactType, Equipment: EquipmentType, Potion: PotionType, - Itention: ItentionType, + Intention: IntentionType, } var CardTypeNames = map[string]CardType{ @@ -64,18 +65,20 @@ var CardTypeNames = map[string]CardType{ "artifact": ArtifactType, "equipment": EquipmentType, "potion": PotionType, - "itention": ItentionType, + "intention": IntentionType, } const ( CARD_DATA_URL string = "data/cards" + NOT_BUYABLE int = -1 ) type Card struct { - Name string - Set SetIdentifier - Type CardType - Values map[string]interface{} + Name string + Set SetIdentifier + Type CardType + BuyCost int + Values map[string]interface{} } var cards = map[string]map[string][]byte{} @@ -103,8 +106,8 @@ func (card *Card) parseDefinition(definition []byte) { log.Fatalf("parsing %s failed with: %v\n", definition, err) } - name, ok := data["name"] - if !ok { + name, found := data["name"] + if !found { log.Fatalf("no name in card yaml %s\n", definition) } delete(data, "name") @@ -119,14 +122,20 @@ func (card *Card) parseDefinition(definition []byte) { log.Fatalf("Unexpected type %T of yml card field 'Name'\n", name) } - t, ok := data["type"] - if !ok { + t, found := data["type"] + if !found { log.Fatalf("no type in card yaml %s\n", definition) } delete(data, "type") card.Type = CardTypeNames[t.(string)] + bc, found := data["buy"] + if found { + card.BuyCost = bc.(int) + } + delete(data, "buy") + for k, v := range data { card.Values[k.(string)] = v } @@ -165,7 +174,15 @@ func NewCard(cardPath string) *Card { cards[set][cardName] = cardDefinition } - c := Card{"", SetIdentifierNames[set], UndefinedCardType, map[string]interface{}{}} + c := Card{"", SetIdentifierNames[set], UndefinedCardType, -1, map[string]interface{}{}} c.parseDefinition(cardDefinition) return &c } + +func (c *Card) Path() string { + return path.Join(c.Set.String(), strings.ToLower(c.Name)) +} + +func (c *Card) IsPermanent() bool { + return c.Type != UndefinedCardType && c.Type != SpellType && c.Type != IntentionType +} |
