schema

package
v0.0.0-...-59cac3b Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Package schema defines database and JSON schema as structs, as well as functions for creating and using these structs

Index

Constants

This section is empty.

Variables

View Source
var GolemArchetypes = map[string]GolemArchetype{
	"invoker": {Name: "Invoker", Abbreviation: "INV",
		AllowedStatuses: []string{"idle", "invoking"},
	},
	"harvester": {Name: "Harvester", Abbreviation: "HRV",
		AllowedStatuses: []string{"idle", "traveling", "harvesting"},
	},
	"courier": {Name: "Courier", Abbreviation: "COR",
		AllowedStatuses: []string{"idle", "traveling"},
	},
	"artisan": {Name: "Artisan", Abbreviation: "ART",
		AllowedStatuses: []string{"idle", "traveling"},
	},
	"merchant": {Name: "Merchant", Abbreviation: "MRC",
		AllowedStatuses: []string{"idle", "traveling"},
	},
}
View Source
var GolemStatuses = map[string]GolemStatus{
	"idle":       {Name: "Idle", IsBlocking: false},
	"harvesting": {Name: "Harvesting", IsBlocking: false},
	"traveling":  {Name: "Traveling", IsBlocking: true},
	"invoking":   {Name: "Invoking", IsBlocking: true},
}
View Source
var Leaderboards = map[string]Leaderboard{
	"coin-leaders":        {Thing: Thing{HasSymbol: HasSymbol{Symbol: "coin-leaders"}, Name: "Coin Leaders", Description: "Top 10 Users by Coins"}, Users: make([]LeaderboardEntry, 0)},
	"golem-leaders":       {Thing: Thing{HasSymbol: HasSymbol{Symbol: "golem-leaders"}, Name: "Golem Leaders", Description: "Top 10 Users by Golem Count"}, Users: make([]LeaderboardEntry, 0)},
	"achievement-leaders": {Thing: Thing{HasSymbol: HasSymbol{Symbol: "achievement-leaders"}, Name: "Achievement Leaders", Description: "Top 10 Users by Achievements Completed"}, Users: make([]LeaderboardEntry, 0)},
}
View Source
var Rituals = map[string]Ritual{
	"summon-invoker":   NewRitual("Summon Invoker", "summon-invoker", "Spend mana to summon a new invoker, who can be used to help generate even more mana.", 600),
	"summon-harvester": NewRitual("Summon Harvester", "summon-harvester", "Spend mana to summon a new harvester, who can be used to gather resources from nodes in the world.", 600),
}

ritual info map

Functions

func CheckForExistingUser

func CheckForExistingUser(token string, udb rdb.Database) (bool, error)

Check DB for existing user with given token and return bool for if exists, and error if error encountered

func DoesGolemArchetypeMatch

func DoesGolemArchetypeMatch(golem Golem, archetype string) bool

func DoesGolemStatusMatch

func DoesGolemStatusMatch(golem Golem, status string) bool

func FindIndexOfGolemWithSymbol

func FindIndexOfGolemWithSymbol(golems []Golem, symbol string) (bool, int)

func IsStatusAllowedForArchetype

func IsStatusAllowedForArchetype(archetype string, newStatus string) (bool, error)

func Locale_get_all_from_db

func Locale_get_all_from_db(wdb rdb.Database) (map[string]Locale, error)

Gets all locales from DB

func Locale_get_json_from_db

func Locale_get_json_from_db(wdb rdb.Database, path string) ([]byte, error)

Get json from db based on path

func Locale_save_all_to_db

func Locale_save_all_to_db(wdb rdb.Database, locales map[string]Locale) error

Attempt to save all locales, returns error or nil

func Locale_save_to_db

func Locale_save_to_db(wdb rdb.Database, locale Locale) error

Attempt to save locale, returns error or nil

func Locale_unmarshal_all_json

func Locale_unmarshal_all_json(locale_json []byte) (map[string]Locale, error)

Unmarshals all locales from json byte array

func Region_get_all_from_db

func Region_get_all_from_db(wdb rdb.Database) (map[string]Region, error)

Gets all regions from DB

func Region_get_json_from_db

func Region_get_json_from_db(wdb rdb.Database, path string) ([]byte, error)

Get json from db based on path

func Region_save_all_to_db

func Region_save_all_to_db(wdb rdb.Database, regions map[string]Region) error

Attempt to save all regions, returns error or nil

func Region_save_to_db

func Region_save_to_db(wdb rdb.Database, region Region) error

Attempt to save region, returns error or nil

func Region_unmarshal_all_json

