Skip to content

Commit

Permalink
change rulestext to relestexts
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsui committed Apr 26, 2021
1 parent ac93000 commit afe005a
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cardSchema.json

Large diffs are not rendered by default.

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

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

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

type Entity struct {
Expand All @@ -52,7 +52,7 @@ type Entity struct {
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
RulesTexts RulesTexts
}

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

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

type Place struct {
Expand All @@ -76,7 +76,7 @@ type Place struct {
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
RulesTexts RulesTexts
}

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

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

type Headquarter struct {
Expand All @@ -100,7 +100,7 @@ type Headquarter struct {
FlavourText FlavourText
Tags Tags
Keywords Keywords
RulesText RulesText
RulesTexts RulesTexts
}

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

func (a Headquarter) InteractionText() string {
return "§CardName §Class §Delay §Abilities §Health §FlavourText §Tags §Keywords §RulesText"
return "§CardName §Class §Delay §Abilities §Health §FlavourText §Tags §Keywords §RulesTexts"
}
55 changes: 55 additions & 0 deletions cardobject/rulestext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cardobject

import (
"errors"
"strconv"

"github.com/DecentralCardGame/cardobject/jsonschema"
)

const maxRulesTextLength int = 1000
const minRulesTextLength int = 0

type RulesTexts []RulesText

func (r RulesTexts) Validate() error {
return r.ValidateArray()
}

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

func (r RulesTexts) MinMaxItems() (int, int) {
return 0, 3
}

func (r RulesTexts) ItemName() string {
return jsonschema.ItemNameFromArray(r)
}

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
}
2 changes: 1 addition & 1 deletion cardobject/testJsons/actionTest1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Culture":false
},
"CastingCost":13,
"RulesText": "This could be your RulesText",
"RulesTexts": ["This could be your RulesText",""],
"Effects":[
{
"TargetEffect":{
Expand Down
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,"RulesText": "This could be your RulesText","Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":false},"Abilities":[],"Health":3,"FlavourText":"lulul","Tags":["PRIMITIVE"]}}
{"Place":{"CardName":"Mühle","CastingCost":2,"RulesTexts": ["This could be your RulesText"],"Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":false},"Abilities":[],"Health":3,"FlavourText":"lulul","Tags":["PRIMITIVE"]}}
21 changes: 0 additions & 21 deletions cardobject/validatePrimitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const maxGrowth = 32
const minGrowth = 0
const maxHealth int = 32
const minHealth int = 0
const maxRulesTextLength int = 1000
const minRulesTextLength int = 0
const maxSimpleInt int = 32
const minSimpleInt int = 0
const maxSimpleStringLength = 32
Expand Down Expand Up @@ -186,25 +184,6 @@ 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.

24 changes: 12 additions & 12 deletions keywords/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type action struct {
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
RulesTexts cardobject.RulesTexts
}

func (a action) Resolve() cardobject.Card {
Expand All @@ -67,7 +67,7 @@ func (a action) Resolve() cardobject.Card {
FlavourText: a.FlavourText,
Tags: a.Tags,
Keywords: a.Keywords,
RulesText: a.RulesText}}
RulesTexts: a.RulesTexts}}
return card
}

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

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

type entity struct {
Expand All @@ -93,7 +93,7 @@ type entity struct {
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
RulesTexts cardobject.RulesTexts
}

func (e entity) Resolve() cardobject.Card {
Expand All @@ -109,7 +109,7 @@ func (e entity) Resolve() cardobject.Card {
FlavourText: e.FlavourText,
Tags: e.Tags,
Keywords: e.Keywords,
RulesText: e.RulesText}}
RulesTexts: e.RulesTexts}}
return card
}

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

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

type place struct {
Expand All @@ -134,7 +134,7 @@ type place struct {
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
RulesTexts cardobject.RulesTexts
}

func (p place) Resolve() cardobject.Card {
Expand All @@ -149,7 +149,7 @@ func (p place) Resolve() cardobject.Card {
FlavourText: p.FlavourText,
Tags: p.Tags,
Keywords: p.Keywords,
RulesText: p.RulesText}}
RulesTexts: p.RulesTexts}}
return card
}

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

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

type headquarter struct {
Expand All @@ -174,7 +174,7 @@ type headquarter struct {
FlavourText cardobject.FlavourText
Tags cardobject.Tags
Keywords cardobject.Keywords
RulesText cardobject.RulesText
RulesTexts cardobject.RulesTexts
}

func (h headquarter) Resolve() cardobject.Card {
Expand All @@ -189,7 +189,7 @@ func (h headquarter) Resolve() cardobject.Card {
FlavourText: h.FlavourText,
Tags: h.Tags,
Keywords: h.Keywords,
RulesText: h.RulesText}}
RulesTexts: h.RulesTexts}}
return card
}

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

func (h headquarter) InteractionText() string {
return "§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags §Keywords §RulesText"
return "§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags §Keywords §RulesTexts"
}
2 changes: 1 addition & 1 deletion keywords/testJsons/keywordedCard.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Attack":10,
"Health":10,
"Keywords":["ARM", "PAY"],
"RulesText":"This could be your RulesText",
"RulesTexts":["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"],"Keywords":["ARM","PAY"],"RulesText":"This could be your RulesText"}}
{"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"],"RulesTexts":["This could be your RulesText",""]}}

0 comments on commit afe005a

Please sign in to comment.