models

package
v0.0.0-...-bd241b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_SHIELDS = 50 // Arbitrarily large

	MAX_X_COORD = 300 // TODO fix
	MAX_Y_COORD = 300 // TODO fix

	DEFAULT_SIZE_X = 20
	DEFAULT_SIZE_Y = 20

	AnnotationTypeSquare = 1
	AnnotationTypeCircle = 2
)
View Source
const (
	// Const names to be retrievable from model code
	NORMAL_SHIELD_ICON  = "normal_shield"
	SKULL_SHIELD_ICON   = "skull_shield"
	HEART_SHIELD_ICON   = "heart_shield"
	UT_SHIELD_ICON      = "ut_shield"
	SPECIAL_SHIELD_ICON = "special_shield"
)
View Source
const (
	SALT_LEN         = 32
	PASSWORD_MIN_LEN = 8
)

Variables

This section is empty.

Functions

func Graph

func Graph(db *gorp.DbMap, scenar *Scenario) (interface{}, error)

Types

type Card

type Card struct {
	ID          int64     `json:"id" db:"id"`
	IDScenario  int64     `json:"-" db:"id_scenario"`
	Number      uint      `json:"number" db:"number"`
	Description string    `json:"description" db:"description"`
	Front       *CardFace `json:"front" db:"front"`
	Back        *CardFace `json:"back" db:"back"`
}

Type card is the basic building block for other game objects. It is a generic representation of a card.

func CreateCard

func CreateCard(db *gorp.DbMap, scenar *Scenario, num uint, desc string, front *CardFace, back *CardFace) (*Card, error)

Create a card.

func GetElementCards

func GetElementCards(db *gorp.DbMap, scenar *Scenario) ([]*Card, error)

Returns all card objects that belong to elements.

func ListCards

func ListCards(db *gorp.DbMap, scenar *Scenario) ([]*Card, error)

List a scenario's cards.

func LoadCardFromID

func LoadCardFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*Card, error)

Load a card by ID. Optionally filtered by scenario.

func (*Card) CreateCardIcon

func (c *Card) CreateCardIcon(db *gorp.DbMap, ico *Icon,
	FrontBack bool, X, Y, SizeX, SizeY uint,
	Annotation string, AnnotationType int,
	SkillTest *SkillTest, StateTokenLink *StateTokenLink) (*CardIcon, error)

Create a CardIcon object.

func (*Card) Delete

func (c *Card) Delete(db *gorp.DbMap) error

Delete a card.

func (*Card) ListCardIcons

func (c *Card) ListCardIcons(db *gorp.DbMap, SkillTest *SkillTest, StateTokenLink *StateTokenLink) ([]*CardIcon, error)

List all CardIcon objects linked to this card, with filters.

func (*Card) LoadCardIconFromID

func (c *Card) LoadCardIconFromID(db *gorp.DbMap, ID int64) (*CardIcon, error)

Load one CardIcon object linked to this card, by ID.

func (*Card) Update

func (c *Card) Update(db *gorp.DbMap, num uint, desc string, front *CardFace, back *CardFace) error

Update a card.

type CardFace

type CardFace struct {
	TextAreaSize int         `json:"text_area_size"`
	TextFields   []TextField `json:"text_fields"`
}

CardFace describes the Front or Back non-image components of a card. It is stored as JSON to allow flexibility / evolution in the definition.

func (*CardFace) Scan

func (cf *CardFace) Scan(value interface{}) error

func (*CardFace) Value

func (cf *CardFace) Value() (driver.Value, error)

type CardGraph

type CardGraph struct {
	ID                    int64   `json:"id"`
	Description           string  `json:"description"`
	Reveals               []int64 `json:"reveals,omitempty"`
	UnlockStateTokens     []int64 `json:"unlocks_state_tokens,omitempty"`
	IsUnlockedStateTokens []int64 `json:"is_unlocked_state_tokens,omitempty"`
	SkillTests            []int64 `json:"skill_tests,omitempty"`
}

type CardIcon

