diff --git a/assets.py b/assets.py index 3c7c48fb19ec3dbcbf7de257be88dc3b90541d53..0a3cffea3b145ff9b377c722b1144d3f7320f41e 100755 --- a/assets.py +++ b/assets.py @@ -106,7 +106,7 @@ class UnityFile: print(f"lecture de {self.get_full_path()}") if platform.system() == "Windows": winsound.PlaySound(self.get_full_path(), winsound.SND_FILENAME) - + else: playsound(self.get_full_path(), sync) @@ -118,17 +118,22 @@ class UnityFile: #https://stackoverflow.com/a/7493603/19587593 def asset_atlas(cls): cls.atlas = {} - def getinstance(anid, snd_or_dico=None, img=None, base_path=""): + cls.rewrite_list = {} + def getinstance(anid, snd_or_dico=None, img=None, base_path="", name_space=None): + if name_space != None: + anid = cls.check_rewrite(anid, name_space) if anid not in cls.atlas: - cls.atlas[anid] = cls(anid, snd_or_dico, img, base_path) + cls.atlas[anid] = cls(anid, snd_or_dico, img, base_path)#le name_space n'est pas nécessaire dans ce cas elif snd_or_dico != None or img != None: - cls.atlas[anid].merge(cls(anid, snd_or_dico, img, base_path)) + if not cls.atlas[anid].merge(cls(anid, snd_or_dico, img, base_path)): + anid = cls.rewrite_id(anid, name_space) + cls.atlas[anid] = cls(anid, snd_or_dico, img, base_path) return cls.atlas[anid] return getinstance @asset_atlas class Asset: - def __init__(self, anid, snd_or_dico=None, img=None, base_path=""): + def __init__(self, anid, snd_or_dico=None, img=None, base_path="", name_space = None): self.mid = anid if type(snd_or_dico) == dict: if img == None: @@ -149,6 +154,24 @@ class Asset: else: #path self.img = UnityFile(img, base_path, self.mid) + @classmethod + def rewrite_id(cls, anid, name_space): + if anid in cls.atlas.keys(): + new_id += f"_{name_space}" + while new_id in cls.atlas.keys(): + new_id += name_space + if name_space not in cls.rewrite_list.keys(): + cls.rewrite_list[name_space] = {} + cls.rewrite_list[name_space][anid] = new_id + return new_id + + @classmethod + def check_rewrite(cls, anid, name_space): + if name_space in cls.rewrite_list.keys() and anid in cls.rewrite_list[name_space].keys(): + return cls.rewrite_list[name_space][anid] + else: + return anid + def set_id(self, new_id): self.mid = new_id