diff --git a/define/component.go b/define/component.go index 869c62b..4247840 100644 --- a/define/component.go +++ b/define/component.go @@ -33,14 +33,6 @@ func Component[COMP any](name ...string) ComponentDefinition { } } -// ComponentInterface 定义有接口的组件 -func ComponentInterface[COMP, COMP_IFACE any]() ComponentDefinition { - return ComponentDefinition{ - Prototype: pt.DefaultComponentLib().Declare(types.ZeroT[COMP]()).Prototype(), - Name: types.FullNameT[COMP_IFACE](), - } -} - // ComponentDefinition 组件定义 type ComponentDefinition struct { Prototype string // 组件原型名称 diff --git a/pt/entity.go b/pt/entity.go index c9c5983..30d4ca6 100644 --- a/pt/entity.go +++ b/pt/entity.go @@ -33,6 +33,7 @@ type ComponentDesc struct { PT ComponentPT // 组件原型 Name string // 组件名称 NonRemovable bool // 不可删除 + CustomAtti CustomAtti // 自定义原型属性 } // EntityPT 实体原型接口 @@ -47,6 +48,8 @@ type EntityPT interface { ComponentAwakeOnFirstTouch() *bool // ComponentUniqueID 开启组件唯一Id ComponentUniqueID() *bool + // CustomAtti 自定义原型属性 + CustomAtti() CustomAtti // CountComponents // 组件数量 CountComponents() int // Component 获取组件 @@ -63,6 +66,7 @@ type _EntityPT struct { scope *ec.Scope componentAwakeOnFirstTouch *bool componentUniqueID *bool + customAtti CustomAtti components []ComponentDesc } @@ -96,6 +100,11 @@ func (pt *_EntityPT) CountComponents() int { return len(pt.components) } +// CustomAtti 自定义原型属性 +func (pt *_EntityPT) CustomAtti() CustomAtti { + return pt.customAtti +} + // Component 获取组件 func (pt *_EntityPT) Component(idx int) ComponentDesc { if idx < 0 || idx >= len(pt.components) { diff --git a/pt/entitylib.go b/pt/entitylib.go index 1178bd5..93cfd49 100644 --- a/pt/entitylib.go +++ b/pt/entitylib.go @@ -174,6 +174,7 @@ func (lib *_EntityLib) declare(re bool, prototype any, comps ...any) EntityPT { scope: entityAtti.Scope, componentAwakeOnFirstTouch: entityAtti.ComponentAwakeOnFirstTouch, componentUniqueID: entityAtti.ComponentUniqueID, + customAtti: entityAtti.CustomAtti, } if entityAtti.Instance != nil { @@ -205,11 +206,13 @@ func (lib *_EntityLib) declare(re bool, prototype any, comps ...any) EntityPT { case CompAtti: compDesc.Name = v.Name compDesc.NonRemovable = v.NonRemovable + compDesc.CustomAtti = v.CustomAtti comp = v.Instance goto retry case *CompAtti: compDesc.Name = v.Name compDesc.NonRemovable = v.NonRemovable + compDesc.CustomAtti = v.CustomAtti comp = v.Instance goto retry case string: diff --git a/pt/entitylib_declare.go b/pt/entitylib_declare.go index 5b906f5..fc2e0a2 100644 --- a/pt/entitylib_declare.go +++ b/pt/entitylib_declare.go @@ -21,50 +21,48 @@ package pt import ( "git.golaxy.org/core/ec" - "git.golaxy.org/core/utils/types" + "git.golaxy.org/core/utils/generic" ) +// CustomAtti 自定义原型属性 +type CustomAtti = generic.SliceMap[string, any] + // EntityAtti 实体原型属性 type EntityAtti struct { - Prototype string // 实体原型名称(必填) - Instance any // 实体实例 - Scope *ec.Scope // 可访问作用域 - ComponentAwakeOnFirstTouch *bool // 开启组件被首次访问时,检测并调用Awake() - ComponentUniqueID *bool // 开启组件唯一Id + Prototype string // 实体原型名称(必填) + Instance any // 实体实例 + Scope *ec.Scope // 可访问作用域 + ComponentAwakeOnFirstTouch *bool // 开启组件被首次访问时,检测并调用Awake() + ComponentUniqueID *bool // 开启组件唯一Id + CustomAtti CustomAtti // 自定义原型属性 } // EntityWith 创建实体原型属性,用于注册实体原型时自定义相关属性 -func EntityWith(prototype string, inst any, scope *ec.Scope, componentAwakeOnFirstTouch, componentUniqueID *bool) EntityAtti { +func EntityWith(prototype string, inst any, scope *ec.Scope, componentAwakeOnFirstTouch, componentUniqueID *bool, customAtti ...generic.KV[string, any]) EntityAtti { return EntityAtti{ Prototype: prototype, Instance: inst, Scope: scope, ComponentAwakeOnFirstTouch: componentAwakeOnFirstTouch, ComponentUniqueID: componentUniqueID, + CustomAtti: generic.MakeSliceMap(customAtti...), } } // CompAtti 组件原型属性 type CompAtti struct { - Instance any // 组件实例(必填) - Name string // 组件名称 - NonRemovable bool // 是否不可删除 + Instance any // 组件实例(必填) + Name string // 组件名称 + NonRemovable bool // 是否不可删除 + CustomAtti CustomAtti // 自定义原型属性 } // CompWith 创建组件原型属性,用于注册实体原型时自定义相关属性 -func CompWith(inst any, name string, nonRemovable bool) CompAtti { +func CompWith(inst any, name string, nonRemovable bool, customAtti ...generic.KV[string, any]) CompAtti { return CompAtti{ Instance: inst, Name: name, NonRemovable: nonRemovable, - } -} - -// CompInterfaceWith 创建组件原型属性,用于注册实体原型时使用接口名作为组件名称,并自定义相关属性 -func CompInterfaceWith[FACE any](inst any, nonRemovable bool) CompAtti { - return CompAtti{ - Instance: inst, - Name: types.FullNameT[FACE](), - NonRemovable: nonRemovable, + CustomAtti: generic.MakeSliceMap(customAtti...), } }