Skip to content

Commit

Permalink
Split game core into different files (#4705)
Browse files Browse the repository at this point in the history
* Split game core into different files

* eof
  • Loading branch information
ramon-bernardo authored May 26, 2024
1 parent 187a517 commit 5601a62
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 305 deletions.
2 changes: 1 addition & 1 deletion data/lib/core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dofile('data/lib/core/combat.lua')
dofile('data/lib/core/constants.lua')
dofile('data/lib/core/container.lua')
dofile('data/lib/core/creature.lua')
dofile('data/lib/core/game.lua')
dofile('data/lib/core/game/lib.lua')
dofile('data/lib/core/highscores.lua')
dofile('data/lib/core/item.lua')
dofile('data/lib/core/itemtype.lua')
Expand Down
304 changes: 0 additions & 304 deletions data/lib/core/game.lua

This file was deleted.

53 changes: 53 additions & 0 deletions data/lib/core/game/account_storage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
do
local accountsStorage = {}

function Game.getAccountsStorage() return accountsStorage end

function Game.clearAccountStorageValue(accountId, key)
local accountStorage = accountsStorage[accountId]
if accountStorage then
accountStorage[key] = nil
end
end

function Game.getAccountStorageValue(accountId, key)
local accountStorage = accountsStorage[accountId]
return accountStorage and accountStorage[key] or nil
end

function Game.setAccountStorageValue(accountId, key, value)
if not accountsStorage[accountId] then
accountsStorage[accountId] = {}
end
accountsStorage[accountId][key] = value
end

function Game.saveAccountsStorage()
local transaction = DBTransaction()
if not transaction:begin() then
return false
end

local result = db.query("DELETE FROM `account_storage`")
if not result then
return false
end

local accountsStorage = Game.getAccountsStorage()
for accountId, accountStorage in pairs(accountsStorage) do
local query = DBInsert("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES")
for key, value in pairs(accountStorage) do
local success = query:addRow(accountId .. ", " .. key .. ", " .. value)
if not success then
return false
end
end

if not query:execute() then
return false
end
end

return transaction:commit()
end
end
11 changes: 11 additions & 0 deletions data/lib/core/game/global_storage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
do
local globalStorageTable = {}

function Game.getStorageValue(key)
return globalStorageTable[key] or -1
end

function Game.setStorageValue(key, value)
globalStorageTable[key] = value
end
end
Loading

0 comments on commit 5601a62

Please sign in to comment.