type CardIcon struct {
	ID               int64  `json:"id" db:"id"`
	IDCard           int64  `json:"id_card" db:"id_card"`
	FrontBack        bool   `json:"front_back" db:"front_back"`
	IDIcon           int64  `json:"id_icon" db:"id_icon"`
	X                uint   `json:"x" db:"x"`
	Y                uint   `json:"y" db:"y"`
	SizeX            uint   `json:"size_x" db:"size_x"`
	SizeY            uint   `json:"size_y" db:"size_y"`
	Annotation       string `json:"annotation" db:"annotation"`
	AnnotationType   int    `json:"annotation_type" db:"annotation_type"`
	IDSkillTest      *int64 `json:"-" db:"id_skilltest"`
	IDStateTokenLink *int64 `json:"-" db:"id_statetokenlink"`
}

CardIcon represents a single graphical icon on the Front or the Back of a Card. It is linked to a Card, and to a collection of Icon graphical elements. It has coordinates/size properties, and optional annotations (small circle or square) to add e.g. a Stat value for a character or a number above a Shield. It also has foreign keys to the SkillTest/StateTokenLink that it originated from, so that it can be retrieved for update when the SkillTest/StateTokenLink is updated, and can be automatically deleted through CASCADE.

func (*CardIcon) Delete

func (ci *CardIcon) Delete(db *gorp.DbMap) error

Delete a CardIcon object.

func (*CardIcon) Update

func (ci *CardIcon) Update(db *gorp.DbMap, ico *Icon, FrontBack bool,
	X, Y, SizeX, SizeY uint,
	Annotation string, AnnotationType int) error

Update a CardIcon object.

func (*CardIcon) Valid

func (ci *CardIcon) Valid() error

Verify that a CardIcon object is valid before creating/updating it.

type Element

type Element struct {
	ID          int64  `json:"-" db:"id"`
	IDScenario  int64  `json:"-" db:"id_scenario"`
	Number      int    `json:"number" db:"number"`
	Description string `json:"description" db:"description"`
	Notes       string `json:"notes" db:"notes"`
	IDCard      int64  `json:"id_card" db:"id_card"`
}

func CreateElement

func CreateElement(db *gorp.DbMap, scenar *Scenario, Number int, Description string) (*Element, error)

Create a new element.

func ListElements

func ListElements(db *gorp.DbMap, scenar *Scenario) ([]*Element, error)

List elements, optionally filtered by scenario.

func LoadElementFromID

func LoadElementFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*Element, error)

Load element by ID. Optional scenario filter.

func (*Element) Delete

func (e *Element) Delete(db *gorp.DbMap) error

Delete an element.

func (*Element) Update

func (e *Element) Update(db *gorp.DbMap, Number int, Description string, Notes string) error

Update an element.

func (*Element) Valid

func (e *Element) Valid() error
type ElementLink struct {
	ID         int64 `json:"id" db:"id"`
	IDScenario int64 `json:"id_scenario" db:"id_scenario"`
	IDElement  int64 `json:"id_element" db:"id_element"`
	IDCard     int64 `json:"id_card" db:"id_card"`
	GivesUses  bool  `json:"gives_uses" db:"gives_uses"`
}
func CreateElementLink(db *gorp.DbMap, card *Card, elem *Element, GivesUses bool) (*ElementLink, error)

Create a link between an element and a card.

func ListElementLinks(db *gorp.DbMap, scenar *Scenario, card *Card, elem *Element) ([]*ElementLink, error)

List element links, with filters.

func LoadElementLinkFromID

func LoadElementLinkFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*ElementLink, error)

Load an element link by id, with optional scenario filter.

func (*ElementLink) Delete

func (el *ElementLink) Delete(db *gorp.DbMap) error

Delete an element link

type Icon

type Icon struct {
	ID         int64  `json:"id" db:"id"`
	IDScenario *int64 `json:"id_scenario" db:"id_scenario"`
	ShortName  string `json:"short_name" db:"short_name"`
	URL        string `json:"url" db:"url"`
}

func CreateIcon

func CreateIcon(db *gorp.DbMap, scenar *Scenario, ShortName string, URL string) (*Icon, error)

Create an icon

func ListIcons

func ListIcons(db *gorp.DbMap, scenar *Scenario) ([]*Icon, error)

List icons, optionally filtered by scenario.

func LoadBaseIconFromShortName

func LoadBaseIconFromShortName(db *gorp.DbMap, ShortName string) (*Icon, error)

Used to load base game objects, e.g. shield icons. These need to be referenced by a const name for conveniency. This enforces id_scenario IS NULL (i.e. base game objects) on returned rows.

