Rename class: Entity -> Creature
This commit is contained in:
4
mods/CORE/Creature/init.lua
Normal file
4
mods/CORE/Creature/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__core__creature')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('Creature')
|
||||||
1
mods/CORE/Creature/mod.conf
Normal file
1
mods/CORE/Creature/mod.conf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name = smc__core__creature
|
||||||
@@ -2,11 +2,11 @@ local getInstance, extend = Class.getInstance, Class.extend
|
|||||||
|
|
||||||
local tableCopy, tableMerge = table.copy, table.merge
|
local tableCopy, tableMerge = table.copy, table.merge
|
||||||
|
|
||||||
---@class Entity
|
---@class Creature
|
||||||
---@field entityDef Entity.EntityDefinition
|
---@field entityDef Creature.CreatureDefinition
|
||||||
---@field luantiDef EntityDefinition
|
---@field luantiDef EntityDefinition
|
||||||
---@field defaultDef Entity.EntityDefinition
|
---@field defaultDef Creature.CreatureDefinition
|
||||||
local Entity = {
|
local Creature = {
|
||||||
defaultDef = {
|
defaultDef = {
|
||||||
settings = {
|
settings = {
|
||||||
_name = '',
|
_name = '',
|
||||||
@@ -23,7 +23,7 @@ local defMerge = function(...)
|
|||||||
return tableMerge(...)
|
return tableMerge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entityDef Entity.EntityDefinition
|
---@param entityDef Creature.CreatureDefinition
|
||||||
---@return EntityDefinition
|
---@return EntityDefinition
|
||||||
local function entityDefToLuantiDef(entityDef)
|
local function entityDefToLuantiDef(entityDef)
|
||||||
entityDef = tableCopy(entityDef)
|
entityDef = tableCopy(entityDef)
|
||||||
@@ -36,14 +36,14 @@ local function entityDefToLuantiDef(entityDef)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---The alias `table.merge` for EmmyLua
|
---The alias `table.merge` for EmmyLua
|
||||||
---@type fun(...):(Entity.EntityDefinition)
|
---@type fun(...):(Creature.CreatureDefinition)
|
||||||
local defMerge = function(...)
|
local defMerge = function(...)
|
||||||
return tableMerge(...)
|
return tableMerge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entityDef Entity.EntityDefinition
|
---@param entityDef Creature.CreatureDefinition
|
||||||
---@return Entity
|
---@return Creature
|
||||||
function Entity:new(entityDef)
|
function Creature:new(entityDef)
|
||||||
-- Adding default parameters
|
-- Adding default parameters
|
||||||
entityDef = defMerge(entityDef, self.defaultDef, true)
|
entityDef = defMerge(entityDef, self.defaultDef, true)
|
||||||
local s = entityDef.settings
|
local s = entityDef.settings
|
||||||
@@ -52,7 +52,7 @@ function Entity:new(entityDef)
|
|||||||
s._name = Mod.getInfo().shortName .. ':' .. s._name
|
s._name = Mod.getInfo().shortName .. ':' .. s._name
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type Entity
|
---@type Creature
|
||||||
local instance = getInstance(self, {})
|
local instance = getInstance(self, {})
|
||||||
|
|
||||||
local luantiDef = entityDefToLuantiDef(entityDef)
|
local luantiDef = entityDefToLuantiDef(entityDef)
|
||||||
@@ -68,12 +68,12 @@ end
|
|||||||
---Allows you to create a child class of an entity by specifying
|
---Allows you to create a child class of an entity by specifying
|
||||||
---default parameters that will be added to the entity's parameters
|
---default parameters that will be added to the entity's parameters
|
||||||
---when an instance is received.
|
---when an instance is received.
|
||||||
---@param defaultDef Entity.EntityDefinition
|
---@param defaultDef Creature.CreatureDefinition
|
||||||
---@return Entity
|
---@return Creature
|
||||||
function Entity:getExtended(defaultDef)
|
function Creature:getExtended(defaultDef)
|
||||||
defaultDef = defMerge(self.defaultDef, defaultDef)
|
defaultDef = defMerge(self.defaultDef, defaultDef)
|
||||||
|
|
||||||
---@type Entity
|
---@type Creature
|
||||||
local ChildClass = extend(self, {
|
local ChildClass = extend(self, {
|
||||||
defaultDef = defaultDef,
|
defaultDef = defaultDef,
|
||||||
})
|
})
|
||||||
@@ -81,4 +81,4 @@ function Entity:getExtended(defaultDef)
|
|||||||
return ChildClass
|
return ChildClass
|
||||||
end
|
end
|
||||||
|
|
||||||
return Entity
|
return Creature
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
---@class Entity.Callbacks
|
---@class Creature.Callbacks
|
||||||
local Callbacks = {}
|
local Callbacks = {}
|
||||||
|
|
||||||
---Called when the object is instantiated.
|
---Called when the object is instantiated.
|
||||||
--- * `dtime_s` is the time passed since the object was unloaded,
|
--- * `dtime_s` is the time passed since the object was unloaded,
|
||||||
---which can be used for updating the entity state.
|
---which can be used for updating the entity state.
|
||||||
---@type fun(self, staticdata:string, dtime_s:number)?
|
---@type fun(self:LuaEntity, staticdata:string, dtime_s:number)?
|
||||||
Callbacks.on_activate = nil
|
Callbacks.on_activate = nil
|
||||||
|
|
||||||
---Called when the object is about to get removed or unloaded.
|
---Called when the object is about to get removed or unloaded.
|
||||||
@@ -15,16 +15,15 @@ Callbacks.on_activate = nil
|
|||||||
---Note that this won't be called if the object hasn't been activated in the first place.
|
---Note that this won't be called if the object hasn't been activated in the first place.
|
||||||
---In particular, `core.clear_objects({mode = "full"})` won't call this,
|
---In particular, `core.clear_objects({mode = "full"})` won't call this,
|
||||||
---whereas `core.clear_objects({mode = "quick"})` might call this.
|
---whereas `core.clear_objects({mode = "quick"})` might call this.
|
||||||
---@type fun(self, removal:boolean)?
|
---@type fun(self:LuaEntity, removal:boolean)?
|
||||||
Callbacks.on_deactivate = nil
|
Callbacks.on_deactivate = nil
|
||||||
|
|
||||||
---Called on every server tick, after movement and collision processing.
|
---Called on every server tick, after movement and collision processing.
|
||||||
--- * `dtime`: elapsed time since last call
|
--- * `dtime`: elapsed time since last call
|
||||||
--- * `s`: table with collision info (only available if `physical=true`)
|
--- * `s`: table with collision info (only available if `physical=true`)
|
||||||
---@type fun(self, dtime:number, moveresult:table)? -- TODO: дописать более точный тип moveresult
|
---@type fun(self:LuaEntity, dtime:number, moveresult:table)? -- TODO: дописать более точный тип moveresult
|
||||||
Callbacks.on_step = nil
|
Callbacks.on_step = nil
|
||||||
|
|
||||||
|
|
||||||
---Called when somebody punches the object.
|
---Called when somebody punches the object.
|
||||||
---Note that you probably want to handle most punches using the automatic armor group system.
|
---Note that you probably want to handle most punches using the automatic armor group system.
|
||||||
--- * `puncher`: an `ObjectRef `(can be `nil`)
|
--- * `puncher`: an `ObjectRef `(can be `nil`)
|
||||||
@@ -34,42 +33,40 @@ Callbacks.on_step = nil
|
|||||||
--- * `damage``: damage that will be done to entity.
|
--- * `damage``: damage that will be done to entity.
|
||||||
---
|
---
|
||||||
---Can return `true` to prevent the default damage mechanism.
|
---Can return `true` to prevent the default damage mechanism.
|
||||||
---@type (fun(self, puncher:ObjectRef|Player|nil, time_from_last_punch:number|nil, tool_capabilities:table|nil, dir:vector, damage:number):boolean)? -- TODO: дописать более точный тип для tool_capabilities
|
---@type (fun(self:LuaEntity, puncher:ObjectRef|Player|nil, time_from_last_punch:number|nil, tool_capabilities:table|nil, dir:vector, damage:number):boolean)? -- TODO: дописать более точный тип для tool_capabilities
|
||||||
Callbacks.on_punch = nil
|
Callbacks.on_punch = nil
|
||||||
|
|
||||||
---Called when the object dies.
|
---Called when the object dies.
|
||||||
--- * `killer`: an `ObjectRef` (can be `nil`)
|
--- * `killer`: an `ObjectRef` (can be `nil`)
|
||||||
---@type fun(self, killer:ObjectRef|Player|nil)?
|
---@type fun(self:LuaEntity, killer:ObjectRef|Player|nil)?
|
||||||
Callbacks.on_death = nil
|
Callbacks.on_death = nil
|
||||||
|
|
||||||
---Called when `clicker` pressed the 'place/use' key while
|
---Called when `clicker` pressed the 'place/use' key while
|
||||||
---pointing to the object (not necessarily an actual rightclick)
|
---pointing to the object (not necessarily an actual rightclick)
|
||||||
--- * `clicker`: an `ObjectRef` (may or may not be a player)
|
--- * `clicker`: an `ObjectRef` (may or may not be a player)
|
||||||
---@type fun(self, clicker:ObjectRef|Player)?
|
---@type fun(self:LuaEntity, clicker:ObjectRef|Player)?
|
||||||
Callbacks.on_rightclick = nil
|
Callbacks.on_rightclick = nil
|
||||||
|
|
||||||
|
|
||||||
---Called after another object is attached to this object.
|
---Called after another object is attached to this object.
|
||||||
--- * `child`: an `ObjectRef` of the child
|
--- * `child`: an `ObjectRef` of the child
|
||||||
---@type fun(self, child:ObjectRef)?
|
---@type fun(self:LuaEntity, child:ObjectRef)?
|
||||||
Callbacks.on_attach_child = nil
|
Callbacks.on_attach_child = nil
|
||||||
|
|
||||||
---Called after another object has detached from this object.
|
---Called after another object has detached from this object.
|
||||||
--- * `child`: an `ObjectRef` of the child
|
--- * `child`: an `ObjectRef` of the child
|
||||||
---@type fun(self, child:ObjectRef)?
|
---@type fun(self:LuaEntity, child:ObjectRef)?
|
||||||
Callbacks.on_detach_child = nil
|
Callbacks.on_detach_child = nil
|
||||||
|
|
||||||
|
|
||||||
---Called after detaching from another object.
|
---Called after detaching from another object.
|
||||||
--- * `parent`: an ObjectRef from where it got detached
|
--- * `parent`: an ObjectRef from where it got detached
|
||||||
---
|
---
|
||||||
---**Note**: this is also called before removal from the world.
|
---**Note**: this is also called before removal from the world.
|
||||||
---@type fun(self, parent)?
|
---@type fun(self:LuaEntity, parent)?
|
||||||
Callbacks.on_detach = nil
|
Callbacks.on_detach = nil
|
||||||
|
|
||||||
---Should return a string that will be passed to `on_activate` when the object
|
---Should return a string that will be passed to `on_activate` when the object
|
||||||
---is instantiated the next time.
|
---is instantiated the next time.
|
||||||
---@type (fun(self):string)?
|
---@type (fun(self:LuaEntity):string)?
|
||||||
Callbacks.get_staticdata = nil
|
Callbacks.get_staticdata = nil
|
||||||
|
|
||||||
return Callbacks
|
return Callbacks
|
||||||
6
mods/CORE/Creature/src/Creature/CreatureDefinition.lua
Normal file
6
mods/CORE/Creature/src/Creature/CreatureDefinition.lua
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---@class Creature.CreatureDefinition
|
||||||
|
---@field settings Creature.Settings
|
||||||
|
---@field callbacks Creature.Callbacks?
|
||||||
|
local CreatureDefinition = {}
|
||||||
|
|
||||||
|
return CreatureDefinition
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
---@class Entity.Settings
|
---@class Creature.Settings
|
||||||
local Settings = {}
|
local Settings = {}
|
||||||
|
|
||||||
---Registration name for the entity. Must be unique.
|
---Registration name for the entity. Must be unique.
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
local modInfo = Mod.getInfo('smc__core__entity')
|
|
||||||
local require = modInfo.require
|
|
||||||
|
|
||||||
return require('Entity')
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
name = smc__core__entity
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
---@class Entity.EntityDefinition
|
|
||||||
---@field settings Entity.Settings
|
|
||||||
---@field callbacks Entity.Callbacks?
|
|
||||||
local EntityDefinition = {}
|
|
||||||
|
|
||||||
return EntityDefinition
|
|
||||||
Reference in New Issue
Block a user