Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split game core into different files #4705

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading