Skip to content

Commit

Permalink
Merge pull request #111 from DonavinDraws/main
Browse files Browse the repository at this point in the history
Old Code Revamp, Curved Rails, & Actor To Rail Fix
  • Loading branch information
jupahe64 authored Mar 2, 2024
2 parents d7e3d1e + 8284aaf commit 401c21f
Show file tree
Hide file tree
Showing 10 changed files with 1,091 additions and 693 deletions.
5 changes: 2 additions & 3 deletions Fushigi/actor_pack/ActorPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ private void LoadComponents(SARC.SARC sarc, ActorParam param)
}
}

private ShapeParamList GetActorShape(SARC.SARC sarc)
private ShapeParamList? GetActorShape(SARC.SARC sarc)
{

var file = GetPathGyml(GamePhysicsRef.mPath);
var file = GetPathGyml(this.GamePhysicsRef.mPath);
var dat = sarc.OpenFile(file);
this.ControllerPath = BymlSerialize.Deserialize<ControllerSetParam>(dat);

Expand Down
2 changes: 1 addition & 1 deletion Fushigi/course/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void Save()

foreach (CourseArea area in mAreas)
{
refArr.AddNodeToArray(BymlUtil.CreateNode<string>("", $"Work/Stage/StageParam/{area.GetName()}.game__stage__StageParam.gyml"));
refArr.AddNodeToArray(BymlUtil.CreateNode($"Work/Stage/StageParam/{area.GetName()}.game__stage__StageParam.gyml"));
}

stageParamRoot.AddNode(BymlNodeId.Array, refArr, "RefStages");
Expand Down
47 changes: 35 additions & 12 deletions Fushigi/course/CourseRail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ public CourseRail(BymlHashTable node)

string pointParam = Path.GetFileNameWithoutExtension(BymlUtil.GetNodeData<string>(node["Gyaml"])).Split(".game")[0];
var railParams = ParamDB.GetRailComponent(pointParam);
var railParent = ParamDB.GetRailComponentParent(railParams);
var comp = ParamDB.GetRailComponentParams(railParams);
if (railParent != "null")
{
var parentComp = ParamDB.GetRailComponentParams(railParent);
foreach (var component in parentComp)
{
comp.TryAdd(component.Key, component.Value);
}
}

if (!node.ContainsKey("Dynamic"))
{
Expand Down Expand Up @@ -132,14 +141,15 @@ public CourseRailPoint()
{
this.mHash = RandomUtil.GetRandom();
this.mTranslate = new System.Numerics.Vector3();
this.mControl = new(this, mTranslate);
}


public CourseRailPoint(CourseRailPoint point)
{
this.mHash = RandomUtil.GetRandom();
this.mTranslate = point.mTranslate;
this.mControl = point.mControl;
this.mControl = new(this, point.mControl.mTranslate);
foreach (var param in point.mParameters)
this.mParameters.Add(param.Key, param.Value);
}
Expand All @@ -148,6 +158,7 @@ public CourseRailPoint(BymlHashTable node, string pointParam)
{
mHash = BymlUtil.GetNodeData<ulong>(node["Hash"]);
mTranslate = BymlUtil.GetVector3FromArray(node["Translate"] as BymlArrayNode);
mControl = new(this, mTranslate);

IDictionary<string, ParamDB.ComponentParam> comp;
if (ParamDB.TryGetRailPointComponent(pointParam, out var componentName))
Expand All @@ -169,7 +180,8 @@ public CourseRailPoint(BymlHashTable node, string pointParam)

if (node.ContainsKey("Control1"))
{
mControl = BymlUtil.GetVector3FromArray(node["Control1"] as BymlArrayNode);
mControl.mTranslate = BymlUtil.GetVector3FromArray(node["Control1"] as BymlArrayNode);
mIsCurve = true;
}

var dynamicNode = node["Dynamic"] as BymlHashTable;
Expand Down Expand Up @@ -204,20 +216,20 @@ public BymlHashTable BuildNode()

tbl.AddNode(BymlNodeId.Hash, dynamicNode, "Dynamic");

if (mControl != null)
if (mIsCurve)
{
BymlArrayNode controlNode = new(3);
controlNode.AddNodeToArray(BymlUtil.CreateNode<float>("X", mControl.Value.X));
controlNode.AddNodeToArray(BymlUtil.CreateNode<float>("Y", mControl.Value.Y));
controlNode.AddNodeToArray(BymlUtil.CreateNode<float>("Z", mControl.Value.Z));
controlNode.AddNodeToArray(BymlUtil.CreateNode(mControl.mTranslate.X));
controlNode.AddNodeToArray(BymlUtil.CreateNode(mControl.mTranslate.Y));
controlNode.AddNodeToArray(BymlUtil.CreateNode(mControl.mTranslate.Z));

tbl.AddNode(BymlNodeId.Array, controlNode, "Control1");
}

BymlArrayNode translateNode = new(3);
translateNode.AddNodeToArray(BymlUtil.CreateNode<float>("X", mTranslate.X));
translateNode.AddNodeToArray(BymlUtil.CreateNode<float>("Y", mTranslate.Y));
translateNode.AddNodeToArray(BymlUtil.CreateNode<float>("Z", mTranslate.Z));
translateNode.AddNodeToArray(BymlUtil.CreateNode(mTranslate.X));
translateNode.AddNodeToArray(BymlUtil.CreateNode(mTranslate.Y));
translateNode.AddNodeToArray(BymlUtil.CreateNode(mTranslate.Z));

tbl.AddNode(BymlNodeId.Array, translateNode, "Translate");

Expand All @@ -227,10 +239,20 @@ public BymlHashTable BuildNode()
public ulong mHash;
public Dictionary<string, object> mParameters = new();
public System.Numerics.Vector3 mTranslate;
public System.Numerics.Vector3? mControl = null;
public CourseRailPointControl mControl;
public bool mIsCurve;
}
public class CourseRailPointControl
{
public CourseRailPointControl(CourseRail.CourseRailPoint point, System.Numerics.Vector3 pos)
{
this.point = point;
this.mTranslate = pos;
}
public CourseRail.CourseRailPoint point;
public System.Numerics.Vector3 mTranslate;
}
}

public class CourseRailHolder
{
public CourseRailHolder()
Expand Down Expand Up @@ -291,6 +313,7 @@ public CourseActorToRailLink(BymlHashTable table)
{
mSourceActor = BymlUtil.GetNodeData<ulong>(table["Src"]);
mDestRail = BymlUtil.GetNodeData<ulong>(table["Dst"]);
mDestPoint = BymlUtil.GetNodeData<ulong>(table["Point"]);
mLinkName = BymlUtil.GetNodeData<string>(table["Name"]);
}

Expand All @@ -299,7 +322,7 @@ public BymlHashTable BuildNode()
BymlHashTable tbl = new();
tbl.AddNode(BymlNodeId.UInt64, BymlUtil.CreateNode<ulong>(mDestRail), "Dst");
tbl.AddNode(BymlNodeId.String, BymlUtil.CreateNode<string>(mLinkName), "Name");
tbl.AddNode(BymlNodeId.UInt64, BymlUtil.CreateNode<ulong>(mSourceActor), "Point");
tbl.AddNode(BymlNodeId.UInt64, BymlUtil.CreateNode<ulong>(mDestPoint), "Point");
tbl.AddNode(BymlNodeId.UInt64, BymlUtil.CreateNode<ulong>(mSourceActor), "Src");
return tbl;
}
Expand Down
3 changes: 1 addition & 2 deletions Fushigi/course/distance_view/DistantViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace Fushigi.course.distance_view
public class DistantViewManager
{
private Dictionary<string, Matrix4x4> LayerMatrices = new Dictionary<string, Matrix4x4>();

private DVLayerParamTable ParamTable = new DVLayerParamTable();
public DVLayerParamTable ParamTable = new DVLayerParamTable();

private CourseActor DVLocator;

Expand Down
10 changes: 7 additions & 3 deletions Fushigi/param/ParamDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static void Init()
public static List<string> GetActorComponents(string actor) => sActors[actor].Components;

public static Dictionary<string, ComponentParam> GetComponentParams(string componentName) => sComponents[componentName].Parameters;
public static string GetComponentParent(string componentName) => sComponents[componentName].Parent;
public static string GetRailComponent(string railName) => sRailParamList[railName].Components[0];
public static bool TryGetRailPointComponent(string railName, [NotNullWhen(true)] out string? componentName)
{
Expand All @@ -125,6 +126,7 @@ public static bool TryGetRailPointComponent(string railName, [NotNullWhen(true)]
return componentName is not null;
}

public static string GetRailComponentParent(string componentName) => sRails[componentName].Parent;
public static Dictionary<string, ComponentParam> GetRailComponentParams(string componentName) => sRails[componentName].Parameters;

public static string[] GetActors() => sActors.Keys.ToArray();
Expand Down Expand Up @@ -207,7 +209,7 @@ public static void Load(IProgress<(string operationName, float? progress)> progr
{
var byml = new Byml.Byml(new MemoryStream(File.ReadAllBytes(railComp)));
string name = Path.GetFileNameWithoutExtension(railComp).Split(".engine")[0];
Component component = ReadByml(byml);
Component component = ReadByml(byml, true);
sRails.Add(name, component);
}

Expand Down Expand Up @@ -268,7 +270,7 @@ public static void Reload(IProgress<(string operationName, float? progress)> pro
Load(progress);
}

static Component ReadByml(Byml.Byml byml)
static Component ReadByml(Byml.Byml byml, bool isRailParam = false)
{
var root = (BymlHashTable)byml.Root;

Expand Down Expand Up @@ -340,10 +342,12 @@ static Component ReadByml(Byml.Byml byml)

/* if the IsInstanceParam value is False, it means that the parameter is not used in a course context
* so, if it is False, we ignore it and move on to the next parameter as we will only read what matters
* No, this causes some rail types to save without default parameters. -Donavin
*/
bool isInstParam = ((BymlNode<bool>)(ht["IsInstanceParam"])).Data;

if (!isInstParam)
if (!isInstParam && !isRailParam)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/ui/EditContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Commit(string name)

public ICommittable BeginBatchAction()
{
mCurrentActionBatch = [];
mCurrentActionBatch ??= [];
var batchAction = new BatchAction(this);
mNestedBatchActions.Push(batchAction);
return batchAction;
Expand Down
Loading

0 comments on commit 401c21f

Please sign in to comment.