-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split game core into different files (#4705)
* Split game core into different files * eof
- Loading branch information
1 parent
187a517
commit 5601a62
Showing
8 changed files
with
300 additions
and
305 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
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
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 |
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,11 @@ | ||
do | ||
local globalStorageTable = {} | ||
|
||
function Game.getStorageValue(key) | ||
return globalStorageTable[key] or -1 | ||
end | ||
|
||
function Game.setStorageValue(key, value) | ||
globalStorageTable[key] = value | ||
end | ||
end |
Oops, something went wrong.