Skip to content

Commit

Permalink
added rulestext and keywords attribute to card
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsui committed Apr 20, 2021
1 parent 5c3db8f commit 405856a
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cardSchema.json

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions cardobject/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Action struct {
Effects Effects
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
}

func (a Action) Validate() error {
Expand All @@ -37,7 +39,7 @@ func (a Action) ValidateStruct() error {
}

func (a Action) InteractionText() string {
return "§CardName §CastingCost §Class §Effects §FlavourText §Tags"
return "§CardName §CastingCost §Class §Effects §FlavourText §Tags §Keywords §RulesText"
}

type Entity struct {
Expand All @@ -49,6 +51,8 @@ type Entity struct {
Health Health
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
}

func (e Entity) Validate() error {
Expand All @@ -60,7 +64,7 @@ func (e Entity) ValidateStruct() error {
}

func (a Entity) InteractionText() string {
return "§CardName §CastingCost §Class §Abilities §Attack §Health §FlavourText §Tags"
return "§CardName §CastingCost §Class §Abilities §Attack §Health §FlavourText §Tags §Keywords §RulesText"
}

type Place struct {
Expand All @@ -71,6 +75,8 @@ type Place struct {
Health Health
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
}

func (p Place) Validate() error {
Expand All @@ -82,7 +88,7 @@ func (p Place) ValidateStruct() error {
}

func (a Place) InteractionText() string {
return "§CardName §CastingCost §Class §Abilities §Health §FlavourText §Tags"
return "§CardName §CastingCost §Class §Abilities §Health §FlavourText §Tags §Keywords §RulesText"
}

type Headquarter struct {
Expand All @@ -93,6 +99,8 @@ type Headquarter struct {
Health Health
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
}

func (h Headquarter) Validate() error {
Expand All @@ -104,5 +112,5 @@ func (h Headquarter) ValidateStruct() error {
}

func (a Headquarter) InteractionText() string {
return "§CardName §Class §Delay §Abilities §Health §FlavourText §Tags"
return "§CardName §Class §Delay §Abilities §Health §FlavourText §Tags §Keywords §RulesText"
}
25 changes: 25 additions & 0 deletions cardobject/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ const Tribute = "TRIBUTE"
var possibleKeywords []string = []string{
Anthem, Arm, Arrival, Battlecry, Harm, Kill, OnConstruction, OnDeath, OnSpawn, Pay, Periodic, Produce, Repair, Tribute}

type Keywords []Keyword

func (k Keywords) Validate() error {
return k.ValidateArray()
}

func (k Keywords) ValidateArray() error {
errorRange := []error{}
for _, v := range k {
err := v.Validate()
if err != nil {
errorRange = append(errorRange, err)
}
}
return jsonschema.CombineErrors(errorRange)
}

func (k Keywords) MinMaxItems() (int, int) {
return 1, 3
}

func (k Keywords) ItemName() string {
return jsonschema.ItemNameFromArray(k)
}

type Keyword jsonschema.BasicString

func (k Keyword) Validate() error {
Expand Down
1 change: 1 addition & 0 deletions cardobject/testJsons/actionTest1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Culture":false
},
"CastingCost":13,
"RulesText": "This could be your RulesText",
"Effects":[
{
"TargetEffect":{
Expand Down
2 changes: 1 addition & 1 deletion cardobject/testJsons/entityTest1.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Entity":{"CardName":"Name","Tags":["TECHNOCRAT"],"FlavourText":"asdf","Class":{"Technology":false,"Nature":false,"Mysticism":false,"Culture":true},"CastingCost":15,"Abilities":[{"ActivatedAbility":{"path":["children","Entity","children","Abilities","children","Ability","children"],"AbilityCost":{"RessourceCost":{"RessourceCostType":{"Nature":true},"CostAmount":2}}}}],"Health":0,"Attack":0}}
{"Entity":{"CardName":"Name","Tags":["TECHNOCRAT"],"FlavourText":"asdf","Class":{"Technology":false,"Nature":false,"Mysticism":false,"Culture":true},"CastingCost":15,"RulesText": "This could be your RulesText","Abilities":[{"ActivatedAbility":{"path":["children","Entity","children","Abilities","children","Ability","children"],"AbilityCost":{"RessourceCost":{"RessourceCostType":{"Nature":true},"CostAmount":2}}}}],"Health":0,"Attack":0}}
2 changes: 1 addition & 1 deletion cardobject/testJsons/place1Test.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Place":{"CardName":"Mühle","CastingCost":2,"Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":false},"Abilities":[],"Health":3,"FlavourText":"lulul","Tags":["PRIMITIVE"]}}
{"Place":{"CardName":"Mühle","CastingCost":2,"RulesText": "This could be your RulesText","Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":false},"Abilities":[],"Health":3,"FlavourText":"lulul","Tags":["PRIMITIVE"]}}
21 changes: 21 additions & 0 deletions cardobject/validatePrimitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const maxGrowth = 32
const minGrowth = 0
const maxHealth int = 32
const minHealth int = 0
const maxRulesTextLength int = 1000
const minRulesTextLength int = 1
const maxSimpleInt int = 32
const minSimpleInt int = 0
const maxSimpleStringLength = 32
Expand Down Expand Up @@ -184,6 +186,25 @@ func (h Health) MinMax() (int, int) {
return minHealth, maxHealth
}

type RulesText jsonschema.BasicString

func (r RulesText) Validate() error {
return r.ValidateString()
}

func (r RulesText) ValidateString() error {
minLength, maxLength := r.MinMaxLength()
length := len(string(r))
if length < minLength || length > maxLength {
return errors.New("RulesText must be between " + strconv.Itoa(minLength) + " and " + strconv.Itoa(maxLength) + " characters long")
}
return nil
}

func (r RulesText) MinMaxLength() (int, int) {
return minRulesTextLength, maxRulesTextLength
}

type StartingHandsize jsonschema.BasicInt

func (s StartingHandsize) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion keywordedSchema.json

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions keywords/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type action struct {
Effects effects
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
}

func (a action) Resolve() cardobject.Card {
Expand All @@ -63,7 +65,9 @@ func (a action) Resolve() cardobject.Card {
Class: a.Class,
Effects: effects,
FlavourText: a.FlavourText,
Tags: a.Tags}}
Tags: a.Tags,
Keywords: a.Keywords,
RulesText: a.RulesText}}
return card
}

Expand All @@ -76,7 +80,7 @@ func (a action) ValidateStruct() error {
}

func (a action) InteractionText() string {
return "§CardName §CastingCost §Class §Effects §FlavourText §Tags"
return "§CardName §CastingCost §Class §Effects §FlavourText §Tags §Keywords §RulesText"
}

type entity struct {
Expand All @@ -88,6 +92,8 @@ type entity struct {
Health cardobject.Health
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
}

func (e entity) Resolve() cardobject.Card {
Expand All @@ -101,7 +107,9 @@ func (e entity) Resolve() cardobject.Card {
Attack: e.Attack,
Health: e.Health,
FlavourText: e.FlavourText,
Tags: e.Tags}}
Tags: e.Tags,
Keywords: e.Keywords,
RulesText: e.RulesText}}
return card
}

Expand All @@ -114,7 +122,7 @@ func (e entity) ValidateStruct() error {
}

func (e entity) InteractionText() string {
return "§CardName §CastingCost §Class §Abilities §Attack §Health §FlavourText §Tags"
return "§CardName §CastingCost §Class §Abilities §Attack §Health §FlavourText §Tags §Keywords §RulesText"
}

type place struct {
Expand All @@ -125,6 +133,8 @@ type place struct {
Health cardobject.Health
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
}

func (p place) Resolve() cardobject.Card {
Expand All @@ -137,7 +147,9 @@ func (p place) Resolve() cardobject.Card {
Abilities: abilities,
Health: p.Health,
FlavourText: p.FlavourText,
Tags: p.Tags}}
Tags: p.Tags,
Keywords: p.Keywords,
RulesText: p.RulesText}}
return card
}

Expand All @@ -150,7 +162,7 @@ func (p place) ValidateStruct() error {
}

func (p place) InteractionText() string {
return "§CardName §CastingCost §Class §Abilities §Health §FlavourText §Tags"
return "§CardName §CastingCost §Class §Abilities §Health §FlavourText §Tags §Keywords §RulesText"
}

type headquarter struct {
Expand All @@ -161,6 +173,8 @@ type headquarter struct {
Health cardobject.Health
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
}

func (h headquarter) Resolve() cardobject.Card {
Expand All @@ -173,7 +187,9 @@ func (h headquarter) Resolve() cardobject.Card {
Abilities: abilities,
Health: h.Health,
FlavourText: h.FlavourText,
Tags: h.Tags}}
Tags: h.Tags,
Keywords: h.Keywords,
RulesText: h.RulesText}}
return card
}

