Refacor object hierarchy creation to be more maintainable and extensible
This commit is contained in:
parent
6f87bc6904
commit
9e115b6906
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using KeepersCompound.LGS.Database.Chunks;
|
using KeepersCompound.LGS.Database.Chunks;
|
||||||
|
|
||||||
|
@ -35,54 +36,25 @@ public class ObjectHierarchy
|
||||||
{
|
{
|
||||||
_objects = new Dictionary<int, DarkObject>();
|
_objects = new Dictionary<int, DarkObject>();
|
||||||
|
|
||||||
if (db.Chunks.TryGetValue("P$ModelName", out var modelNamesRaw) &&
|
T GetMergedChunk<T>(string name) where T : IMergable
|
||||||
db.Chunks.TryGetValue("P$Scale", out var scalesRaw) &&
|
|
||||||
db.Chunks.TryGetValue("P$RenderTyp", out var renderTypesRaw) &&
|
|
||||||
db.Chunks.TryGetValue("P$OTxtRepr0", out var txtRepl0Raw) &&
|
|
||||||
db.Chunks.TryGetValue("P$OTxtRepr1", out var txtRepl1Raw) &&
|
|
||||||
db.Chunks.TryGetValue("P$OTxtRepr2", out var txtRepl2Raw) &&
|
|
||||||
db.Chunks.TryGetValue("P$OTxtRepr3", out var txtRepl3Raw) &&
|
|
||||||
db.Chunks.TryGetValue("P$RenderAlp", out var renderAlphaRaw) &&
|
|
||||||
db.Chunks.TryGetValue("L$MetaProp", out var metaPropLinksRaw) &&
|
|
||||||
db.Chunks.TryGetValue("LD$MetaProp", out var metaPropLinkDataRaw))
|
|
||||||
{
|
{
|
||||||
var modelNames = (PropertyChunk<PropModelName>)modelNamesRaw;
|
if (db.Chunks.TryGetValue(name, out var rawChunk))
|
||||||
var scales = (PropertyChunk<PropScale>)scalesRaw;
|
{
|
||||||
var renderTypes = (PropertyChunk<PropRenderType>)renderTypesRaw;
|
var chunk = (T)rawChunk;
|
||||||
var txtRepl0s = (PropertyChunk<PropString>)txtRepl0Raw;
|
if (gam != null && gam.Chunks.TryGetValue(name, out var rawGamChunk))
|
||||||
var txtRepl1s = (PropertyChunk<PropString>)txtRepl1Raw;
|
{
|
||||||
var txtRepl2s = (PropertyChunk<PropString>)txtRepl2Raw;
|
var gamChunk = (T)rawGamChunk;
|
||||||
var txtRepl3s = (PropertyChunk<PropString>)txtRepl3Raw;
|
chunk.Merge(gamChunk);
|
||||||
var renderAlpha = (PropertyChunk<PropFloat>)renderAlphaRaw;
|
}
|
||||||
var metaPropLinks = (LinkChunk)metaPropLinksRaw;
|
return chunk;
|
||||||
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
|
}
|
||||||
|
|
||||||
// Merge gam chunks
|
throw new ArgumentException($"No chunk with name ({name}) found", nameof(name));
|
||||||
if (gam != null &&
|
|
||||||
gam.Chunks.TryGetValue("P$ModelName", out var gamModelNames) &&
|
|
||||||
gam.Chunks.TryGetValue("P$Scale", out var gamScales) &&
|
|
||||||
gam.Chunks.TryGetValue("P$RenderTyp", out var gamRenderTypes) &&
|
|
||||||
gam.Chunks.TryGetValue("P$OTxtRepr0", out var gamTxtRepl0s) &&
|
|
||||||
gam.Chunks.TryGetValue("P$OTxtRepr1", out var gamTxtRepl1s) &&
|
|
||||||
gam.Chunks.TryGetValue("P$OTxtRepr2", out var gamTxtRepl2s) &&
|
|
||||||
gam.Chunks.TryGetValue("P$OTxtRepr3", out var gamTxtRepl3s) &&
|
|
||||||
gam.Chunks.TryGetValue("P$RenderAlp", out var gamRenderAlpha) &&
|
|
||||||
gam.Chunks.TryGetValue("L$MetaProp", out var gamLinks) &&
|
|
||||||
gam.Chunks.TryGetValue("LD$MetaProp", out var gamLinkData))
|
|
||||||
{
|
|
||||||
modelNames.properties.AddRange(((PropertyChunk<PropModelName>)gamModelNames).properties);
|
|
||||||
scales.properties.AddRange(((PropertyChunk<PropScale>)gamScales).properties);
|
|
||||||
renderTypes.properties.AddRange(((PropertyChunk<PropRenderType>)gamRenderTypes).properties);
|
|
||||||
txtRepl0s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl0s).properties);
|
|
||||||
txtRepl1s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl1s).properties);
|
|
||||||
txtRepl2s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl2s).properties);
|
|
||||||
txtRepl3s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl3s).properties);
|
|
||||||
renderAlpha.properties.AddRange(((PropertyChunk<PropFloat>)gamRenderAlpha).properties);
|
|
||||||
metaPropLinks.links.AddRange(((LinkChunk)gamLinks).links);
|
|
||||||
metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamLinkData).linkData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add parentages
|
// Add parentages
|
||||||
|
var metaPropLinks = GetMergedChunk<LinkChunk>("L$MetaProp");
|
||||||
|
var metaPropLinkData = GetMergedChunk<LinkDataMetaProp>("LD$MetaProp");
|
||||||
var length = metaPropLinks.links.Count;
|
var length = metaPropLinks.links.Count;
|
||||||
for (var i = 0; i < length; i++)
|
for (var i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
@ -105,50 +77,28 @@ public class ObjectHierarchy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TryAddProp(string propName, Property prop)
|
void AddProp<T>(string name) where T : Property, new()
|
||||||
|
{
|
||||||
|
var chunk = GetMergedChunk<PropertyChunk<T>>(name);
|
||||||
|
foreach (var prop in chunk.properties)
|
||||||
{
|
{
|
||||||
var id = prop.objectId;
|
var id = prop.objectId;
|
||||||
if (!_objects.ContainsKey(id))
|
if (!_objects.ContainsKey(id))
|
||||||
{
|
{
|
||||||
_objects.Add(id, new DarkObject(id));
|
_objects.Add(id, new DarkObject(id));
|
||||||
}
|
}
|
||||||
_objects[id].properties.TryAdd(propName, prop);
|
_objects[id].properties.TryAdd(name, prop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Find a way to do this better
|
AddProp<PropModelName>("P$ModelName");
|
||||||
foreach (var prop in modelNames.properties)
|
AddProp<PropScale>("P$Scale");
|
||||||
{
|
AddProp<PropRenderType>("P$RenderTyp");
|
||||||
TryAddProp("P$ModelName", prop);
|
AddProp<PropString>("P$OTxtRepr0");
|
||||||
}
|
AddProp<PropString>("P$OTxtRepr1");
|
||||||
foreach (var prop in scales.properties)
|
AddProp<PropString>("P$OTxtRepr2");
|
||||||
{
|
AddProp<PropString>("P$OTxtRepr3");
|
||||||
TryAddProp("P$Scale", prop);
|
AddProp<PropFloat>("P$RenderAlp");
|
||||||
}
|
|
||||||
foreach (var prop in renderTypes.properties)
|
|
||||||
{
|
|
||||||
TryAddProp("P$RenderTyp", prop);
|
|
||||||
}
|
|
||||||
foreach (var prop in txtRepl0s.properties)
|
|
||||||
{
|
|
||||||
TryAddProp("P$OTxtRepr0", prop);
|
|
||||||
}
|
|
||||||
foreach (var prop in txtRepl1s.properties)
|
|
||||||
{
|
|
||||||
TryAddProp("P$OTxtRepr1", prop);
|
|
||||||
}
|
|
||||||
foreach (var prop in txtRepl2s.properties)
|
|
||||||
{
|
|
||||||
TryAddProp("P$OTxtRepr2", prop);
|
|
||||||
}
|
|
||||||
foreach (var prop in txtRepl3s.properties)
|
|
||||||
{
|
|
||||||
TryAddProp("P$OTxtRepr3", prop);
|
|
||||||
}
|
|
||||||
foreach (var prop in renderAlpha.properties)
|
|
||||||
{
|
|
||||||
TryAddProp("P$RenderAlp", prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetProperty<T>(int objectId, string propName) where T : Property
|
public T GetProperty<T>(int objectId, string propName) where T : Property
|
||||||
|
|
Loading…
Reference in New Issue