fix: copy instead of just require dataset

This commit is contained in:
Kazhnuz 2020-08-07 13:26:29 +02:00
parent 04ae4ef657
commit a016a2fb31
3 changed files with 38 additions and 7 deletions

View file

@ -64,10 +64,10 @@ end
function CharUtils.getCharacterData(charname)
-- va eprmettre de récupérer les données d'un personnage
local charfolder = CharUtils.getCharacterDirectory(charname, true)
local character = require(charfolder)
character.stats = datasutils.require(charfolder, "stats")
character.inventory = datasutils.require(charfolder, "inventory")
character.skills = datasutils.require(charfolder, "skills")
local character = datasutils.copy(charfolder)
character.stats = datasutils.copyDataset(charfolder, "stats")
character.inventory = datasutils.copyDataset(charfolder, "inventory")
character.skills = datasutils.copyDataset(charfolder, "skills")
return character
end

View file

@ -28,6 +28,37 @@ function DataUtils.require(parent, filename)
return require(DataUtils.concatFolder(parent, filename, true))
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)
return DataUtils.concatFolder(DataUtils.getGameDataDir(lua), folder, lua)
end

View file

@ -35,9 +35,9 @@ end
function EnnemyUtils.getData(directory, name)
-- va eprmettre de récupérer les données d'un personnage
local folder = EnnemyUtils.getEnnemyFolder(directory, name, true)
local ennemy = require(folder)
ennemy.stats = datasutils.require(folder, "stats")
ennemy.skills = datasutils.require(folder, "skills")
local ennemy = datasutils.copy(folder)
ennemy.stats = datasutils.copyDataset(folder, "stats")
ennemy.skills = datasutils.copyDataset(folder, "skills")
return ennemy
end