func LoadIconFromID

func LoadIconFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*Icon, error)

Load an icon from ID. If scenar parameter is non-nil it acts as a filter: only rows with id_scenario NULL or stricly equal will be returned.

func (*Icon) Delete

func (i *Icon) Delete(db *gorp.DbMap) error

Delete an icon

func (*Icon) Update

func (i *Icon) Update(db *gorp.DbMap, ShortName string, URL string) error

Update an icon

func (*Icon) Valid

func (i *Icon) Valid() error

Verify that an icon object is valid before creating/updating it

type LocGraph

type LocGraph struct {
	ID     int64        `json:"id"`
	Name   string       `json:"name"`
	Hidden bool         `json:"hidden"`
	Cards  []*CardGraph `json:"cards,omitempty"`
}

type Location

type Location struct {
	ID         int64  `json:"id" db:"id"`
	IDScenario int64  `json:"-" db:"id_scenario"`
	Name       string `json:"name" db:"name"`
	Hidden     bool   `json:"hidden" db:"hidden"`
	Notes      string `json:"notes" db:"notes"`
}

Location represents a location the players can visit. It is composed of several cards.

func CreateLocation

func CreateLocation(db *gorp.DbMap, scenar *Scenario, Name string, Hidden bool) (*Location, error)

Create a location.

func ListLocations

func ListLocations(db *gorp.DbMap, scenar *Scenario) ([]*Location, error)

List locations, with filters.

func LoadLocationFromID

func LoadLocationFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*Location, error)

Load a Location from ID. Optionally filtered by scenario.

func (*Location) CreateLocationCard

func (loc *Location) CreateLocationCard(db *gorp.DbMap, scenar *Scenario, letter string) (*LocationCard, error)

Create a link between a card and a location.

func (*Location) Delete

func (loc *Location) Delete(db *gorp.DbMap) error

Delete a location.

func (*Location) GetCards

func (loc *Location) GetCards(db *gorp.DbMap) ([]*Card, error)

TEMP ?

func (*Location) ListLocationCards

func (loc *Location) ListLocationCards(db *gorp.DbMap) ([]*LocationCard, error)

List a location's cards.

func (*Location) LoadLocationCardFromID

func (loc *Location) LoadLocationCardFromID(db *gorp.DbMap, ID int64) (*LocationCard, error)

Load a location card,

func (*Location) Update

func (loc *Location) Update(db *gorp.DbMap, Name string, Hidden bool, Notes string) error

Update a location.

func (*Location) Valid

func (loc *Location) Valid() error

Verify that a Location is valid before creating/updating it.

type LocationCard

type LocationCard struct {
	ID         int64  `json:"id" db:"id"`
	IDLocation int64  `json:"-" db:"id_location"`
	IDCard     int64  `json:"id_card" db:"id_card"`
	Letter     string `json:"letter" db:"letter"`
}

LocationCard represents the cards contained in a location. Decoupled from Location to allow things like multiple "A" locations

func (*LocationCard) Delete

func (lc *LocationCard) Delete(db *gorp.DbMap) error

Delete a location card.

func (*LocationCard) Update

func (lc *LocationCard) Update(db *gorp.DbMap, letter string) error

Update a location card.

func (*LocationCard) Valid

func (lc *LocationCard) Valid() error

Verify that a LocationCard is valid before creating/updating it.

type LocationLink struct {
	ID         int64 `json:"id" db:"id"`
	IDScenario int64 `json:"-" db:"id_scenario"`
	IDCard     int64 `json:"id_card" db:"id_card"`
	IDLocation int64 `json:"id_location" db:"id_location"`
}

LocationLink represents a link between a card and a Location. The card REVEALS the location.

func CreateLocationLink(db *gorp.DbMap, card *Card, loc *Location) (*LocationLink, error)

Create a link between a card and a location.

func ListLocationLinks(db *gorp.DbMap, scenar *Scenario, card *Card, loc *Location) ([]*LocationLink, error)

List location links, with filters.

func LoadLocationLinkFromID

func LoadLocationLinkFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*LocationLink, error)

Loads a location link by ID. Optionally filtered by scenario.

func (*LocationLink) Delete

func (ll *LocationLink) Delete(db *gorp.DbMap) error

Delete a location link.

type Scenario

