Skip to content
Snippets Groups Projects
Commit aca56e3f authored by Hilel Alvarez--Huguet's avatar Hilel Alvarez--Huguet
Browse files

[edit] utilisation du name space + modification du merge

parent 531aa698
No related branches found
No related tags found
No related merge requests found
...@@ -155,10 +155,10 @@ class AssetList: ...@@ -155,10 +155,10 @@ class AssetList:
return res return res
@classmethod @classmethod
def unserialize(cls, aDict, aBasePath = ""): def unserialize(cls, aDict, aBasePath = "", name_space = None):
a_l = cls(aBasePath) a_l = cls(aBasePath)
for k,v in aDict.items(): for k,v in aDict.items():
a_l.assets[k]=Asset(k, v, base_path=aBasePath) a_l.assets[k]=Asset(k, v, base_path=aBasePath, name_space = name_space)
a_l.set_folders(a_l.assets[k]) a_l.set_folders(a_l.assets[k])
return a_l return a_l
......
...@@ -99,7 +99,8 @@ class UnityFile: ...@@ -99,7 +99,8 @@ class UnityFile:
return os.path.splitext(self.path)[0] return os.path.splitext(self.path)[0]
def get_full_path(self): def get_full_path(self):
return os.path.join(self.base_path, self.path) relative = os.path.join(self.base_path, self.path)
return os.path.abspath(relative)
def is_image(self): def is_image(self):
return self.type == "image" return self.type == "image"
...@@ -128,13 +129,13 @@ class UnityFile: ...@@ -128,13 +129,13 @@ class UnityFile:
def asset_atlas(cls): def asset_atlas(cls):
cls.atlas = {} cls.atlas = {}
cls.rewrite_list = {} cls.rewrite_list = {}
def getinstance(anid, snd_or_dico=None, img=None, txt=None, base_path="", name_space= ''): def getinstance(anid, snd_or_dico=None, img=None, txt=None, base_path="", name_space= None):
if name_space != None: if name_space != None:
anid = cls.check_rewrite(anid, name_space) anid = cls.check_rewrite(anid, name_space)
if anid not in cls.atlas: if anid not in cls.atlas:
cls.atlas[anid] = cls(anid, snd_or_dico, img, txt, base_path)#le name_space n'est pas nécessaire dans ce cas cls.atlas[anid] = cls(anid, snd_or_dico, img, txt, base_path)#le name_space n'est pas nécessaire dans ce cas
elif snd_or_dico != None or img != None or txt != None: elif snd_or_dico != None or img != None or txt != None:
if not cls.atlas[anid].merge(cls(anid, snd_or_dico, img, txt, base_path)): if cls.atlas[anid].merge(cls(anid, snd_or_dico, img, txt, base_path)):
anid = cls.rewrite_id(anid, name_space) anid = cls.rewrite_id(anid, name_space)
cls.atlas[anid] = cls(anid, snd_or_dico, img, txt, base_path) cls.atlas[anid] = cls(anid, snd_or_dico, img, txt, base_path)
return cls.atlas[anid] return cls.atlas[anid]
...@@ -142,7 +143,7 @@ def asset_atlas(cls): ...@@ -142,7 +143,7 @@ def asset_atlas(cls):
@asset_atlas @asset_atlas
class Asset: class Asset:
def __init__(self, anid, snd_or_dico=None, img=None, txt=None, base_path="", name_space = ''): def __init__(self, anid, snd_or_dico=None, img=None, txt=None, base_path="", name_space = None):
self.mid = anid self.mid = anid
self.lang = None self.lang = None
self.transcript = None self.transcript = None
...@@ -302,18 +303,16 @@ class Asset: ...@@ -302,18 +303,16 @@ class Asset:
def merge(self, other): def merge(self, other):
merged = False merged = False
if self != other and self.mid == other.mid: if str(self) != str(other) and self.mid == other.mid:
if not( if not(self.snd != None and other.snd != None and self.snd.get_full_path() != other.snd.get_full_path()):
self.txt != None or other.txt != None or self.snd = other.snd
(self.snd != None and other.snd != None and self.snd.get_full_path() != other.snd.get_full_path()) or self.set_lang(other.lang)
(self.img != None and other.img != None and self.img.get_full_path() != other.img.get_full_path()) self.txt = other.txt
): #not not mergeable self.transcript = other.transcript
if self.snd == None and other.snd != None: merged = True
self.snd = other.snd if not(self.img != None and other.img != None and self.img.get_full_path() != other.img.get_full_path()):
merged = True self.img = other.img
if self.img == None and other.img != None: merged = True
self.img = other.img
merged = True
return merged return merged
@classmethod @classmethod
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from Backend.asset_list import AssetList from Backend.asset_list import AssetList
from Backend.sessions import Session from Backend.sessions import Session
from pathlib import Path
import json import json
import os import os
...@@ -16,7 +17,7 @@ class Test: ...@@ -16,7 +17,7 @@ class Test:
else: else:
self.base_path = base_path self.base_path = base_path
json_t = json.load(open(json_file_path, encoding="utf8")) json_t = json.load(open(json_file_path, encoding="utf8"))
self.assets = AssetList.unserialize(json_t['assets'], os.path.dirname(json_file_path)) self.assets = AssetList.unserialize(json_t['assets'], os.path.dirname(json_file_path), name_space = Path(self.json_path).stem)
self.sessions = [] self.sessions = []
for s in json_t['sessions']: for s in json_t['sessions']:
self.add_session(Session.unserialize(s)) self.add_session(Session.unserialize(s))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment