Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
DonavinDraws committed Dec 4, 2023
2 parents e812ec9 + 627002d commit 3e918eb
Show file tree
Hide file tree
Showing 21 changed files with 1,227 additions and 686 deletions.
1 change: 1 addition & 0 deletions Fushigi/Fushigi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="fasterflect" Version="3.0.0" />
<PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="ImGui.NET" Version="1.90.0.1" />
<PackageReference Include="NativeFileDialogSharp" Version="0.6.0-alpha" />
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/course/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public int GetAreaCount()
public void AddGlobalLink()
{
CourseLink link = new("Reference");
mGlobalLinks.GetLinks().Add(link);
mGlobalLinks.mLinks.Add(link);
}

public void RemoveGlobalLink(CourseLink link)
{
mGlobalLinks.GetLinks().Remove(link);
mGlobalLinks.mLinks.Remove(link);
}

public CourseLinkHolder GetGlobalLinks()
Expand Down
87 changes: 35 additions & 52 deletions Fushigi/course/CourseActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -18,23 +19,23 @@ public CourseActor(BymlHashTable actorNode)
{
mActorParameters = new Dictionary<string, object>();

mActorName = BymlUtil.GetNodeData<string>(actorNode["Gyaml"]);
mPackName = BymlUtil.GetNodeData<string>(actorNode["Gyaml"]);
mLayer = BymlUtil.GetNodeData<string>(actorNode["Layer"]);

mTranslation = BymlUtil.GetVector3FromArray(actorNode["Translate"] as BymlArrayNode);
mRotation = BymlUtil.GetVector3FromArray(actorNode["Rotate"] as BymlArrayNode);
mScale = BymlUtil.GetVector3FromArray(actorNode["Scale"] as BymlArrayNode);
mAreaHash = BymlUtil.GetNodeData<uint>(actorNode["AreaHash"]);
mActorHash = BymlUtil.GetNodeData<ulong>(actorNode["Hash"]);
mHash = BymlUtil.GetNodeData<ulong>(actorNode["Hash"]);
mName = BymlUtil.GetNodeData<string>(actorNode["Name"]);
mActorPack = ActorPackCache.Load(mActorName);
mActorPack = ActorPackCache.Load(mPackName);


if (actorNode.ContainsKey("Dynamic"))
{
if (ParamDB.HasActorComponents(mActorName))
if (ParamDB.HasActorComponents(mPackName))
{
List<string> paramList = ParamDB.GetActorComponents(mActorName);
List<string> paramList = ParamDB.GetActorComponents(mPackName);

foreach (string p in paramList)
{
Expand Down Expand Up @@ -112,19 +113,17 @@ public CourseActor(BymlHashTable actorNode)
}
}

public CourseActor(string actorName, uint areaHash, string actorLayer)
public CourseActor(string packName, uint areaHash, string actorLayer)
{
mActorName = actorName;
mPackName = packName;
mAreaHash = areaHash;
mLayer = actorLayer;
mName = "";
mTranslation = new System.Numerics.Vector3(0.0f);
mRotation = new System.Numerics.Vector3(0.0f);
mScale = new System.Numerics.Vector3(1.0f);
mActorHash = RandomUtil.GetRandom();
mActorParameters = new();
mSystemParameters = new();
mActorPack = ActorPackCache.Load(mActorName);
mHash = RandomUtil.GetRandom();
mActorPack = ActorPackCache.Load(mPackName);

InitializeDefaultDynamicParams();
}
Expand All @@ -133,9 +132,9 @@ public void InitializeDefaultDynamicParams()
{
mActorParameters.Clear();

if (ParamDB.HasActorComponents(mActorName))
if (ParamDB.HasActorComponents(mPackName))
{
List<string> paramList = ParamDB.GetActorComponents(mActorName);
List<string> paramList = ParamDB.GetActorComponents(mPackName);

foreach (string p in paramList)
{
Expand Down Expand Up @@ -173,17 +172,12 @@ public void InitializeDefaultDynamicParams()
}
}

public ulong GetHash()
{
return mActorHash;
}

public BymlHashTable BuildNode(CourseLinkHolder linkHolder)
{
BymlHashTable table = new();
table.AddNode(BymlNodeId.UInt, BymlUtil.CreateNode<uint>(mAreaHash), "AreaHash");
table.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>(mActorName), "Gyaml");
table.AddNode(BymlNodeId.UInt64, BymlUtil.CreateNode<ulong>(mActorHash), "Hash");
table.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>(mPackName), "Gyaml");
table.AddNode(BymlNodeId.UInt64, BymlUtil.CreateNode<ulong>(mHash), "Hash");
table.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>(mLayer), "Layer");
table.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>(mName), "Name");

Expand Down Expand Up @@ -217,11 +211,11 @@ public BymlHashTable BuildNode(CourseLinkHolder linkHolder)
table.AddNode(BymlNodeId.Hash, sysNode, "System");
}

if (linkHolder.GetSrcHashesFromDest(mActorHash).Values.Count > 0)
if (linkHolder.GetSrcHashesFromDest(mHash).Values.Count > 0)
{
BymlHashTable inLinksNode = new();

foreach (var (linkName, links) in linkHolder.GetSrcHashesFromDest(mActorHash))
foreach (var (linkName, links) in linkHolder.GetSrcHashesFromDest(mHash))
{
inLinksNode.AddNode(BymlNodeId.Int, BymlUtil.CreateNode<int>(links.Count), linkName);
}
Expand Down Expand Up @@ -253,76 +247,65 @@ public BymlHashTable BuildNode(CourseLinkHolder linkHolder)
return table;
}