func Region_unmarshal_all_json(region_json []byte) (map[string]Region, error)

Unmarshals all regions from json byte array

func ResourceNode_get_all_from_db

func ResourceNode_get_all_from_db(wdb rdb.Database) (map[string]ResourceNode, error)

Gets all resourcenodes from DB

func ResourceNode_get_json_from_db

func ResourceNode_get_json_from_db(wdb rdb.Database, path string) ([]byte, error)

Get json from db based on path

func ResourceNode_save_all_to_db

func ResourceNode_save_all_to_db(wdb rdb.Database, resourcenodes map[string]ResourceNode) error

Attempt to save all resourcenodes, returns error or nil

func ResourceNode_save_to_db

func ResourceNode_save_to_db(wdb rdb.Database, resourcenode ResourceNode) error

Attempt to save resourcenode, returns error or nil

func ResourceNode_unmarshal_all_json

func ResourceNode_unmarshal_all_json(resourcenode_json []byte) (map[string]ResourceNode, error)

Unmarshals all resourcenodes from json byte array

func Resource_get_all_from_db

func Resource_get_all_from_db(wdb rdb.Database) (map[string]Resource, error)

Gets all resources from DB

func Resource_get_json_from_db

func Resource_get_json_from_db(wdb rdb.Database, path string) ([]byte, error)

Get json from db based on path

func Resource_save_all_to_db

func Resource_save_all_to_db(wdb rdb.Database, resources map[string]Resource) error

Attempt to save all resources, returns error or nil

func Resource_save_to_db

func Resource_save_to_db(wdb rdb.Database, resource Resource) error

Attempt to save resource, returns error or nil

func Resource_unmarshal_all_json

func Resource_unmarshal_all_json(resource_json []byte) (map[string]Resource, error)

Unmarshals all resources from json byte array

func Route_get_all_from_db

func Route_get_all_from_db(wdb rdb.Database) (map[string]Route, error)

Gets all routes from DB

func Route_get_json_from_db

func Route_get_json_from_db(wdb rdb.Database, path string) ([]byte, error)

Get json from db based on path

func Route_save_all_to_db

func Route_save_all_to_db(wdb rdb.Database, routes map[string]Route) error

Attempt to save all routes, returns error or nil

func Route_save_to_db

func Route_save_to_db(wdb rdb.Database, route Route) error

Attempt to save route, returns error or nil

func Route_unmarshal_all_json

func Route_unmarshal_all_json(route_json []byte) (map[string]Route, error)

Unmarshals all routes from json byte array

func Test_locale_initialized

func Test_locale_initialized(wdb rdb.Database, locale map[string]Locale)

Test: Get locale from db and compare with json

func Test_region_initialized

func Test_region_initialized(wdb rdb.Database, region map[string]Region)

Test: Get region from db and compare with json

func Test_resource_initialized

func Test_resource_initialized(wdb rdb.Database, resource map[string]Resource)

Test: Get resource from db and compare with json

func Test_resourcenode_initialized

func Test_resourcenode_initialized(wdb rdb.Database, resourcenode map[string]ResourceNode)

Test: Get resourcenode from db and compare with json

func Test_route_initialized

func Test_route_initialized(wdb rdb.Database, route map[string]Route)

Test: Get route from db and compare with json

func Test_world_initialized

func Test_world_initialized(wdb rdb.Database, world World)

Test: Get world from db and compare with json

func World_get_json_from_db

func World_get_json_from_db(wdb rdb.Database, path string) ([]byte, error)

func World_save_to_db

func World_save_to_db(wdb rdb.Database, world World) error

Attempt to save world, returns error or nil

Types

type AchievementMetric

type AchievementMetric struct {
	Thing          // name,symbol,description of particular achievement - may want to substitute this once achievements are made
	Users []string `json:"users" binding:"required"` //usernames
}

type ActiveUsersMetric

type ActiveUsersMetric struct {
	Metric
	UserActivity []UserCallTimestamp `json:"user-activity" binding:"required"` //usernames
}

Active Users

type DropTable

type DropTable struct {
	ResourceSymbol string  `json:"resource_symbol" binding:"required"`
	Rarity         float64 `json:"rarity" binding:"required"`
	HarvestAmount  int     `json:"harvest_amount" binding:"required"`
}

Defines droptables

type Golem

type Golem struct {
	HasSymbol
	Archetype      string          `json:"archetype" binding:"required"`
	LocationSymbol string          `json:"location_symbol" binding:"required"`
	Status         string          `json:"status" binding:"required"`
	Capacity       float64         `json:"capacity" binding:"required"`
	TravelInfo     GolemTravelInfo `json:"travel_info" binding:"required"`
}

