From a016a2fb31801342e2d663d4e2b1380e261298f9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 7 Aug 2020 13:26:29 +0200 Subject: [PATCH] fix: copy instead of just require dataset --- sonic-radiance.love/game/utils/characters.lua | 8 ++--- sonic-radiance.love/game/utils/datas.lua | 31 +++++++++++++++++++ sonic-radiance.love/game/utils/ennemies.lua | 6 ++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/game/utils/characters.lua b/sonic-radiance.love/game/utils/characters.lua index 465ce30..37fb34b 100644 --- a/sonic-radiance.love/game/utils/characters.lua +++ b/sonic-radiance.love/game/utils/characters.lua @@ -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 diff --git a/sonic-radiance.love/game/utils/datas.lua b/sonic-radiance.love/game/utils/datas.lua index dca4921..59de66a 100644 --- a/sonic-radiance.love/game/utils/datas.lua +++ b/sonic-radiance.love/game/utils/datas.lua @@ -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 diff --git a/sonic-radiance.love/game/utils/ennemies.lua b/sonic-radiance.love/game/utils/ennemies.lua index dbb9444..11a6c83 100644 --- a/sonic-radiance.love/game/utils/ennemies.lua +++ b/sonic-radiance.love/game/utils/ennemies.lua @@ -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