public string mActorName;
public string mPackName;
public string mName;
public string mLayer;
public System.Numerics.Vector3 mStartingTrans;
public System.Numerics.Vector3 mTranslation;
public System.Numerics.Vector3 mRotation;
public System.Numerics.Vector3 mScale;
public uint mAreaHash;
public ulong mActorHash;
public Dictionary<string, object> mActorParameters;
public ulong mHash;
public Dictionary<string, object> mActorParameters = new();
public Dictionary<string, object> mSystemParameters = new();

public ActorPack mActorPack;
}

public class CourseActorHolder
{
public CourseActorHolder(BymlArrayNode actorArray)
{
foreach (BymlHashTable actor in actorArray.Array)
{
mCourseActors.Add(new CourseActor(actor));
}
}

public CourseActorHolder()
{

}

CourseActor GetActor(ulong hash)
public CourseActorHolder(BymlArrayNode actorArray)
{
foreach (var actor in mCourseActors)
foreach (BymlHashTable actor in actorArray.Array)
{
if (actor.GetHash() == hash)
{
return actor;
}
mActors.Add(new CourseActor(actor));
}

return null;
}

public bool HasHash(ulong hash)
public bool TryGetActor(ulong hash, [NotNullWhen(true)] out CourseActor? actor)
{
return mCourseActors.Any(x => x.GetHash() == hash);
actor = mActors.Find(x => x.mHash == hash);
return actor is not null;
}

public CourseActor this[ulong hash]
{
get => GetActor(hash);
}

public List<CourseActor> GetActors()
{
return mCourseActors;
get
{
bool exists = TryGetActor(hash, out CourseActor? actor);
Debug.Assert(exists);
return actor!;
}
}

public BymlArrayNode SerializeToArray(CourseLinkHolder linkHolder)
{
BymlArrayNode node = new((uint)mCourseActors.Count);
BymlArrayNode node = new((uint)mActors.Count);

foreach (CourseActor actor in mCourseActors)
foreach (CourseActor actor in mActors)
{
node.AddNodeToArray(actor.BuildNode(linkHolder));
}

return node;
}

List<CourseActor> mCourseActors = new List<CourseActor>();
public List<CourseActor> mActors = new List<CourseActor>();
}

public class CourseActorRender //This can be overridden per actor for individual behavior
Expand Down
26 changes: 13 additions & 13 deletions Fushigi/course/CourseArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public void Load()
if (root.ContainsKey("ActorToRailLinks"))
{
BymlArrayNode? actorLinksArray = root["ActorToRailLinks"] as BymlArrayNode;
mRailLinks = new CourseActorToRailLinks(actorLinksArray, mActorHolder, mRailHolder);
mRailLinksHolder = new CourseActorToRailLinksHolder(actorLinksArray, mActorHolder, mRailHolder);
}
else
{
mRailLinks = new();
mRailLinksHolder = new();
}

if (root.ContainsKey("Links"))
Expand All @@ -83,11 +83,11 @@ public void Load()
if (root.ContainsKey("SimultaneousGroups"))
{
BymlArrayNode? groupsArray = root["SimultaneousGroups"] as BymlArrayNode;
mGroups = new CourseGroupHolder(groupsArray);
mGroupsHolder = new CourseGroupHolder(groupsArray);
}
else
{
mGroups = new();
mGroupsHolder = new();
}

if (root.ContainsKey("BgUnits"))
Expand All @@ -113,9 +113,9 @@ public void Save(RSTB resource_table, string folder)
Directory.CreateDirectory(folder);

BymlHashTable root = new();
root.AddNode(BymlNodeId.UInt, BymlUtil.CreateNode<uint>("RootAreaHash", mRootHash), "RootAreaHash");
root.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>("StageParam", mStageParams), "StageParam");
root.AddNode(BymlNodeId.Array, mRailLinks.SerializeToArray(), "ActorToRailLinks");
root.AddNode(BymlNodeId.UInt, BymlUtil.CreateNode<uint>(mRootHash), "RootAreaHash");
root.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>(mStageParams), "StageParam");
root.AddNode(BymlNodeId.Array, mRailLinksHolder.SerializeToArray(), "ActorToRailLinks");
root.AddNode(BymlNodeId.Array, mActorHolder.SerializeToArray(mLinkHolder), "Actors");

if (mUnitHolder != null)
Expand All @@ -125,7 +125,7 @@ public void Save(RSTB resource_table, string folder)

root.AddNode(BymlNodeId.Array, mLinkHolder.SerializeToArray(), "Links");
root.AddNode(BymlNodeId.Array, mRailHolder.SerializeToArray(), "Rails");
root.AddNode(BymlNodeId.Array, mGroups.SerializeToArray(), "SimultaneousGroups");
root.AddNode(BymlNodeId.Array, mGroupsHolder.SerializeToArray(), "SimultaneousGroups");

var byml = new Byml.Byml(root);
var mem = new MemoryStream();
Expand All @@ -147,20 +147,20 @@ public string GetName()
return mAreaName;
}

public List<CourseActor> GetActors()
public IReadOnlyList<CourseActor> GetActors()
{
return mActorHolder.GetActors();
return mActorHolder.mActors;
}

string mAreaName;
public string mAreaName;
public uint mRootHash;
string mStageParams;
public AreaParam mAreaParams;
public CourseActorHolder mActorHolder;
public CourseRailHolder mRailHolder;
public CourseActorToRailLinks mRailLinks;
public CourseActorToRailLinksHolder mRailLinksHolder;
public CourseLinkHolder mLinkHolder;
public CourseGroupHolder mGroups;
public CourseGroupHolder mGroupsHolder;
public CourseUnitHolder mUnitHolder;

public class AreaParam
Expand Down
Loading

0 comments on commit 3e918eb

Please sign in to comment.