Defines a user which has Name, Symbol, Description

func FilterGolemListByArchetype

func FilterGolemListByArchetype(golems []Golem, archetype string) []Golem

func FilterGolemListByStatus

func FilterGolemListByStatus(golems []Golem, status string) []Golem

func NewGolem

func NewGolem(symbol string, archetype string, startingStatus string, capacity float64) Golem

type GolemArchetype

type GolemArchetype struct {
	Name            string   `json:"name" binding:"required"`
	Abbreviation    string   `json:"abbreviation" binding:"required"`
	AllowedStatuses []string `json:"allowed-statuses" binding:"required"`
}

golem archetypes and abbreviations map

type GolemStatus

type GolemStatus struct {
	Name       string `json:"name" binding:"required"`
	IsBlocking bool   `json:"is-blocking" binding:"required"`
}

golem statuses map

type GolemStatusUpdateBody

type GolemStatusUpdateBody struct {
	NewStatus    string      `json:"new_status" binding:"required"`
	Instructions interface{} `json:"instructions" binding:"required"`
}

Defines the structure for golem status update requests Instructions expects an object/map with different keys depending on newStatus

type GolemTravelInfo

type GolemTravelInfo struct {
	ArrivalTime       int64  `json:"arrival_time" binding:"required"`
	OriginSymbol      string `json:"origin_symbol" binding:"required"`
	DestinationSymbol string `json:"destination_symbol" binding:"required"`
	RouteDanger       int    `json:"route_danger" binding:"required"`
}

Defines relevant info for golems while traveling

type HasSymbol

type HasSymbol struct {
	Symbol string `json:"symbol" binding:"required"`
}

type InventoryResource

type InventoryResource struct {
	Resource
	Quantity int `json:"quantity" binding:"required"`
}

Defines resource in an inventory, used in udb, not json/wdb

type Leaderboard

type Leaderboard struct {
	Thing
	Users []LeaderboardEntry `json:"users" binding:"required"`
}

type LeaderboardDescriptionResponse

type LeaderboardDescriptionResponse struct {
	Symbol      string `json:"symbol" binding:"required"`
	Name        string `json:"name" binding:"required"`
	Description string `json:"description" binding:"required"`
}

func GetLeaderboardDescriptionResponses

func GetLeaderboardDescriptionResponses(boards []Leaderboard) []LeaderboardDescriptionResponse

type LeaderboardEntry

type LeaderboardEntry struct {
	Rank int `json:"rank" binding:"required"`
	PublicUserInfo
}

type Locale

type Locale struct {
	Thing
	ResourceNodeSymbols []string `json:"resource_node_symbols" binding:"required"`
	RouteSymbols        []string `json:"route_symbols" binding:"required"`
}

Defines the characteristics of Locales (e.g. cities, forests, etc.)

func Locale_get_from_db

func Locale_get_from_db(wdb rdb.Database, path string) (Locale, error)

Get the locale specified by path from db

func Locale_unmarshal_json

func Locale_unmarshal_json(locale_json []byte) (Locale, error)

Unmarshals locale from json byte array

type LocationInventory

type LocationInventory struct {
	LocationSymbol string     `json:"location-symbol" binding:"required"`
	Contents       []Resource `json:"contents" binding:"required"`
}

Defines the schema for LocationInventories - lists of items owned by the player at a certain location

type ManaDetails

type ManaDetails struct {
	Mana         float64 `json:"mana" binding:"required"`
	ManaCap      float64 `json:"mana-cap" binding:"required"`
	ManaRegen    float64 `json:"mana-regen" binding:"required"`
	LastManaTick int64   `json:"last-mana-tick" binding:"required"`
}

Defines the schema for ManaDetails - a struct containing information on mana for players

type Metric

type Metric struct {
	Name        string `json:"name" binding:"required"`
	Description string `json:"description" binding:"required"`
}

type PublicUserInfo

type PublicUserInfo struct {
	Username  string `json:"username" binding:"required"`
	Title     string `json:"title" binding:"required"`
	Coins     uint64 `json:"coins" binding:"required"`
	UserSince int64  `json:"user-since" binding:"required"`
}

Defines the public User info for the /users/{username} endpoint

type Region

type Region struct {
	Thing
	BorderRegionSymbols []string `json:"border_region_symbols" binding:"required"`
	LocaleSymbols       []string `json:"locale_symbols" binding:"required"`
}

func Region_get_from_db

