Skip to content

Commit

Permalink
Create lord_object_state mod outline (relates to #1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doloment committed Jul 26, 2024
1 parent 5c9950e commit 7aa11f2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mods/lord/_experimental/lord_object_state/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local mod_path = minetest.get_modpath(minetest.get_current_modname())
local old_require = require
require = function(name) return dofile(mod_path .. "/src/" .. name:gsub("%.", "/") .. ".lua") end


require("object_state").init()


require = old_require
2 changes: 2 additions & 0 deletions mods/lord/_experimental/lord_object_state/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = lord_object_state
depends = lordlib
13 changes: 13 additions & 0 deletions mods/lord/_experimental/lord_object_state/src/object_state.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local api = require("object_state.api")

lord_object_state = {}

local function register_api()
_G.lord_bows = api
end

return {
init = function()
register_api()
end,
}
59 changes: 59 additions & 0 deletions mods/lord/_experimental/lord_object_state/src/object_state/api.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--- @class base_classes.ObjectState
local ObjectState = {
--- @type ObjectRef
object = nil,
}

--- @param object ObjectRef
--- @return ObjectState
function ObjectState:new(object)
local class = self
self = {}

self.object = object

return setmetatable(self, {__index = class})
end

---@param player ObjectRef
function ObjectState:get_player_state(player)
local meta = player:get_meta()
local state_string = meta:get("object_state")
local state_table = minetest.deserialize(state_string)
return state_table
end

---@param player ObjectRef
function ObjectState:set_player_state(player, state_table)
local meta = player:get_meta()
local state_string = minetest.serialize(state_table)
meta:set_string("object_state", state_string)
end

---@param object ObjectRef
function ObjectState:get_entity_state(object)
local properties = object:get_properties()
local state_table = properties["object_state"]
return state_table
end

---@param object ObjectRef
function ObjectState:set_entity_state(object, state_table)
local properties = object:get_properties()
properties["object_state"] = state_table
object:set_properties(properties)
end

function ObjectState:add_state(player, state_name, value)
-- body
end

function ObjectState:remove_state()
-- body
end



return {

}

0 comments on commit 7aa11f2

Please sign in to comment.