fix library references in yaml2mcl compiler
This commit is contained in:
parent
a40a8b3685
commit
ad6c84d6ce
@ -78,6 +78,8 @@ class Yaml2Mcl:
|
|||||||
yl = YAMLLibraryParser(manager)
|
yl = YAMLLibraryParser(manager)
|
||||||
|
|
||||||
# before we load any files, load entity definitions from referenced libraries
|
# before we load any files, load entity definitions from referenced libraries
|
||||||
|
libraryRefGuids = [ ]
|
||||||
|
|
||||||
for libraryRef in libraryReferences:
|
for libraryRef in libraryReferences:
|
||||||
from mocha.library.mcx.dataformats import McxDataFormat
|
from mocha.library.mcx.dataformats import McxDataFormat
|
||||||
from mocha.library.mcx.objectmodels import McxObjectModel
|
from mocha.library.mcx.objectmodels import McxObjectModel
|
||||||
@ -88,6 +90,8 @@ class Yaml2Mcl:
|
|||||||
df.load_internal(om, f)
|
df.load_internal(om, f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
libraryRefGuids.append(om.get_guid())
|
||||||
|
|
||||||
print ("loading entity definitions from library reference '" + libraryRef + "'")
|
print ("loading entity definitions from library reference '" + libraryRef + "'")
|
||||||
|
|
||||||
for (k, v) in om.get_entity_definitions():
|
for (k, v) in om.get_entity_definitions():
|
||||||
@ -103,6 +107,7 @@ class Yaml2Mcl:
|
|||||||
for key in tdfs:
|
for key in tdfs:
|
||||||
yl.register_template(key, tdfs[key], True)
|
yl.register_template(key, tdfs[key], True)
|
||||||
|
|
||||||
|
manager.library_reference_guids = libraryRefGuids
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not os.path.isdir(filename):
|
if not os.path.isdir(filename):
|
||||||
|
|||||||
@ -30,6 +30,8 @@ class MemoryLibraryManager (MochaLibraryManager):
|
|||||||
self.attribute_ops = [ ]
|
self.attribute_ops = [ ]
|
||||||
self.relationship_ops = [ ]
|
self.relationship_ops = [ ]
|
||||||
|
|
||||||
|
self.library_reference_guids = [ ]
|
||||||
|
|
||||||
def process_attribute_ops(self, ops):
|
def process_attribute_ops(self, ops):
|
||||||
self.attribute_ops.extend(ops)
|
self.attribute_ops.extend(ops)
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ class MemoryLibraryManager (MochaLibraryManager):
|
|||||||
# *** SECOND PASS ***
|
# *** SECOND PASS ***
|
||||||
|
|
||||||
# first, go through and load all the instances GUIDs
|
# first, go through and load all the instances GUIDs
|
||||||
refs = [ ]
|
refs_db = [ ]
|
||||||
insts = [ ]
|
insts = [ ]
|
||||||
atts = [ ]
|
atts = [ ]
|
||||||
rels = [ ]
|
rels = [ ]
|
||||||
@ -138,6 +140,9 @@ class MemoryLibraryManager (MochaLibraryManager):
|
|||||||
print(dump)
|
print(dump)
|
||||||
templates_db[str(key2)] = dump
|
templates_db[str(key2)] = dump
|
||||||
|
|
||||||
|
for r in self.library_reference_guids:
|
||||||
|
refs_db.append(r)
|
||||||
|
|
||||||
from .sectionfile import SectionFile, Section, GuidSection, InstancesSection, AttributesSection, RelationshipsSection, StringTableSection, ResourcesSection, DefinitionsSection, TemplatesSection
|
from .sectionfile import SectionFile, Section, GuidSection, InstancesSection, AttributesSection, RelationshipsSection, StringTableSection, ResourcesSection, DefinitionsSection, TemplatesSection
|
||||||
f = SectionFile("MCX!", 2.0, 15)
|
f = SectionFile("MCX!", 2.0, 15)
|
||||||
f.open(self.filename)
|
f.open(self.filename)
|
||||||
@ -150,6 +155,7 @@ class MemoryLibraryManager (MochaLibraryManager):
|
|||||||
f.sections.append(ResourcesSection("Resources", rsrc_db))
|
f.sections.append(ResourcesSection("Resources", rsrc_db))
|
||||||
f.sections.append(DefinitionsSection(defs_db))
|
f.sections.append(DefinitionsSection(defs_db))
|
||||||
f.sections.append(TemplatesSection(templates_db))
|
f.sections.append(TemplatesSection(templates_db))
|
||||||
|
f.sections.append(GuidSection("LibraryRefs", refs_db))
|
||||||
|
|
||||||
f.save()
|
f.save()
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@ class McxDataFormat (DataFormat):
|
|||||||
flags = r.read_int32()
|
flags = r.read_int32()
|
||||||
section_count = r.read_int32()
|
section_count = r.read_int32()
|
||||||
guid = r.read_guid()
|
guid = r.read_guid()
|
||||||
|
object_model.set_guid(guid)
|
||||||
|
|
||||||
sections = [ ]
|
sections = [ ]
|
||||||
|
|
||||||
@ -68,17 +69,20 @@ class McxDataFormat (DataFormat):
|
|||||||
|
|
||||||
for (section_name, offset, length, length2, itemcount) in sections:
|
for (section_name, offset, length, length2, itemcount) in sections:
|
||||||
if section_name == 'GUIDTable':
|
if section_name == 'GUIDTable':
|
||||||
print("mcx: reading GUID table")
|
print("mcx: reading GUID table (offset %s, length %s, count %s)" % (offset, length, itemcount))
|
||||||
r.get_stream().seek(offset)
|
r.get_stream().seek(offset)
|
||||||
for i in range(0, itemcount):
|
for i in range(0, itemcount):
|
||||||
gids.append(r.read_guid())
|
gid = r.read_guid()
|
||||||
|
gids.append(gid)
|
||||||
|
print(gid)
|
||||||
|
print (str(len(gids)) + " GUIDs loaded")
|
||||||
elif section_name == 'StringTable':
|
elif section_name == 'StringTable':
|
||||||
print("mcx: reading string table")
|
print("mcx: reading string table (offset %s, length %s, count %s)" % (offset, length, itemcount))
|
||||||
r.get_stream().seek(offset)
|
r.get_stream().seek(offset)
|
||||||
for i in range(0, itemcount):
|
for i in range(0, itemcount):
|
||||||
strs.append(r.read_terminatedstring())
|
strs.append(r.read_terminatedstring())
|
||||||
elif section_name == 'Defs':
|
elif section_name == 'Defs':
|
||||||
print("mcx: reading definitions")
|
print("mcx: reading definitions (offset %s, length %s, count %s)" % (offset, length, itemcount))
|
||||||
r.get_stream().seek(offset)
|
r.get_stream().seek(offset)
|
||||||
for i in range(0, itemcount):
|
for i in range(0, itemcount):
|
||||||
key = r.read_terminatedstring()
|
key = r.read_terminatedstring()
|
||||||
@ -87,13 +91,19 @@ class McxDataFormat (DataFormat):
|
|||||||
|
|
||||||
for (section_name, offset, length, length2, itemcount) in sections:
|
for (section_name, offset, length, length2, itemcount) in sections:
|
||||||
if section_name == 'Instances':
|
if section_name == 'Instances':
|
||||||
print("mcx: reading instances")
|
print("mcx: reading instances at offset " + str(offset))
|
||||||
r.get_stream().seek(offset)
|
r.get_stream().seek(offset)
|
||||||
for i in range(0, itemcount):
|
for i in range(0, itemcount):
|
||||||
cgidi = r.read_int32()
|
cgidi = r.read_int32()
|
||||||
cgid = gids[cgidi]
|
cgid = gids[cgidi]
|
||||||
igidi = r.read_int32()
|
igidi = r.read_int32()
|
||||||
igid = gids[igidi]
|
|
||||||
|
igid = None
|
||||||
|
if igidi >= 0 and igidi < len(gids):
|
||||||
|
igid = gids[igidi]
|
||||||
|
else:
|
||||||
|
print("not found igid at index " + str(igidi))
|
||||||
|
|
||||||
ckey = r.read_int32()
|
ckey = r.read_int32()
|
||||||
ikey = r.read_int32()
|
ikey = r.read_int32()
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,12 @@ class McxObjectModel (ObjectModel):
|
|||||||
self.__entityDefinitionsValues = dict()
|
self.__entityDefinitionsValues = dict()
|
||||||
|
|
||||||
self.template_definitions = dict()
|
self.template_definitions = dict()
|
||||||
|
self.__guid = None
|
||||||
|
|
||||||
|
def get_guid(self):
|
||||||
|
return self.__guid
|
||||||
|
def set_guid(self, guid):
|
||||||
|
self.__guid = guid
|
||||||
|
|
||||||
def get_instances(self) -> list[McxInstance]:
|
def get_instances(self) -> list[McxInstance]:
|
||||||
return self._instances
|
return self._instances
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user