Expand All @@ -186,5 +202,5 @@ func (h headquarter) ValidateStruct() error {
}

func (h headquarter) InteractionText() string {
return "§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags"
return "§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags §Keywords §RulesText"
}
2 changes: 2 additions & 0 deletions keywords/testJsons/keywordedCard.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"CastingCost":13,
"Attack":10,
"Health":10,
"Keywords":["ARM", "PAY"],
"RulesText":"This could be your RulesText",
"Abilities":[
{
"Pay":{
Expand Down
2 changes: 1 addition & 1 deletion keywords/testJsons/resolvedGroundTruth.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Entity":{"CardName":"Name","CastingCost":13,"Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":false},"Abilities":[{"ActivatedAbility":{"AbilityCost":{"ManaCost":{"CostAmount":2}},"Effects":[{"TargetEffect":{"EntityTargetEffect":{"EntitySelector":{"PlayerMode":"YOU","CardMode":"TARGET","EntityZone":"FIELD"},"EntityManipulations":[{"EntityIntManipulation":{"IntProperty":"HEALTH","IntOperator":"ADD","IntValue":{"SimpleIntValue":2},"Keyword":"ARM"}},{"EntityIntManipulation":{"IntProperty":"ATTACK","IntOperator":"ADD","IntValue":{"SimpleIntValue":2},"Keyword":"ARM"}}]}}}]}}],"Attack":10,"Health":10,"FlavourText":"-.-","Tags":["SPIRITUAL"]}}
{"Entity":{"CardName":"Name","CastingCost":13,"Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":false},"Abilities":[{"ActivatedAbility":{"AbilityCost":{"ManaCost":{"CostAmount":2}},"Effects":[{"TargetEffect":{"EntityTargetEffect":{"EntitySelector":{"PlayerMode":"YOU","CardMode":"TARGET","EntityZone":"FIELD"},"EntityManipulations":[{"EntityIntManipulation":{"IntProperty":"HEALTH","IntOperator":"ADD","IntValue":{"SimpleIntValue":2},"Keyword":"ARM"}},{"EntityIntManipulation":{"IntProperty":"ATTACK","IntOperator":"ADD","IntValue":{"SimpleIntValue":2},"Keyword":"ARM"}}]}}}]}}],"Attack":10,"Health":10,"FlavourText":"-.-","Tags":["SPIRITUAL"],"Keywords":["ARM","PAY"],"RulesText":"This could be your RulesText"}}

0 comments on commit 405856a

Please sign in to comment.