Skip to content

Commit

Permalink
A new way to manage player storages (otland#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT authored Feb 19, 2022
1 parent e20bc71 commit 50f1b46
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions data/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ NORTHEAST = DIRECTION_NORTHEAST
SPEECHBUBBLE_QUESTTRADER = SPEECHBUBBLE_QUEST

do
local function storageProxy(player)
return setmetatable({}, {
__index = function (self, key)
return player:getStorageValue(key)
end,
__newindex = function (self, key, value)
player:setStorageValue(key, value)
end
})
end

local function accountStorageProxy(player)
return setmetatable({}, {
__index = function (self, key)
return Game.getAccountStorageValue(player:getAccountId(), key)
end,
__newindex = function (self, key, value)
Game.setAccountStorageValue(player:getAccountId(), key, value)
end
})
end

local function CreatureIndex(self, key)
local methods = getmetatable(self)
if key == "uid" then
Expand All @@ -62,7 +84,16 @@ do
return 1
elseif key == "actionid" then
return 0
elseif key == "storage" then
if methods.isPlayer(self) then
return storageProxy(self)
end
elseif key == "accountStorage" then
if methods.isPlayer(self) then
return accountStorageProxy(self)
end
end

return methods[key]
end
rawgetmetatable("Player").__index = CreatureIndex
Expand Down

0 comments on commit 50f1b46

Please sign in to comment.