-
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.
Add
base_classes.ObjectState.Storage
. Relates to #1515
- Loading branch information
Showing
5 changed files
with
49 additions
and
44 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
38 changes: 38 additions & 0 deletions
38
mods/lord/Core/base_classes/src/base_classes/ObjectState/Storage.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,38 @@ | ||
--- @static | ||
--- @class base_classes.ObjectState.Storage | ||
local Storage = {} | ||
|
||
--- Obtains `ObjectState` from meta or object properties depending on whether `object` is a player or not | ||
--- @param object Player|Entity | ||
--- @return table | ||
function Storage.get_state_of(object) | ||
if not object then | ||
return | ||
end | ||
|
||
return object:is_player() | ||
and minetest.deserialize(object:get_meta():get("object_state")) | ||
or object:get_luaentity().object_state | ||
end | ||
|
||
--- Obtains `ObjectState` from meta or object properties depending on whether `object` is a player or not | ||
--- @param object ObjectRef a player or an entity to apply `ObjectState` to | ||
--- @param state_table table | ||
function Storage.set_state_of(object, state_table) | ||
if not object then | ||
return | ||
end | ||
|
||
local state_string = minetest.serialize(state_table) | ||
|
||
if object:is_player() then | ||
local meta = object:get_meta() | ||
meta:set_string("object_state", state_string) | ||
else | ||
local entity = object:get_luaentity() | ||
entity.object_state = state_table | ||
end | ||
end | ||
|
||
|
||
return Storage |
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
This file was deleted.
Oops, something went wrong.
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