Documentation ¶
Index ¶
- Constants
- Variables
- func FillNumber(slice []int64, num int64) []int64
- func StrClear(slice []string) []string
- func ZeroClear(slice []int64) []int64
- type CharaReferences
- type Character
- type Characters
- func (cs *Characters) AddEmptyCharacter() *Character
- func (cs *Characters) AddID(ID int64) (*Character, error)
- func (cs *Characters) AddIDs(IDs ...int64) ([]*Character, error)
- func (cs *Characters) Clear()
- func (cs Characters) FindBy(f func(*Character) bool) *Character
- func (cs Characters) FindIndexBy(f func(*Character) bool) int
- func (cs Characters) FindIndexByUID(uid uint64) int
- func (cs Characters) Get(i int) *Character
- func (cs Characters) Len() int
- func (cs Characters) Less(i, j int) bool
- func (cs *Characters) Remove(idx int) bool
- func (cs Characters) RevSortBy(by func(*Character, *Character) bool)
- func (cs Characters) Set(i int, c *Character)
- func (cs Characters) SortBy(by func(*Character, *Character) bool)
- func (cs Characters) Swap(i, j int)
- type GameState
- func (state *GameState) Clear()
- func (state *GameState) FileExists(no int) bool
- func (state *GameState) LoadHeader(no int) (*MetaData, error)
- func (state *GameState) LoadShare() error
- func (state *GameState) LoadSystem(no int) error
- func (state *GameState) SaveShare() error
- func (state *GameState) SaveSystem(no int) error
- func (state *GameState) SaveSystemWithComment(no int, comment string) error
- type IntParam
- func (ip IntParam) Fill(value int64)
- func (ip IntParam) Get(i int) int64
- func (ip IntParam) GetByStr(key string) (int64, bool)
- func (ip IntParam) GetIndex(key string) int
- func (ip IntParam) Len() int
- func (ip IntParam) Set(i int, val int64)
- func (ip IntParam) SetByStr(key string, val int64) bool
- func (ip IntParam) Slice(from, to int) IntParam
- type LimitedRangeNameIndexer
- type MetaData
- type NameIndexer
- type NoneNameIndexer
- type Repository
- type SaveInfo
- type StrParam
- func (ip StrParam) Fill(value string)
- func (ip StrParam) Get(i int) string
- func (ip StrParam) GetByStr(key string) (string, bool)
- func (ip StrParam) GetIndex(key string) int
- func (ip StrParam) Len() int
- func (ip StrParam) Set(i int, val string)
- func (ip StrParam) SetByStr(key string, val string) bool
- func (ip StrParam) Slice(from, to int) StrParam
- type SystemData
- type UserVariables
- func (uvars UserVariables) Clear()
- func (usr_vars UserVariables) ForEachIntParam(f func(string, IntParam))
- func (usr_vars UserVariables) ForEachStrParam(f func(string, StrParam))
- func (usr_vars UserVariables) GetInt(varname string) (IntParam, bool)
- func (usr_vars UserVariables) GetStr(varname string) (StrParam, bool)
Constants ¶
const ( DefaultMetaIdent = "erago" DefaultMetaIdentLen = 5 MetaTitleLimit = 120 // 30 * 4byte char )
const IndexNotFound = csv.IndexNotFound
IndexNotFound is a value implying index is not found. Re-declare here so that csv package is not inported explicitly to use this constant.
Variables ¶
Functions ¶
Types ¶
type CharaReferences ¶
type CharaReferences struct { Indexes []int // contains filtered or unexported fields }
It has references for *Character. Its capacity of array is a number of csv.Character.
The reference is actually index of []*Character. So the reference is not always equal to *Character, which case is occurred if []*Character is sorted, and relation between index and *Character are changed.
func (*CharaReferences) Clear ¶
func (cref *CharaReferences) Clear()
all Indexes are cleared by zero.
func (CharaReferences) GetChara ¶
func (cref CharaReferences) GetChara(idx int) *Character
get character using idx, as like chara = reference[i], exception that if index out of range return nil.
func (CharaReferences) GetIndex ¶
func (cref CharaReferences) GetIndex(i int) int
get index of Character at i. if i is out of range return -1.
type Character ¶
type Character struct { ID int64 // ID: means reference for csv.Character. -1 means no reference. UID uint64 // Uniq ID. Indicating its identity. IsAssi int64 // experience of assistant Name string // formal name CallName string // usual name NickName string // use for special case MasterName string // call for you UserVariables }
Character has some parameters including csv character's parameters.
func (*Character) CsvInitialize ¶
Initialize by csv parameters.
type Characters ¶
type Characters struct { List characters CountNewChara uint64 // count of call newCharacters() // contains filtered or unexported fields }
Character pool. Its size are fit automatically to appropriate size.
Adding new character is done by Characters.AddID().
func (*Characters) AddEmptyCharacter ¶
func (cs *Characters) AddEmptyCharacter() *Character
add empty Character that has not initialized parameters, and return added new Character.
func (*Characters) AddID ¶
func (cs *Characters) AddID(ID int64) (*Character, error)
Add one character detected by character's ID and return added new Character. if character of given id is not found retrun that error.
func (*Characters) AddIDs ¶
func (cs *Characters) AddIDs(IDs ...int64) ([]*Character, error)
Add Characters detected by Character's ID. return list of added Characters and error that Chara is not found.
func (Characters) FindBy ¶
func (cs Characters) FindBy(f func(*Character) bool) *Character
find Character by bool func. if not found, return nil
func (Characters) FindIndexBy ¶
func (cs Characters) FindIndexBy(f func(*Character) bool) int
find true index by bool func. if not found, return -1
func (Characters) FindIndexByUID ¶
func (cs Characters) FindIndexByUID(uid uint64) int
find index by compairing UID.
func (Characters) Get ¶
func (cs Characters) Get(i int) *Character
like array access a_chara = charas[i], if idx out of range return nil
func (Characters) Less ¶
func (cs Characters) Less(i, j int) bool
implement sort.Interface. default compare Character's ID.
func (*Characters) Remove ¶
func (cs *Characters) Remove(idx int) bool
Remove Character at index and return IsRemoved. NOTE: after removing, the characters after given idx are shifted to fill empty index.
func (Characters) RevSortBy ¶
func (cs Characters) RevSortBy(by func(*Character, *Character) bool)
reverse ordered sort by "less" func.
func (Characters) Set ¶
func (cs Characters) Set(i int, c *Character)
like array access charas[i] = a_chara
func (Characters) SortBy ¶
func (cs Characters) SortBy(by func(*Character, *Character) bool)
sort by "less" function, which returns true if first character is less than second character. NOTE: if "less" function returns inverted booleen, sort order is reversed.
func (Characters) Swap ¶
func (cs Characters) Swap(i, j int)
implement sort.Interface. swap positions between i-th character and j-th character.
type GameState ¶
type GameState struct { CSV *csv.CsvManager SystemData *SystemData *SaveInfo // contains filtered or unexported fields }
game State holds all game parameters.
func NewGameState ¶
func NewGameState(csvdb *csv.CsvManager, repo Repository) *GameState
consturct gameState with CSV Manager and config.
func (*GameState) Clear ¶
func (state *GameState) Clear()
clear all data, including system and share, using 0 and empty string.
func (*GameState) FileExists ¶
check whether does save[No.] exists?
func (*GameState) LoadHeader ¶
load only header from save[No.].
func (*GameState) LoadSystem ¶
load game system state from save[No.].
func (*GameState) SaveSystem ¶
save game system state to save[No.].
type IntParam ¶
type IntParam struct { Values []int64 // it must be exported to marshall object. // contains filtered or unexported fields }
IntParam can be treated as []int64. And can use string key.
func NewIntParam ¶
func NewIntParam(vars []int64, indexer NameIndexer) IntParam
type LimitedRangeNameIndexer ¶ added in v0.3.0
type LimitedRangeNameIndexer struct {
// contains filtered or unexported fields
}
LimitedRangeNameIndexer limits the index range from original NameIndexer to the specified range [from:to) and maps the specified range into 0-based range, [0:to-from). It returns index -1 when the original NameIndexer returns out bounds of the specified range.
func (LimitedRangeNameIndexer) GetIndex ¶ added in v0.3.0
func (n LimitedRangeNameIndexer) GetIndex(key string) int
type NameIndexer ¶
type NameIndexer interface { // get index by querying string name // if not found return csv.IndexNotFound GetIndex(string) int }
name indexer is mapping string key to index.
type NoneNameIndexer ¶
type NoneNameIndexer struct{}
it always returns index -1 for any key. to use it, simply none_indexer := NoneNameIndexer{}.
func (NoneNameIndexer) GetIndex ¶
func (n NoneNameIndexer) GetIndex(key string) int
type Repository ¶
type Repository interface { // Exist returns whether a persisted GameState with id exists? // return true if exists. return false if not exists or // context is canceled. Exist(ctx context.Context, id int) bool // SaveSystemData persists SystemData, the game specific data, // in the given GameState. // ID is used to identify the persisted data. // return nil on success. return some error on failure or // context is canceled. SaveSystemData(ctx context.Context, id int, state *SystemData, info *SaveInfo) error // LoadSystemData restores SystemData, the game specific data, // into the given GameState. // ID is used to identify the persisted data. // return nil on success. return some error on failure or // context is canceled. LoadSystemData(ctx context.Context, id int, state *SystemData, info *SaveInfo) error // in the given GameState. return nil on success. return some error // on failure or context is canceled. SaveShareData(ctx context.Context, state *UserVariables) error // into the given GameState. // return nil on success. return some error on failure or // context is canceled. LoadShareData(ctx context.Context, state *UserVariables) error // LoadMetaList returns list of meta data associated to id list. // If id list is empty or nil, return empty list of meta data for persisted // GameState. // It also returns error if any id is not found or context is canceled. LoadMetaList(ctx context.Context, ids ...int) ([]*MetaData, error) }
Repository is a abstract data-store which persists GameState to arbitrary storage.
type StrParam ¶
type StrParam struct { Values []string // contains filtered or unexported fields }
StrParam can be treated as []string. And can use string key.
func NewStrParam ¶
func NewStrParam(vars []string, indexer NameIndexer) StrParam
type SystemData ¶
type SystemData struct { Chara *Characters // references of Chara Target *CharaReferences Master *CharaReferences Player *CharaReferences Assi *CharaReferences UserVariables }
System data has data using for the game system. it is remains after end game.
func (*SystemData) Clear ¶
func (sysdata *SystemData) Clear()
clear all data using 0, empty string and nil.
type UserVariables ¶
type UserVariables struct { // exported to marshall/unmarshall object. user should not // access this field directory IntMap intParamMap StrMap strParamMap // contains filtered or unexported fields }
UserVariables defines user defined values from csv data base. Its contents are accessed via API such as GetInt(varname) or GetStr(varname).
func (UserVariables) Clear ¶
func (uvars UserVariables) Clear()
clear contents of UserVariables. Int vars are cleared by 0, and Str vars are empty string.
func (UserVariables) ForEachIntParam ¶
func (usr_vars UserVariables) ForEachIntParam(f func(string, IntParam))
iteration of each int parameters.
func (UserVariables) ForEachStrParam ¶
func (usr_vars UserVariables) ForEachStrParam(f func(string, StrParam))
iteration of each str parameters.