Documentation ¶
Overview ¶
Package csv provides csv-parser for game parameter names. The parser read csv file and store internal data.
Index ¶
- Constants
- func CloneInt64(data []int64) []int64
- func CloneStr(data []string) []string
- func FileExists(file string) bool
- func InRangeInt64(data []int64, index int) bool
- func InRangeStr(data []string, index int) bool
- func ReadFileFunc(file string, f func([]string) error) error
- func ReadFunc(r io.Reader, f func([]string) error) error
- type CharaInfo
- type Character
- type Config
- type Constant
- type CsvManager
- func (cm *CsvManager) BuildIntUserVars(where VarScope) map[string][]int64
- func (cm *CsvManager) BuildStrUserVars(where VarScope) map[string][]string
- func (csv *CsvManager) Const(vname string) (Constant, error)
- func (csv *CsvManager) Constants() map[string]Constant
- func (cm *CsvManager) Initialize(config Config) (err error)
- func (cm *CsvManager) IntVariableSpecs(where VarScope) []VariableSpec
- func (csv *CsvManager) MustConst(vname string) Constant
- func (csv *CsvManager) NameIndexOf(group, name string) int
- func (cm *CsvManager) StrVariableSpecs(where VarScope) []VariableSpec
- type CustomFieldType
- type CustomFields
- func (cf *CustomFields) Has(key string) bool
- func (cf *CustomFields) Ints(key string) (*Ints, bool)
- func (cf *CustomFields) MustInts(key string) *Ints
- func (cf *CustomFields) MustStrings(key string) *Strings
- func (cf *CustomFields) Strings(key string) (*Strings, bool)
- func (cf *CustomFields) TypeOf(key string) CustomFieldType
- type GameBase
- type Ints
- type NameIndex
- type Names
- type NumberConstants
- type Parameter
- type Reader
- type Strings
- type VarScope
- type VariableSpec
Constants ¶
const ( HeaderFieldID = "id" HeaderFieldName = "name" HeaderFieldPrefixInt = "int_" HeaderFieldPrefixStr = "str_" // exceptional custom field which must exist on Item constant // after successful of the csv initialization. HeaderFieldItemPrice = "price" )
const ( // BuiltinXXXName is builtin variable names which always exist in system. // User can modify its size only, and not use these names to user defined variable name. // // These names must exist in CsvManager, // but its size is unstable. BuiltinTrainName = "Train" // Scope CSV BuiltinSourceName = "Source" // Scope CSV BuiltinParamName = "Param" // Scope Chara BuiltinJuelName = "Juel" // Scope Chara BuiltinAblName = "Abl" // Scope Chara BuiltinTalentName = "Talent" // Scope Chara BuiltinMarkName = "Mark" // Scope Chara BuiltinExpName = "Exp" // Scope Chara BuiltinItemStockName = "ItemStock" // Scope System BuiltinMoneyName = "Money" // Scope System // it shares csv defined Item-Names with but separated as variable data. BuiltinItemName = "Item" // Scope System BuiltinItemPriceName = "ItemPrice" // Scope CSV )
const ( // System variables is system-wide global variables. ScopeSystem = VarScope(scopeSystem) ScopeShare = VarScope(scopeShare) // Chara variables is character specific variables. ScopeChara = VarScope(scopeChara) )
const ( // Configures of reading CSV files. // TODO: make it configurable? Separator = "," Comment = ";" )
const IndexNotFound int = -1
IndexNotFound is a value implying the index is not found.
Variables ¶
This section is empty.
Functions ¶
func CloneInt64 ¶
it returns new data conserving contents pf given data.
func FileExists ¶
check whether file exists. It wraps filesystem.Exist() so that user need not to import filesystem package explicitly.
func InRangeInt64 ¶
check wheather index is in valid range?
func InRangeStr ¶
check wheather index is in valid range?
func ReadFileFunc ¶
ReadFileFunc reads csv file formatted by the era manner. Each records in the csv file processed by the user function. It returns error with at which line occurs.
Types ¶
type Constant ¶
type Constant struct { Names NameIndex CustomFields }
Constant is a constant data set defined by a csv file. it must contains constant key names Names and hash map for index-key pair NameIndex. may contains some custom fields.
type CsvManager ¶
type CsvManager struct { // the exceptional constants for reading csv file. Item Constant ItemPrices []int64 // default definition of the characters. // These are defined by "Chara/*.csv". // Each chara is identified by chara No. CharaMap map[int64]*Character // _GameBase.csv GameBase // _Replace.csv NumberConstants // contains filtered or unexported fields }
CSV Manager manages CSV variables.
To use this, first initialize.:
csv := &CsvManager{} err := csv.Initialize(Config{})
func NewCsvManager ¶
func NewCsvManager() *CsvManager
return empty CsvManager same as &CsvManager{} .
func (*CsvManager) BuildIntUserVars ¶
func (cm *CsvManager) BuildIntUserVars(where VarScope) map[string][]int64
return variable maps, which type are DataType int64 and scope where, where = {System, Share}. It allocates new valiables every call.
func (*CsvManager) BuildStrUserVars ¶
func (cm *CsvManager) BuildStrUserVars(where VarScope) map[string][]string
return variable maps, which type are DataType string and scope where, where = {System, Share}. It allocates new valiables every call.
func (*CsvManager) Const ¶
func (csv *CsvManager) Const(vname string) (Constant, error)
get a Constant by a variable name. return Constant and not found error.
func (*CsvManager) Constants ¶
func (csv *CsvManager) Constants() map[string]Constant
get constant variables map. modifying that map breaks constant.
func (*CsvManager) Initialize ¶
func (cm *CsvManager) Initialize(config Config) (err error)
initialize by reading csv files.
func (*CsvManager) IntVariableSpecs ¶ added in v0.6.0
func (cm *CsvManager) IntVariableSpecs(where VarScope) []VariableSpec
IntVariableSpecs returns slice of VariableSpecs which mathces given VarScope and data type Int.
func (*CsvManager) MustConst ¶
func (csv *CsvManager) MustConst(vname string) Constant
get a Constant by a variable name. if vname is not found, it will panic.
func (*CsvManager) NameIndexOf ¶
func (csv *CsvManager) NameIndexOf(group, name string) int
get index using group name: BASE, ABL ... , and param name: 体力 ... , if not found returns -1
func (*CsvManager) StrVariableSpecs ¶ added in v0.6.0
func (cm *CsvManager) StrVariableSpecs(where VarScope) []VariableSpec
StrVariableSpecs returns slice of VariableSpecs which mathces given VarScope and data type Str.
type CustomFieldType ¶ added in v0.4.0
type CustomFieldType int8
CustomFieldType indicates the data type for a custom field in a csv constant.
const ( CFNoneType CustomFieldType = iota CFIntType CFStrType )
type CustomFields ¶ added in v0.4.0
type CustomFields struct {
// contains filtered or unexported fields
}
CustomFields is a read only hash map for key and csv constant pair.
func (*CustomFields) Has ¶ added in v0.4.0
func (cf *CustomFields) Has(key string) bool
Has returns whether CustomFields have data specified by key.
func (*CustomFields) Ints ¶ added in v0.4.0
func (cf *CustomFields) Ints(key string) (*Ints, bool)
Ints returns csv constant with number type specified by the key. If the constant is not a number type, it will returns false as 2nd return value.
func (*CustomFields) MustInts ¶ added in v0.4.0
func (cf *CustomFields) MustInts(key string) *Ints
MustInts returns csv constant with number type specified by the key. If the constant is not a number type, it will panic.
func (*CustomFields) MustStrings ¶ added in v0.4.0
func (cf *CustomFields) MustStrings(key string) *Strings
MustStrings returns csv constant with string type specified by the key. If the constant is not a string type, it will panic.
func (*CustomFields) Strings ¶ added in v0.4.0
func (cf *CustomFields) Strings(key string) (*Strings, bool)
MustStrings returns csv constant with string type specified by the key. If the constant is not a string type, it will returns false as 2nd return value.
func (*CustomFields) TypeOf ¶ added in v0.4.0
func (cf *CustomFields) TypeOf(key string) CustomFieldType
TypeOf returns custom field type for the csv constant specified by the key. It returns CFNoneType if the field specified by the key is not found.
type GameBase ¶
type GameBase struct { Code string Version int32 Title string Author string Develop string AllowDiffVer bool AdditionalInfo string }
Base information for the Game
type Ints ¶ added in v0.4.0
type Ints struct {
// contains filtered or unexported fields
}
Ints is the read-only int64 slice treated as a number type for csv constant
type NameIndex ¶
NameIndex holds indexes corresponding to each Name defined in CSV.
type NumberConstants ¶ added in v0.3.0
Number constants excepted from CSV names.
type Parameter ¶
type Parameter struct {
// contains filtered or unexported fields
}
Parameter is variables which are numbers or strings.
type Reader ¶ added in v0.4.0
type Reader struct {
// contains filtered or unexported fields
}
Reader read csv file with the manner for the Comma and Comment.
type Strings ¶ added in v0.4.0
type Strings struct {
Names
}
Strings is the read-only string slice treated as a string type for csv constant
type VariableSpec ¶ added in v0.6.0
VariableSpec defines the spec of user defined varables.