-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create lord_object_state mod outline (relates to #1515)
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
mods/lord/_experimental/lord_object_state/src/object_state.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
59
mods/lord/_experimental/lord_object_state/src/object_state/api.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |