forked from mtcontrib/maidroid
remove core_name field of maidroid and fix
This commit is contained in:
parent
02f4d13af0
commit
158e9bde5d
@ -61,12 +61,13 @@ end
|
|||||||
|
|
||||||
-- maidroid.maidroid.get_core_name returns a name of a maidroid's current core.
|
-- maidroid.maidroid.get_core_name returns a name of a maidroid's current core.
|
||||||
function maidroid.maidroid.get_core_name(self)
|
function maidroid.maidroid.get_core_name(self)
|
||||||
return self.core_name
|
local inv = self:get_inventory()
|
||||||
|
return inv:get_stack("core", 1):get_name()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- maidroid.maidroid.get_core returns a maidroid's current core definition.
|
-- maidroid.maidroid.get_core returns a maidroid's current core definition.
|
||||||
function maidroid.maidroid.get_core(self)
|
function maidroid.maidroid.get_core(self)
|
||||||
local name = self:get_core_name(self)
|
local name = self:get_core_name()
|
||||||
if name ~= "" then
|
if name ~= "" then
|
||||||
return maidroid.registered_cores[name]
|
return maidroid.registered_cores[name]
|
||||||
end
|
end
|
||||||
@ -342,14 +343,15 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function update_infotext(self)
|
local function update_infotext(self)
|
||||||
if self.core_name ~= "" then
|
local core_name = self:get_core_name()
|
||||||
|
if core_name ~= "" then
|
||||||
local infotext = ""
|
local infotext = ""
|
||||||
if self.pause then
|
if self.pause then
|
||||||
infotext = infotext .. "this maidroid is paused\n"
|
infotext = infotext .. "this maidroid is paused\n"
|
||||||
else
|
else
|
||||||
infotext = infotext .. "this maidroid is active\n"
|
infotext = infotext .. "this maidroid is active\n"
|
||||||
end
|
end
|
||||||
infotext = infotext .. "[Core] : " .. self.core_name
|
infotext = infotext .. "[Core] : " .. core_name
|
||||||
|
|
||||||
self.object:set_properties{infotext = infotext}
|
self.object:set_properties{infotext = infotext}
|
||||||
return
|
return
|
||||||
@ -366,7 +368,6 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
local core_name = stack:get_name()
|
local core_name = stack:get_name()
|
||||||
local core = maidroid.registered_cores[core_name]
|
local core = maidroid.registered_cores[core_name]
|
||||||
core.on_start(self)
|
core.on_start(self)
|
||||||
self.core_name = core_name
|
|
||||||
|
|
||||||
update_infotext(self)
|
update_infotext(self)
|
||||||
end
|
end
|
||||||
@ -386,8 +387,8 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
|
|
||||||
on_take = function(inv, listname, index, stack, player)
|
on_take = function(inv, listname, index, stack, player)
|
||||||
if listname == "core" then
|
if listname == "core" then
|
||||||
local core = maidroid.registered_cores[self.core_name]
|
local core_name = stack:get_name()
|
||||||
self.core_name = ""
|
local core = maidroid.registered_cores[core_name]
|
||||||
core.on_stop(self)
|
core.on_stop(self)
|
||||||
|
|
||||||
update_infotext(self)
|
update_infotext(self)
|
||||||
@ -514,8 +515,8 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
pickup_item(self)
|
pickup_item(self)
|
||||||
|
|
||||||
-- do core method.
|
-- do core method.
|
||||||
if (not self.pause) and self.core_name ~= "" then
|
local core = self:get_core()
|
||||||
local core = maidroid.registered_cores[self.core_name]
|
if (not self.pause) and core then
|
||||||
core.on_step(self, dtime)
|
core.on_step(self, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -531,16 +532,15 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
|
|
||||||
-- on_punch is a callback function that is called when a player punch then.
|
-- on_punch is a callback function that is called when a player punch then.
|
||||||
local function on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
local function on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||||
|
local core = self:get_core()
|
||||||
if self.pause == true then
|
if self.pause == true then
|
||||||
self.pause = false
|
self.pause = false
|
||||||
if self.core_name ~= "" then
|
if core then
|
||||||
local core = maidroid.registered_cores[self.core_name]
|
|
||||||
core.on_resume(self)
|
core.on_resume(self)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.pause = true
|
self.pause = true
|
||||||
if self.core_name ~= "" then
|
if core then
|
||||||
local core = maidroid.registered_cores[self.core_name]
|
|
||||||
core.on_pause(self)
|
core.on_pause(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -569,7 +569,6 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
pause = false,
|
pause = false,
|
||||||
product_name = "",
|
product_name = "",
|
||||||
manufacturing_number = -1,
|
manufacturing_number = -1,
|
||||||
core_name = "",
|
|
||||||
|
|
||||||
-- callback methods.
|
-- callback methods.
|
||||||
on_activate = on_activate,
|
on_activate = on_activate,
|
||||||
|
Loading…
Reference in New Issue
Block a user