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