Skip to content

Commit

Permalink
Updated Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
nlsui committed Aug 19, 2022
1 parent e830452 commit 89cb02f
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 8 deletions.
7 changes: 5 additions & 2 deletions jsonschema/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ func FindImplementer(i interfaceType) (Validateable, error) {
}
}
implementer, error := getDefinedValidateable(possibleImplementer)
if implementer == nil || error != nil {
return nil, errors.New(typeOfB.Name() + " implemented by not exactly one option")
if implementer == nil {
return nil, errors.New(typeOfB.Name() + " not implemented")
}
if error != nil {
return nil, error
}
return implementer, nil
}
Expand Down
2 changes: 1 addition & 1 deletion keywordedSchema.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions keywords/beast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keywords

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

type beast struct{}

func (b beast) ValidateType(r jsonschema.RootElement) error {
return jsonschema.ValidateStruct(b, r)
}

func (b beast) InteractionText() string {
return "3/3 beast"
}

func (b beast) Description() string {
return "A 3/3 entity token."
}

func (b beast) Classes() []jsonschema.Class {
return []jsonschema.Class{cardobject.NATURE}
}
24 changes: 24 additions & 0 deletions keywords/bot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keywords

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

type bot struct{}

func (b bot) ValidateType(r jsonschema.RootElement) error {
return jsonschema.ValidateStruct(b, r)
}

func (b bot) InteractionText() string {
return "2/2 Bot"
}

func (b bot) Description() string {
return "A 2/2 entity token."
}

func (b bot) Classes() []jsonschema.Class {
return []jsonschema.Class{cardobject.TECHNOLOGY}
}
24 changes: 24 additions & 0 deletions keywords/recruit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keywords

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

type recruit struct{}

func (re recruit) ValidateType(r jsonschema.RootElement) error {
return jsonschema.ValidateStruct(re, r)
}

func (re recruit) InteractionText() string {
return "1/1 recruit"
}

func (re recruit) Description() string {
return "A 1/1 entity token."
}

func (re recruit) Classes() []jsonschema.Class {
return []jsonschema.Class{cardobject.CULTURE}
}
6 changes: 3 additions & 3 deletions keywords/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
)

type spawn struct {
TokenType cardobject.TokenType
Amount cardobject.IntValue
Token token
Amount cardobject.IntValue
}

func (s spawn) ValidateType(r jsonschema.RootElement) error {
return jsonschema.ValidateStruct(s, r)
}

func (s spawn) InteractionText() string {
return "Spawn §Amount §TokenType."
return "Spawn §Amount §Token."
}

func (s spawn) Description() string {
Expand Down
3 changes: 2 additions & 1 deletion keywords/spawn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
func TestSpawn(t *testing.T) {
intVariable := cardobject.IntVariableName("X")
intValue := cardobject.IntValue{SimpleIntValue: nil, IntVariable: &intVariable}
spawn := spawn{"2/2 Bot", intValue}
token := token{nil, nil, &recruit{}, nil}
spawn := spawn{token, intValue}
err := spawn.ValidateType(allClassesTestCard())
if err != nil {
t.Error(err)
Expand Down
24 changes: 24 additions & 0 deletions keywords/spirit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keywords

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

type spirit struct{}

func (s spirit) ValidateType(r jsonschema.RootElement) error {
return jsonschema.ValidateStruct(s, r)
}

func (s spirit) InteractionText() string {
return "1/1 spirit"
}

func (s spirit) Description() string {
return "A 1/1 entity token with OnDeath: Insight 1."
}

func (s spirit) Classes() []jsonschema.Class {
return []jsonschema.Class{cardobject.MYSTICISM}
}
2 changes: 1 addition & 1 deletion keywords/testJsons/keywordedCard.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":true},"Abilities":[{"Pay":{"ManaAmount":2,"Effects":[{"Arm":{"Target":"RANDOM","Amount":{"SimpleIntValue":3}}}]}}],"Attack":10,"Health":10,"FlavourText":"-.-","Tags":["SPIRIT"],"Keywords":["ARM","PAY"],"RulesTexts":["This could be your RulesText",""]}}
{"Entity":{"CardName":"Name","CastingCost":13,"Class":{"Nature":false,"Mysticism":false,"Technology":true,"Culture":true},"Abilities":[{"Pay":{"ManaAmount":2,"Effects":[{"Arm":{"Target":"RANDOM","Amount":{"SimpleIntValue":3}}},{"Spawn":{"Token":{"Recruit":{}},"Amount":{"SimpleIntValue":2}}}]}}],"Attack":10,"Health":10,"FlavourText":"-.-","Tags":["SPIRIT"],"Keywords":["ARM","PAY"],"RulesTexts":["This could be your RulesText",""]}}
24 changes: 24 additions & 0 deletions keywords/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keywords

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

type token struct {
Beast *beast `json:",omitempty"`
Bot *bot `json:",omitempty"`
Recruit *recruit `json:",omitempty"`
Spirit *spirit `json:",omitempty"`
}

func (t token) ValidateType(r jsonschema.RootElement) error {
implementer, err := t.FindImplementer()
if err != nil {
return err
}
return implementer.ValidateType(r)
}

func (t token) FindImplementer() (jsonschema.Validateable, error) {
return jsonschema.FindImplementer(t)
}

0 comments on commit 89cb02f

Please sign in to comment.