fix: copy instead of just require dataset
This commit is contained in:
parent
04ae4ef657
commit
a016a2fb31
3 changed files with 38 additions and 7 deletions
|
@ -64,10 +64,10 @@ end
|
||||||
function CharUtils.getCharacterData(charname)
|
function CharUtils.getCharacterData(charname)
|
||||||
-- va eprmettre de récupérer les données d'un personnage
|
-- va eprmettre de récupérer les données d'un personnage
|
||||||
local charfolder = CharUtils.getCharacterDirectory(charname, true)
|
local charfolder = CharUtils.getCharacterDirectory(charname, true)
|
||||||
local character = require(charfolder)
|
local character = datasutils.copy(charfolder)
|
||||||
character.stats = datasutils.require(charfolder, "stats")
|
character.stats = datasutils.copyDataset(charfolder, "stats")
|
||||||
character.inventory = datasutils.require(charfolder, "inventory")
|
character.inventory = datasutils.copyDataset(charfolder, "inventory")
|
||||||
character.skills = datasutils.require(charfolder, "skills")
|
character.skills = datasutils.copyDataset(charfolder, "skills")
|
||||||
|
|
||||||
return character
|
return character
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,37 @@ function DataUtils.require(parent, filename)
|
||||||
return require(DataUtils.concatFolder(parent, filename, true))
|
return require(DataUtils.concatFolder(parent, filename, true))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DataUtils.copy(filepath)
|
||||||
|
local orig = require(filepath)
|
||||||
|
local orig_type = type(orig)
|
||||||
|
local copy
|
||||||
|
if orig_type == 'table' then
|
||||||
|
copy = {}
|
||||||
|
for orig_key, orig_value in pairs(orig) do
|
||||||
|
copy[orig_key] = orig_value
|
||||||
|
end
|
||||||
|
else -- number, string, boolean, etc
|
||||||
|
copy = orig
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DataUtils.copyDataset(parent, filename)
|
||||||
|
local orig = DataUtils.require(parent, filename)
|
||||||
|
local orig_type = type(orig)
|
||||||
|
local copy
|
||||||
|
if orig_type == 'table' then
|
||||||
|
copy = {}
|
||||||
|
for orig_key, orig_value in pairs(orig) do
|
||||||
|
copy[orig_key] = orig_value
|
||||||
|
end
|
||||||
|
else -- number, string, boolean, etc
|
||||||
|
copy = orig
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
function DataUtils.concatDataFolder(folder, lua)
|
function DataUtils.concatDataFolder(folder, lua)
|
||||||
return DataUtils.concatFolder(DataUtils.getGameDataDir(lua), folder, lua)
|
return DataUtils.concatFolder(DataUtils.getGameDataDir(lua), folder, lua)
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,9 +35,9 @@ end
|
||||||
function EnnemyUtils.getData(directory, name)
|
function EnnemyUtils.getData(directory, name)
|
||||||
-- va eprmettre de récupérer les données d'un personnage
|
-- va eprmettre de récupérer les données d'un personnage
|
||||||
local folder = EnnemyUtils.getEnnemyFolder(directory, name, true)
|
local folder = EnnemyUtils.getEnnemyFolder(directory, name, true)
|
||||||
local ennemy = require(folder)
|
local ennemy = datasutils.copy(folder)
|
||||||
ennemy.stats = datasutils.require(folder, "stats")
|
ennemy.stats = datasutils.copyDataset(folder, "stats")
|
||||||
ennemy.skills = datasutils.require(folder, "skills")
|
ennemy.skills = datasutils.copyDataset(folder, "skills")
|
||||||
|
|
||||||
return ennemy
|
return ennemy
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue