Skip to content

Commit

Permalink
return keywords.card
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsui committed Apr 23, 2021
1 parent 6336e3f commit ac93000
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
9 changes: 2 additions & 7 deletions cardobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ func UnmarshalRaw(data []byte) (*cardobject.Card, error) {

/*UnmarshalKeyworded deserializes a keyworded card-json to a validated cardobject.card.
*/
func UnmarshalKeyworded(data []byte) (*cardobject.Card, error) {
func UnmarshalKeyworded(data []byte) (*keywords.Card, error) {
keywordedCard, err := keywords.Unmarshal(data)
if err != nil {
return nil, err
}
resolvedCard := keywordedCard.Resolve()
err = resolvedCard.Validate()
if err != nil {
return &resolvedCard, err
}
return &resolvedCard, nil
return keywordedCard, nil
}
2 changes: 1 addition & 1 deletion keywordedSchema.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Card":{"$ref":"#/definitions/card"},"definitions":{"Attack":{"type":"int","name":"Attack","max":32},"CardName":{"type":"string","name":"Card Name","max":32,"min":1},"CastingCost":{"type":"int","name":"Casting Cost","max":32},"Class":{"type":"struct","name":"Class","description":"Build a Class","children":{"Nature":{"$ref":"#/definitions/Nature"},"Mysticism":{"$ref":"#/definitions/Mysticism"},"Technology":{"$ref":"#/definitions/Technology"},"Culture":{"$ref":"#/definitions/Culture"}},"required":["Nature","Mysticism","Technology","Culture"],"interactionText":"§Nature §Mysticism §Technology §Culture"},"Culture":{"type":"bool","name":"Culture"},"Delay":{"type":"int","name":"Delay","max":32},"FlavourText":{"type":"string","name":"Flavour Text","max":1000},"Health":{"type":"int","name":"Health","max":32},"Keyword":{"type":"string","name":"Keyword","max":10000},"Keywords":{"type":"array","name":"Keywords","description":"Add some Keywords","children":{"Keyword":{"$ref":"#/definitions/Keyword"}},"max":3,"min":1},"Mysticism":{"type":"bool","name":"Mysticism"},"Nature":{"type":"bool","name":"Nature"},"RulesText":{"type":"string","name":"Rules Text","max":1000},"SimpleIntValue":{"type":"int","name":"Simple Int Value","max":32},"Tag":{"type":"enum","name":"Tag","enum":["ANIMAL","BOT","DWARF","ENGINEER","EQUIPMENT","FARM","FIRE","HUMAN","KNIGHT","MAGIC","MILITANT","PRIMITIVE","RANGE","SPIRITUAL","TACTIC","TECHNOCRAT"]},"Tags":{"type":"array","name":"Tags","description":"Add some Tags","children":{"Tag":{"$ref":"#/definitions/Tag"}},"max":3,"min":1},"Technology":{"type":"bool","name":"Technology"},"abilities":{"type":"array","name":"Abilities","description":"Add some Abilities","children":{"Ability":{"$ref":"#/definitions/ability"}},"max":3},"ability":{"type":"interface","name":"Ability","description":"Choose a Ability","children":{"Arrival":{"$ref":"#/definitions/arrival"},"Battlecry":{"$ref":"#/definitions/battlecry"},"OnConstruction":{"$ref":"#/definitions/onConstruction"},"OnDeath":{"$ref":"#/definitions/onDeath"},"OnSpawn":{"$ref":"#/definitions/onSpawn"},"Pay":{"$ref":"#/definitions/pay"},"Periodic":{"$ref":"#/definitions/periodic"},"Tribute":{"$ref":"#/definitions/tribute"}}},"action":{"type":"struct","name":"Action","description":"Build a Action","children":{"CardName":{"$ref":"#/definitions/CardName"},"CastingCost":{"$ref":"#/definitions/CastingCost"},"Class":{"$ref":"#/definitions/Class"},"Effects":{"$ref":"#/definitions/effects"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","CastingCost","Class","Effects","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §CastingCost §Class §Effects §FlavourText §Tags §Keywords §RulesText"},"anthem":{"type":"struct","name":"Anthem","description":"Build a Anthem","children":{"Tag":{"$ref":"#/definitions/Tag"}},"required":["Tag"],"interactionText":"Anthem §Tag."},"arm":{"type":"struct","name":"Arm","description":"Build a Arm","children":{"Amount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["Amount"],"interactionText":"Arm §Amount."},"arrival":{"type":"struct","name":"Arrival","description":"Build a Arrival","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When another entity spawns activate: §Effects."},"battlecry":{"type":"struct","name":"Battlecry","description":"Build a Battlecry","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"At the beginning of each combat activate: §Effects."},"card":{"type":"interface","name":"Card","description":"Choose a Card","children":{"Action":{"$ref":"#/definitions/action"},"Entity":{"$ref":"#/definitions/entity"},"Place":{"$ref":"#/definitions/place"},"Headquarter":{"$ref":"#/definitions/headquarter"}}},"effect":{"type":"interface","name":"Effect","description":"Choose a Effect","children":{"Anthem":{"$ref":"#/definitions/anthem"},"Arm":{"$ref":"#/definitions/arm"},"Harm":{"$ref":"#/definitions/harm"},"Kill":{"$ref":"#/definitions/kill"},"Produce":{"$ref":"#/definitions/produce"},"Repair":{"$ref":"#/definitions/repair"}}},"effects":{"type":"array","name":"Effects","description":"Add some Effects","children":{"Effect":{"$ref":"#/definitions/effect"}},"max":3},"entity":{"type":"struct","name":"Entity","description":"Build a Entity","children":{"CardName":{"$ref":"#/definitions/CardName"},"CastingCost":{"$ref":"#/definitions/CastingCost"},"Class":{"$ref":"#/definitions/Class"},"Abilities":{"$ref":"#/definitions/abilities"},"Attack":{"$ref":"#/definitions/Attack"},"Health":{"$ref":"#/definitions/Health"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","CastingCost","Class","Abilities","Attack","Health","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §CastingCost §Class §Abilities §Attack §Health §FlavourText §Tags §Keywords §RulesText"},"harm":{"type":"struct","name":"Harm","description":"Build a Harm","children":{"Amount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["Amount"],"interactionText":"Harm §Amount."},"headquarter":{"type":"struct","name":"Headquarter","description":"Build a Headquarter","children":{"CardName":{"$ref":"#/definitions/CardName"},"Class":{"$ref":"#/definitions/Class"},"Delay":{"$ref":"#/definitions/Delay"},"Abilities":{"$ref":"#/definitions/abilities"},"Health":{"$ref":"#/definitions/Health"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","Class","Delay","Abilities","Health","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags §Keywords §RulesText"},"kill":{"type":"struct","name":"Kill","description":"Build a Kill","children":{},"interactionText":"Kill an entity."},"onConstruction":{"type":"struct","name":"On Construction","description":"Build a On Construction","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When another places spawns activate: §Effects."},"onDeath":{"type":"struct","name":"On Death","description":"Build a On Death","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When this dies activate: §Effects."},"onSpawn":{"type":"struct","name":"On Spawn","description":"Build a On Spawn","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When this spawns activate: §Effects."},"pay":{"type":"struct","name":"Pay","description":"Build a Pay","children":{"ManaAmount":{"$ref":"#/definitions/SimpleIntValue"},"Effects":{"$ref":"#/definitions/effects"}},"required":["ManaAmount","Effects"],"interactionText":"Pay §ManaAmount to activate: §Effects."},"periodic":{"type":"struct","name":"Periodic","description":"Build a Periodic","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"At the beginning of each tick activate: §Effects."},"place":{"type":"struct","name":"Place","description":"Build a Place","children":{"CardName":{"$ref":"#/definitions/CardName"},"CastingCost":{"$ref":"#/definitions/CastingCost"},"Class":{"$ref":"#/definitions/Class"},"Abilities":{"$ref":"#/definitions/abilities"},"Health":{"$ref":"#/definitions/Health"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","CastingCost","Class","Abilities","Health","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §CastingCost §Class §Abilities §Health §FlavourText §Tags §Keywords §RulesText"},"produce":{"type":"struct","name":"Produce","description":"Build a Produce","children":{"ManaAmount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["ManaAmount"],"interactionText":"Produce §ManaAmount mana."},"repair":{"type":"struct","name":"Repair","description":"Build a Repair","children":{"Amount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["Amount"],"interactionText":"Repair §Amount."},"tribute":{"type":"struct","name":"Tribute","description":"Build a Tribute","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"Sacrifice an entity to activate: §Effects."}}}
{"Card":{"$ref":"#/definitions/Card"},"definitions":{"Attack":{"type":"int","name":"Attack","max":32},"Card":{"type":"interface","name":"Card","description":"Choose a Card","children":{"Action":{"$ref":"#/definitions/action"},"Entity":{"$ref":"#/definitions/entity"},"Place":{"$ref":"#/definitions/place"},"Headquarter":{"$ref":"#/definitions/headquarter"}}},"CardName":{"type":"string","name":"Card Name","max":32,"min":1},"CastingCost":{"type":"int","name":"Casting Cost","max":32},"Class":{"type":"struct","name":"Class","description":"Build a Class","children":{"Nature":{"$ref":"#/definitions/Nature"},"Mysticism":{"$ref":"#/definitions/Mysticism"},"Technology":{"$ref":"#/definitions/Technology"},"Culture":{"$ref":"#/definitions/Culture"}},"required":["Nature","Mysticism","Technology","Culture"],"interactionText":"§Nature §Mysticism §Technology §Culture"},"Culture":{"type":"bool","name":"Culture"},"Delay":{"type":"int","name":"Delay","max":32},"FlavourText":{"type":"string","name":"Flavour Text","max":1000},"Health":{"type":"int","name":"Health","max":32},"Keyword":{"type":"string","name":"Keyword","max":10000},"Keywords":{"type":"array","name":"Keywords","description":"Add some Keywords","children":{"Keyword":{"$ref":"#/definitions/Keyword"}},"max":3,"min":1},"Mysticism":{"type":"bool","name":"Mysticism"},"Nature":{"type":"bool","name":"Nature"},"RulesText":{"type":"string","name":"Rules Text","max":1000},"SimpleIntValue":{"type":"int","name":"Simple Int Value","max":32},"Tag":{"type":"enum","name":"Tag","enum":["ANIMAL","BOT","DWARF","ENGINEER","EQUIPMENT","FARM","FIRE","HUMAN","KNIGHT","MAGIC","MILITANT","PRIMITIVE","RANGE","SPIRITUAL","TACTIC","TECHNOCRAT"]},"Tags":{"type":"array","name":"Tags","description":"Add some Tags","children":{"Tag":{"$ref":"#/definitions/Tag"}},"max":3,"min":1},"Technology":{"type":"bool","name":"Technology"},"abilities":{"type":"array","name":"Abilities","description":"Add some Abilities","children":{"Ability":{"$ref":"#/definitions/ability"}},"max":3},"ability":{"type":"interface","name":"Ability","description":"Choose a Ability","children":{"Arrival":{"$ref":"#/definitions/arrival"},"Battlecry":{"$ref":"#/definitions/battlecry"},"OnConstruction":{"$ref":"#/definitions/onConstruction"},"OnDeath":{"$ref":"#/definitions/onDeath"},"OnSpawn":{"$ref":"#/definitions/onSpawn"},"Pay":{"$ref":"#/definitions/pay"},"Periodic":{"$ref":"#/definitions/periodic"},"Tribute":{"$ref":"#/definitions/tribute"}}},"action":{"type":"struct","name":"Action","description":"Build a Action","children":{"CardName":{"$ref":"#/definitions/CardName"},"CastingCost":{"$ref":"#/definitions/CastingCost"},"Class":{"$ref":"#/definitions/Class"},"Effects":{"$ref":"#/definitions/effects"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","CastingCost","Class","Effects","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §CastingCost §Class §Effects §FlavourText §Tags §Keywords §RulesText"},"anthem":{"type":"struct","name":"Anthem","description":"Build a Anthem","children":{"Tag":{"$ref":"#/definitions/Tag"}},"required":["Tag"],"interactionText":"Anthem §Tag."},"arm":{"type":"struct","name":"Arm","description":"Build a Arm","children":{"Amount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["Amount"],"interactionText":"Arm §Amount."},"arrival":{"type":"struct","name":"Arrival","description":"Build a Arrival","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When another entity spawns activate: §Effects."},"battlecry":{"type":"struct","name":"Battlecry","description":"Build a Battlecry","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"At the beginning of each combat activate: §Effects."},"effect":{"type":"interface","name":"Effect","description":"Choose a Effect","children":{"Anthem":{"$ref":"#/definitions/anthem"},"Arm":{"$ref":"#/definitions/arm"},"Harm":{"$ref":"#/definitions/harm"},"Kill":{"$ref":"#/definitions/kill"},"Produce":{"$ref":"#/definitions/produce"},"Repair":{"$ref":"#/definitions/repair"}}},"effects":{"type":"array","name":"Effects","description":"Add some Effects","children":{"Effect":{"$ref":"#/definitions/effect"}},"max":3},"entity":{"type":"struct","name":"Entity","description":"Build a Entity","children":{"CardName":{"$ref":"#/definitions/CardName"},"CastingCost":{"$ref":"#/definitions/CastingCost"},"Class":{"$ref":"#/definitions/Class"},"Abilities":{"$ref":"#/definitions/abilities"},"Attack":{"$ref":"#/definitions/Attack"},"Health":{"$ref":"#/definitions/Health"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","CastingCost","Class","Abilities","Attack","Health","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §CastingCost §Class §Abilities §Attack §Health §FlavourText §Tags §Keywords §RulesText"},"harm":{"type":"struct","name":"Harm","description":"Build a Harm","children":{"Amount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["Amount"],"interactionText":"Harm §Amount."},"headquarter":{"type":"struct","name":"Headquarter","description":"Build a Headquarter","children":{"CardName":{"$ref":"#/definitions/CardName"},"Class":{"$ref":"#/definitions/Class"},"Delay":{"$ref":"#/definitions/Delay"},"Abilities":{"$ref":"#/definitions/abilities"},"Health":{"$ref":"#/definitions/Health"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","Class","Delay","Abilities","Health","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags §Keywords §RulesText"},"kill":{"type":"struct","name":"Kill","description":"Build a Kill","children":{},"interactionText":"Kill an entity."},"onConstruction":{"type":"struct","name":"On Construction","description":"Build a On Construction","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When another places spawns activate: §Effects."},"onDeath":{"type":"struct","name":"On Death","description":"Build a On Death","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When this dies activate: §Effects."},"onSpawn":{"type":"struct","name":"On Spawn","description":"Build a On Spawn","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"When this spawns activate: §Effects."},"pay":{"type":"struct","name":"Pay","description":"Build a Pay","children":{"ManaAmount":{"$ref":"#/definitions/SimpleIntValue"},"Effects":{"$ref":"#/definitions/effects"}},"required":["ManaAmount","Effects"],"interactionText":"Pay §ManaAmount to activate: §Effects."},"periodic":{"type":"struct","name":"Periodic","description":"Build a Periodic","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"At the beginning of each tick activate: §Effects."},"place":{"type":"struct","name":"Place","description":"Build a Place","children":{"CardName":{"$ref":"#/definitions/CardName"},"CastingCost":{"$ref":"#/definitions/CastingCost"},"Class":{"$ref":"#/definitions/Class"},"Abilities":{"$ref":"#/definitions/abilities"},"Health":{"$ref":"#/definitions/Health"},"FlavourText":{"$ref":"#/definitions/FlavourText"},"Tags":{"$ref":"#/definitions/Tags"},"Keywords":{"$ref":"#/definitions/Keywords"},"RulesText":{"$ref":"#/definitions/RulesText"}},"required":["CardName","CastingCost","Class","Abilities","Health","FlavourText","Tags","Keywords","RulesText"],"interactionText":"§CardName §CastingCost §Class §Abilities §Health §FlavourText §Tags §Keywords §RulesText"},"produce":{"type":"struct","name":"Produce","description":"Build a Produce","children":{"ManaAmount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["ManaAmount"],"interactionText":"Produce §ManaAmount mana."},"repair":{"type":"struct","name":"Repair","description":"Build a Repair","children":{"Amount":{"$ref":"#/definitions/SimpleIntValue"}},"required":["Amount"],"interactionText":"Repair §Amount."},"tribute":{"type":"struct","name":"Tribute","description":"Build a Tribute","children":{"Effects":{"$ref":"#/definitions/effects"}},"required":["Effects"],"interactionText":"Sacrifice an entity to activate: §Effects."}}}
8 changes: 4 additions & 4 deletions keywords/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ type KeywordedCard interface {
Resolve() cardobject.Card
}

type card struct {
type Card struct {
Action *action `json:",omitempty"`
Entity *entity `json:",omitempty"`
Place *place `json:",omitempty"`
Headquarter *headquarter `json:",omitempty"`
}

func (c card) Resolve() cardobject.Card {
func (c Card) Resolve() cardobject.Card {
valueOfB := reflect.ValueOf(c)
typeOfB := reflect.TypeOf(c)
possibleImplementer := []KeywordedCard{}
Expand All @@ -37,11 +37,11 @@ func (c card) Resolve() cardobject.Card {
return cardobject.Card{}
}

func (c card) Validate() error {
func (c Card) Validate() error {
return c.ValidateInterface()
}

func (c card) ValidateInterface() error {
func (c Card) ValidateInterface() error {
return jsonschema.ValidateInterface(c)
}

Expand Down
2 changes: 1 addition & 1 deletion keywords/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/DecentralCardGame/cardobject/jsonschema"
/*Schema provides the instructions on how to build a KeywordedCard via a json-schema
*/
func Schema() ([]byte, error) {
schema, err := jsonschema.Reflect(&card{})
schema, err := jsonschema.Reflect(&Card{})
if err != nil {
return []byte{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions keywords/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
/*Unmarshal takes card that contains keywords as json-file and
returns a validated keyworded card.
*/
func Unmarshal(data []byte) (KeywordedCard, error) {
var card card
func Unmarshal(data []byte) (*Card, error) {
var card Card
err := json.Unmarshal(data, &card)
if err != nil {
return nil, err
Expand All @@ -17,5 +17,5 @@ func Unmarshal(data []byte) (KeywordedCard, error) {
if err != nil {
return nil, err
}
return card, nil
return &card, nil
}

0 comments on commit ac93000

Please sign in to comment.