csv

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2019 License: BSD-3-Clause Imports: 10 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 (

	// 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
	BuiltinExName     = "Ex"     // 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

	// 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 util.FileExists() so that user need not to import util 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
}

Constant is a constant data set defined by a csv file. it contains constant key names Names, and indexes of key in Names, NameIndex.

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) 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

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 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 VarScope

type VarScope uint8

VarScope indicates where are the variables used.

Jump to

Keyboard shortcuts

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