modifyx

package
v0.0.0-...-4da1013 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

modifyz 配置修正系统

  • 提供字段修正的功能,通常用于配置对象
  • 提供的配置修正包括 加成和修正
  • 配置修正对象只在初始化时赋值
  • map和数组的内容无法通过修正增加或者减少,配置修正只对已存在的值进行修正
  • 配置修正不支持any类型的修正

优化

  • 经过测试,使用数组保存数据,比map性能高很多,后期可考虑这个方向的优化
  • 如果采用数组保存数据,配置文件会比较麻烦,在编辑器完成后考虑
  • 采用数组需要字段数量,预创建数组,因此,需要descz的支持

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateBonusFactor

func CalculateBonusFactor(x float64, a IBonus, useFactor, useMultiplier, useBonus bool) (y float64)

y = x * (1 + Factor)* Multiplier + Bonus

func ParseKey

func ParseKey(key string) (kind, id string)

Types

type A

type A = []interface{}

type Array

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

修正对象 如果需要在运行时,替换源的数据,可通过设置runtime实现

func (*Array) Dispose

func (s *Array) Dispose()

func (*Array) RefBool

func (s *Array) RefBool(field int) bool

修正后的整型

func (*Array) RefFloat

func (s *Array) RefFloat(field int) float64

修正后的浮点型

func (*Array) RefInt

func (s *Array) RefInt(field int) int

修正后的整型

func (*Array) RefLength

func (s *Array) RefLength() int

func (*Array) RefObject

func (s *Array) RefObject(index int) (r IObject)

func (*Array) RefSourceData

func (s *Array) RefSourceData() []interface{}

获取原始数据

func (*Array) RefString

func (s *Array) RefString(index int) (val string)

func (*Array) RefUint

func (s *Array) RefUint(index int) (val uint)

type Bonus

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

func NewBonus

func NewBonus(key string) (obj *Bonus)

func NewBonusAll

func NewBonusAll(key string, bonus, factor, multiplier float64) (obj *Bonus)

func (Bonus) Bonus

func (b Bonus) Bonus() float64

func (*Bonus) Combine

func (a *Bonus) Combine(b IBonus)

func (*Bonus) Factor

func (b *Bonus) Factor() float64

func (*Bonus) Key

func (b *Bonus) Key() string

func (Bonus) Multiplier

func (b Bonus) Multiplier() float64

func (*Bonus) SetBonus

func (b *Bonus) SetBonus(val float64) *Bonus

func (*Bonus) SetFactor

func (b *Bonus) SetFactor(val float64) *Bonus

func (*Bonus) SetKey

func (b *Bonus) SetKey(val string) *Bonus

func (*Bonus) SetMultiplier

func (b *Bonus) SetMultiplier(val float64) *Bonus

func (*Bonus) Valid

func (a *Bonus) Valid() bool

type IArray

type IArray interface {
	RefInt(index int) (val int)
	RefUint(index int) (val uint)
	RefFloat(index int) (val float64)
	RefString(index int) (val string)
	RefBool(index int) (val bool)
	RefObject(index int) (r IObject)
	RefLength() int
}

type IBonus

type IBonus interface {
	Key() string
	Factor() float64
	Multiplier() float64
	Bonus() float64
	Valid() bool
}

type IModify

type IModify interface {
	Key() string
	Valid() bool
	Value(old interface{}) (last interface{})
}

type IObject

type IObject interface {
	RefSourceData() map[string]interface{}
	RefSource(field string) interface{}
	RefInt(field string) (val int)
	RefUint(field string) (val uint)
	RefFloat64(field string) (val float64)
	RefString(field string) (val string)
	RefBool(field string) (val bool)
	RefMap(field string) (r IObject)
	RefObject(field string) (r IObject)
	RefArray(field string) (r IArray)
	RefIsNil() bool
	RefKeys() (r []string)
	RefLength() int
	RefClassCreator(field string, creator func(object IObject) IObject)

	SetRuntimeFloat(field string, val float64)
	SetRuntimeInt(field string, val int)
	SetRuntimeBool(field string, val bool)
	SetRuntimeString(field string, val string)
}

type IPool

type IPool interface {
	// 属性是否发生了变化
	IsPropChanged(key string, version int) bool
	GetNewPropInt(key string, val int) (r int, ver int)
	GetNewPropStruct(key string) (r map[string]interface{}, ver int)
	GetNewPropFloat(key string, val int) (r map[string]interface{}, ver int)
	GetNewPropBool(key string, val bool) (r bool, ver int)
}

type IRoot

type IRoot interface {
	IObject

	RefClassId() string
	// Catalog/Id
	RefClassKey() string
	RefClassCatalog() string
	RefClassType() string
	RefDispose()
	RefData() map[string]interface{}
}

type M

type M = map[string]interface{}

type Object

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

修正对象 如果需要在运行时,替换源的数据,可通过设置runtime实现

func NewObject

func NewObject(src *Source) (obj *Object)

新建一个对象

func (*Object) Dispose

func (s *Object) Dispose()

func (*Object) GetArrayFloatModify

func (s *Object) GetArrayFloatModify() (r []float64)

只用于无修正场合

func (*Object) GetMapFloat

func (s *Object) GetMapFloat() (r map[string]float64)

func (*Object) GetMapFloatModify

func (s *Object) GetMapFloatModify() (r map[string]float64)

func (*Object) MapKeyOf

func (s *Object) MapKeyOf(conf func(item interface{}) bool) string

只用于无修正场合

func (*Object) RefArray

func (s *Object) RefArray(field string) (r IArray)

func (*Object) RefBool

func (s *Object) RefBool(field string) bool

修正后的整型

func (*Object) RefClassCreator

