csv

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package csv provides csv-parser for game parameter names. The parser read csv file and store internal data.

Index

Constants

View Source
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"
)
View Source
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

)
View Source
const (
	// System variables is system-wide global variables.
	ScopeSystem = VarScope(scopeSystem)
	// Share variables is global variables shared with other savedata.
	ScopeShare = VarScope(scopeShare)
	// Chara variables is character specific variables.
	ScopeChara = VarScope(scopeChara)
)
View Source
const (
	// Configures of reading CSV files.
	// TODO: make it configurable?
	Separator = ","
	Comment   = ";"
)
View Source
const IndexNotFound int = -1

IndexNotFound is a value implying the index is not found.

Variables

This section is empty.

Functions

func CloneInt64

func CloneInt64(data []int64) []int64

it returns new data conserving contents pf given data.

func CloneStr

func CloneStr(data []string) []string

it returns new data conserving contents pf given data.

func FileExists

func FileExists(file string) bool

check whether file exists. It wraps filesystem.Exist() so that user need not to import filesystem package explicitly.

func InRangeInt64

func InRangeInt64(data []int64, index int) bool

check wheather index is in valid range?

func InRangeStr

func InRangeStr(data []string, index int) bool

check wheather index is in valid range?

func ReadFileFunc

func ReadFileFunc(file string, f func([]string) error) error

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.

func ReadFunc

func ReadFunc(r io.Reader, f func([]string) error) error

ReadFunc reads csv data 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 CharaInfo

type CharaInfo struct {
	ID int64

	Name       string // formal name
	CallName   string // name when is called
	NickName   string // friendly name
	MasterName string // call for you
}

type Character

type Character struct {
	CharaInfo
	Parameter
}

Character defined by csv

type Config

type Config struct {
	Dir          string // extracting CSV directory
	CharaPattern string
}

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

func (*Ints) Get added in v0.4.0

func (v *Ints) Get(i int) int64

func (*Ints) Len added in v0.4.0

func (v *Ints) Len() int

type NameIndex

type NameIndex map[string]int

NameIndex holds indexes corresponding to each Name defined in CSV.

func (NameIndex) GetIndex

func (ni NameIndex) GetIndex(name string) int

return index of name. if not found return IndexNotFound

func (NameIndex) Has

func (ni NameIndex) Has(name string) bool

return name is exist?

type Names

type Names []string

Names has CSV defined names.

func (Names) Get

func (ns Names) Get(i int) string

as like name := names[i]

func (Names) InRange

func (ns Names) InRange(index int) bool

check whether index is valid range?

func (Names) Len

func (ns Names) Len() int

return size of array.

type NumberConstants added in v0.3.0

type NumberConstants struct {
	ParamLvs []int64
	ExpLvs   []int64
}

Number constants excepted from CSV names.

type Parameter

type Parameter struct {
	// contains filtered or unexported fields
}

Parameter is variables which are numbers or strings.

func (Parameter) GetIntMap

func (p Parameter) GetIntMap() map[string][]int64

return int64 variable map which can affect original values.

func (Parameter) GetStrMap

func (p Parameter) GetStrMap() map[string][]string

return string variable map which can affect original values.

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.

func NewReader added in v0.4.0

func NewReader(r io.Reader) *Reader

NewReader creates Reader instance for io.Reader of a csv file.

func (*Reader) Read added in v0.4.0

func (r *Reader) Read() ([]string, error)

Read reads a csv record from io.Reader. Calling it advances underlying buffer position. It returns a record contains some fields and error if read failed, except that if reader reached EOF, it returns (nil, io.EOF).

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 VarScope

type VarScope uint8

VarScope indicates where are the variables used.

type VariableSpec added in v0.6.0

type VariableSpec struct {
	VarName string
	Scope   VarScope
	Size    uint64
}

VariableSpec defines the spec of user defined varables.

Jump to

Keyboard shortcuts

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