func Region_get_from_db(wdb rdb.Database, path string) (Region, error)

Get the region specified by path from db

func Region_unmarshal_json

func Region_unmarshal_json(region_json []byte) (Region, error)

Unmarshals region from json byte array

type Resource

type Resource struct {
	Thing
	CapacityPerUnit float64 `json:"capacity_per_unit" binding:"required"`
}

Defines generic resource type

func Resource_get_from_db

func Resource_get_from_db(wdb rdb.Database, path string) (Resource, error)

Get the resource specified by path from db

func Resource_unmarshal_json

func Resource_unmarshal_json(resource_json []byte) (Resource, error)

Unmarshals resource from json byte array

type ResourceNode

type ResourceNode struct {
	Thing
	HarvestTime int         `json:"harvest_time" binding:"required"`
	DropTables  []DropTable `json:"drop_tables" binding:"required"`
}

Defines harvestable resource node

func ResourceNode_get_from_db

func ResourceNode_get_from_db(wdb rdb.Database, path string) (ResourceNode, error)

Get the resourcenode specified by path from db

func ResourceNode_unmarshal_json

func ResourceNode_unmarshal_json(resourcenode_json []byte) (ResourceNode, error)

Unmarshals resourcenode from json byte array

type Ritual

type Ritual struct {
	Thing
	ManaCost float64 `json:"mana-cost" binding:"required"`
}

Defines Ritual struct

func NewRitual

func NewRitual(name string, symbol string, description string, manaCost float64) Ritual

type Route

type Route struct {
	Thing
	DangerLevel int `json:"danger_level" binding:"required"`
	TravelTime  int `json:"travel_time" binding:"required"`
	Cost        int `json:"cost" binding:"required"`
}

Defines the characteristics of Routes between locales TravelTime in seconds

func Route_get_from_db

func Route_get_from_db(wdb rdb.Database, path string) (Route, error)

Get the route specified by path from db

func Route_unmarshal_json

func Route_unmarshal_json(route_json []byte) (Route, error)

Unmarshals route from json byte array

type Thing

type Thing struct {
	HasSymbol
	Name        string `json:"name" binding:"required"`
	Description string `json:"description" binding:"required"`
}

Defines a 'Thing' which has Name, Symbol, Description

type UniqueUsersMetric

type UniqueUsersMetric struct {
	Metric
	Usernames []string `json:"usernames" binding:"required"` //usernames
}

Unique Users

type User

type User struct {
	Token string `json:"token" binding:"required"`
	PublicUserInfo
	ManaDetails
	Golems       []Golem             `json:"golems" binding:"required"`
	Inventory    []LocationInventory `json:"inventory" binding:"required"`
	KnownRituals []string            `json:"known-rituals" binding:"required"`
}

Defines a user which has Name, Symbol, Description

func GetUserFromDB

func GetUserFromDB(token string, udb rdb.Database) (User, bool, error)

Get user from DB, bool is user found

func NewUser

func NewUser(token string, username string) User

type UserCallTimestamp

type UserCallTimestamp struct {
	Username          string `json:"username" binding:"required"`
	LastCallTimestamp int64  `json:"last-call-timestamp" binding:"required"`
}

type UsersByAchievementMetric

type UsersByAchievementMetric struct {
	Metric
	UsersByAchievement []AchievementMetric `json:"users-by-achievement" binding:"required"`
}

Users by Achievement

type UsersMetricEndpointResponse

type UsersMetricEndpointResponse struct {
	UniqueUsers        []string            `json:"unique-users" binding:"required"`
	ActiveUsers        []string            `json:"active-users" binding:"required"`
	UsersByAchievement []AchievementMetric `json:"users-by-achievement" binding:"required"`
}

type World

type World struct {
	Thing
	RegionSymbols []string `json:"region_symbols" binding:"required"`
}

func World_get_from_db

func World_get_from_db(wdb rdb.Database, path string) (World, error)

func World_unmarshal_json

func World_unmarshal_json(world_json []byte) (World, error)

Unmarshals world from json byte array

type WorldSummaryResponse

type WorldSummaryResponse struct {
	World         World                   `json:"world" binding:"required"`
	Regions       map[string]Region       `json:"regions" binding:"required"`
	Locales       map[string]Locale       `json:"locales" binding:"required"`
	Routes        map[string]Route        `json:"routes" binding:"required"`
	Resources     map[string]Resource     `json:"resources" binding:"required"`
	ResourceNodes map[string]ResourceNode `json:"resource_nodes" binding:"required"`
}

Jump to

Keyboard shortcuts

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