func (s *Object) RefClassCreator(field string, creator func(object IObject) IObject)

func (*Object) RefClassName

func (s *Object) RefClassName() string

func (*Object) RefFloat64

func (s *Object) RefFloat64(field string) float64

修正后的浮点型

func (*Object) RefInt

func (s *Object) RefInt(field string) int

修正后的整型

func (*Object) RefIsNil

func (s *Object) RefIsNil() bool

func (*Object) RefKeys

func (s *Object) RefKeys() (r []string)

func (*Object) RefLength

func (s *Object) RefLength() int

func (*Object) RefMap

func (s *Object) RefMap(field string) (r IObject)

func (*Object) RefObject

func (s *Object) RefObject(field string) (r IObject)

func (*Object) RefSource

func (s *Object) RefSource(field string) interface{}

RefSource 获取原始数据指定的字段

func (*Object) RefSourceData

func (s *Object) RefSourceData() (origin map[string]interface{})

RefSourceData 获取原始数据 可通过 mapx.Int(origin, fieldName)获取指定内容的值

func (*Object) RefString

func (s *Object) RefString(field string) (val string)

func (*Object) RefUint

func (s *Object) RefUint(field string) (val uint)

func (*Object) SetRuntimeBool

func (s *Object) SetRuntimeBool(field string, val bool)

func (*Object) SetRuntimeFloat

func (s *Object) SetRuntimeFloat(field string, val float64)

SetRuntimeFloat 运行时修改的数据, 用于直接替换掉origin数据, 再进行池修正 用于已知目标的情况下使用, 可提高运行效率, 例如初始化时, 为目标单位赋予初值 注: 需要注意设置的类型

func (*Object) SetRuntimeInt

func (s *Object) SetRuntimeInt(field string, val int)

func (*Object) SetRuntimeString

func (s *Object) SetRuntimeString(field string, val string)

func (*Object) ToArrayString

func (s *Object) ToArrayString() (r []string)

只用于无修正场合

func (*Object) ToMapString

func (s *Object) ToMapString() (r map[string]string)

只用于无修正场合

type Pool

type Pool struct {
	//
	Parent *Pool
	// key=结构/属性
	// 例如=CUnit/Vital/Life/Max或 CEffectDamage/Amount
	BonusList map[string]listx.List
	//
	ModifyList map[string]listx.List
	// contains filtered or unexported fields
}

func NewPool

func NewPool() (obj *Pool)

func (*Pool) AddBonus

func (p *Pool) AddBonus(val IBonus, version int)

key为需要修正的属性 例如: key=CEffectDamage/Amount

func (*Pool) AddModify

func (p *Pool) AddModify(val IModify, version int)

co.CModify

func (*Pool) IsPropChanged

func (p *Pool) IsPropChanged(key string, version int) bool

func (*Pool) RemoveBonus

func (p *Pool) RemoveBonus(val IBonus, version int)

func (*Pool) RemoveModify

func (p *Pool) RemoveModify(val IModify, version int)

func (*Pool) SetVersion

func (p *Pool) SetVersion(key string, version int)

增加指定键值的版本号

type PoolList

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

func NewPoolList

func NewPoolList() (obj *PoolList)

func (*PoolList) Dispose

func (p *PoolList) Dispose()

func (*PoolList) GetNewPropBool

func (p *PoolList) GetNewPropBool(key string, val bool) (r bool)

func (*PoolList) GetNewPropFloat

func (p *PoolList) GetNewPropFloat(key string, val float64) (r float64)

func (*PoolList) GetNewPropInt

func (p *PoolList) GetNewPropInt(key string, val int) (r int)

func (*PoolList) GetNewestVersion

func (p *PoolList) GetNewestVersion() int

func (*PoolList) IsPropChanged

func (p *PoolList) IsPropChanged(key string) bool

func (*PoolList) SetHost

func (p *PoolList) SetHost(pool *Pool)

func (*PoolList) SetNewestVersionCreator

func (p *PoolList) SetNewestVersionCreator(val func() int)

func (*PoolList) SetRoot

func (p *PoolList) SetRoot(pool *Pool)

type Root

type Root struct {
	*Object
}

func NewRoot

func NewRoot(source *Source) *Root

func (*Root) GetPools

func (s *Root) GetPools() *PoolList

func (*Root) RefClassId

func (s *Root) RefClassId() string

func (*Root) RefClassKey

func (s *Root) RefClassKey() string

func (*Root) RefClassKind

func (s *Root) RefClassKind() string

func (*Root) RefData

func (s *Root) RefData() map[string]interface{}

func (*Root) RefDispose

func (s *Root) RefDispose()

func (*Root) RefReset

func (s *Root) RefReset()

重置版本和host

func (*Root) RefResetVersion

func (s *Root) RefResetVersion()

func (*Root) Source

func (s *Root) Source() *Source

type Source

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

数据源 通常加载后,数据源不可变,作为配置文件的映射 采用数据源的目的是为了避免数据的克隆影响性能,毕竟需要修正的地方有限

func NewSource

func NewSource() *Source

className = origin["_type"]

func NewSourceWith

func NewSourceWith(origin datax.M) *Source

func (*Source) ClassId

func (s *Source) ClassId() string

func (*Source) ClassKey

func (s *Source) ClassKey() string

func (*Source) ClassKind

func (s *Source) ClassKind() string

func (*Source) ClassName

func (s *Source) ClassName() string

func (*Source) Clone

func (s *Source) Clone() (r *Source)

func (*Source) Dispose

func (s *Source) Dispose()

func (*Source) GetPools

func (s *Source) GetPools() *PoolList

func (*Source) SetClassId

func (s *Source) SetClassId(val string)

Jump to

Keyboard shortcuts

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