type Scenario struct {
	ID       int64  `json:"id" db:"id"`
	Name     string `json:"name" db:"name"`
	IDAuthor int64  `json:"-" db:"id_author"`
}

Scenario is the highest-level object. All other game objects belong to a scenario. A scenario belongs to a user (author).

func CreateScenario

func CreateScenario(db *gorp.DbMap, name string, author *User) (*Scenario, error)

Create a scenario.

func ListScenarios

func ListScenarios(db *gorp.DbMap, author *User) ([]*Scenario, error)

List scenarios, optionally filtered by author.

func LoadScenarioFromID

func LoadScenarioFromID(db *gorp.DbMap, author *User, ID int64) (*Scenario, error)

Load a scenario by id, optionally filtered by author.

func (*Scenario) Delete

func (sc *Scenario) Delete(db *gorp.DbMap) error

Delete a scenario.

func (*Scenario) Update

func (sc *Scenario) Update(db *gorp.DbMap, name string) error

Update a scenario.

func (*Scenario) Valid

func (sc *Scenario) Valid() error

Verify that a scenario is valid before creating/updating it.

type SkillTest

type SkillTest struct {
	ID             int64 `json:"id" db:"id"`
	IDScenario     int64 `json:"-" db:"id_scenario"`
	IDCard         int64 `json:"id_card" db:"id_card"`
	IDStat         int64 `json:"id_stat" db:"id_stat"`
	NormalShields  uint  `json:"normal_shields" db:"normal_shields"`
	SkullShields   uint  `json:"skull_shields" db:"skull_shields"`
	HeartShields   uint  `json:"heart_shields" db:"heart_shields"`
	UTShields      uint  `json:"ut_shields" db:"ut_shields"`
	SpecialShields uint  `json:"special_shields" db:"special_shields"`
}

SkillTest represents a statistic skill-test required by a Card. It links the Card and the Stat for easy querying/navigation, and allows easy declaration of test difficulty by declaring each number of shields. The code managing SkillTest objects will create CardIcon objects for the skill-test statistic and for each kind of non-zero Shield, and link them to the Card. That way, the user only has to create a SkillTest to have all the necessary graphical elements added to a Card, which can then be edited individually.

func CreateSkillTest

func CreateSkillTest(db *gorp.DbMap, card *Card, linkedStat *Stat, NormalShields, SkullShields, HeartShields, UTShields, SpecialShields uint) (*SkillTest, error)

Create a skill test. This will also create CardIcon objects on the Front of the Card, for the statistic itself and each of the present shields.

func ListSkillTests

func ListSkillTests(db *gorp.DbMap, scenar *Scenario, card *Card, s *Stat) ([]*SkillTest, error)

List skill tests with filters.

func LoadSkillTestFromID

func LoadSkillTestFromID(db *gorp.DbMap, scenar *Scenario, IDSkillTest int64) (*SkillTest, error)

Load a skill test, by ID. Optionally filtered by scenario.

func (*SkillTest) Delete

func (st *SkillTest) Delete(db *gorp.DbMap) error

Delete a skill test linked to a card.

func (*SkillTest) Update

func (st *SkillTest) Update(db *gorp.DbMap, card *Card, linkedStat *Stat, NormalShields, SkullShields, HeartShields, UTShields, SpecialShields uint) error

Update a skill test linked to a card. This will also create CardIcon objects on the Front of the Card, for the statistic itself and each of the present shields. The card parameter CANNOT overwrite the card associated with the SkillTest, it is permanent. It is passed only to be able to retrieve the associated CardIcon objects.

func (*SkillTest) Valid

func (st *SkillTest) Valid() error

Verify that a skill test object is valid before creating/updating it.

type Stat

type Stat struct {
	ID          int64  `json:"id" db:"id"`
	IDScenario  int64  `json:"-" db:"id_scenario"`
	Name        string `json:"name" db:"name"`
	Description string `json:"description" db:"description"`
	IDIcon      int64  `json:"id_icon" db:"id_icon"`
}

func CreateStat

func CreateStat(db *gorp.DbMap, scenar *Scenario, ico *Icon, name string, description string) (*Stat, error)

Create a stat object.

func ListStats

func ListStats(db *gorp.DbMap, scenar *Scenario) ([]*Stat, error)

List stats, optionally filtered by scenario.

func LoadStatFromID

func LoadStatFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*Stat, error)

