Skip to content

DecentralCardGame/cardobject

Repository files navigation

Cardobject

The Cardobject describes a crowd-control card. A Card is represented by a nested go-struct which contains all necessary data including effects and abilities. Addidtional functions provided allow to retrieve a build-instruction, an unmarshaling-method and the validation of a card. It also provides a shortened Version, the KeywordedCard which can be resolved to a full Card.

Usage

  1. An instruction on how to build a card is provided in form of a json-schema.
  2. A card-json can be unmarshaled and validated to a Card.

Schema

  1. The schema that describes to a frontend how to build a card is provided by the CardSchema()-function.
  2. The schema that describes to a frontend how to build a keyworded card is provided by the KeywordedSchema()-function.

Unmarshal and validate a Card

  1. The UnmarshalRaw()-method takes a Card in form of a json and returns a Card or an error.
  2. This process involves validating the Card.
  3. Example:
import "github.com/DecentralCardGame/cardobject"

data, _ := ioutil.ReadFile("card.json")
  
card, err := cardobject.UnmarshalRaw(data)

Unmarshal and validate a KeywordedCard

  1. The UnmarshalKeyworded()-method takes a KeywordedCard in form of a json and returns a Card or an error.
  2. This process involves resolving and validating the KeywordedCard and validating the resulting Card.
  3. Example:
import "github.com/DecentralCardGame/cardobject"

data, _ := ioutil.ReadFile("KeywordedCard.json")
  
card, err := cardobject.UnmarshalKeyworded(data)

Marshal a Card

  1. Cards can be marshaled using the go-json package.
  2. Example:
import "encoding/json"

cardJSON, error := json.Marshal(card)