Load stat by id, optionally filtered by scenario.

func (*Stat) Delete

func (st *Stat) Delete(db *gorp.DbMap) error

Delete a stat object.

func (*Stat) Update

func (st *Stat) Update(db *gorp.DbMap, ico *Icon, name string, description string) error

Update stat object.

func (*Stat) Valid

func (st *Stat) Valid() error

Verify that a stat object is valid before creating/updating it.

type StateToken

type StateToken struct {
	ID        int64  `json:"id" db:"id"`
	ShortName string `json:"short_name" db:"short_name"`
	IDIcon    int64  `json:"id_icon" db:"id_icon"`
}

StateToken represents base game tokens with different icons that maintain game state (e.g. unlock access to cards) These are bootstrapped in DB, only need Load functions.

func ListStateTokens

func ListStateTokens(db *gorp.DbMap) ([]*StateToken, error)

List all state tokens

func LoadStateTokenFromID

func LoadStateTokenFromID(db *gorp.DbMap, ID int64) (*StateToken, error)

Loads a state token by ID

type StateTokenLink struct {
	ID              int64 `json:"id" db:"id"`
	IDScenario      int64 `json:"-" db:"id_scenario"`
	IDCard          int64 `json:"id_card" db:"id_card"`
	IDStateToken    int64 `json:"id_state_token" db:"id_state_token"`
	UnlocksUnlocked bool  `json:"unlocks_unlocked" db:"unlocks_unlocked"`
}

StateTokenLink represents a Card -> StateToken relation. It is uni-directional but can be configured using the UnlocksUnlocked parameter. This lets the user express relations such as:

Card X (unlocks) -> StateToken Y (unlocks) -> Card Z

A CardIcon object containing the StateToken icon will be added to the Front of any Card that "unlocks" it, and to the back of any Card that is "unlocked" by it.

func CreateStateTokenLink(db *gorp.DbMap, card *Card, tk *StateToken, UnlocksUnlocked bool) (*StateTokenLink, error)

Create a link between a card and a state token. This will also create a CardIcon object representing the state token on either the front or the back of the card (depending on if it unlocks / is unlocked).

func ListStateTokenLinks(db *gorp.DbMap, scenar *Scenario, card *Card, tk *StateToken) ([]*StateTokenLink, error)

List state token links, with filters.

func LoadStateTokenLinkFromID

func LoadStateTokenLinkFromID(db *gorp.DbMap, scenar *Scenario, ID int64) (*StateTokenLink, error)

Loads a state token link by ID. Optionally filtered by scenario.

func (*StateTokenLink) Delete

func (cl *StateTokenLink) Delete(db *gorp.DbMap) error

Delete a state token link.

func (*StateTokenLink) Update

func (cl *StateTokenLink) Update(db *gorp.DbMap, card *Card, tk *StateToken, UnlocksUnlocked bool) error

TODO delete? Update a state token link. This will also create a CardIcon object representing the state token on either the front or the back of the card (depending on if it unlocks / is unlocked). The card parameter CANNOT overwrite the card associated with the StateTokenLink, it is permanent. It is passed only to be able to retrieve the associated CardIcon object.

type TextField

type TextField struct {
	X    int    `json:"x"`
	Y    int    `json:"y"`
	Text string `json:"text"`
}

TextField describes a single field of text on a card. For now, it just has spacial coordinates. Later, this will evolve to contain more flexibility (box_size x/y, font, font_size, opacity, color, ...)

type User

type User struct {
	ID           int64  `json:"-" db:"id"`
	Email        string `json:"email" db:"email"`
	PasswordHash string `json:"-" db:"password_hash"`
	PasswordSalt string `json:"-" db:"password_salt"`
	// contains filtered or unexported fields
}

func CreateUser

func CreateUser(db *gorp.DbMap, email string, password string) (*User, error)

Create a user.

func LoadUserFromEmail

func LoadUserFromEmail(db *gorp.DbMap, email string) (*User, error)

Load a user by email.

func (*User) PasswordEquals

func (u *User) PasswordEquals(pw string) bool

Check if the user's password matches the plain parameter.

func (*User) Update

func (u *User) Update(db *gorp.DbMap, email string, password string) error

Update a user.

func (*User) Valid

func (u *User) Valid() error

Verify that a user is valid before creating/updating it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL