Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/shibbo/Fushigi
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Apr 13, 2024
2 parents 52b3882 + 64b11c9 commit 768b990
Show file tree
Hide file tree
Showing 21 changed files with 1,550 additions and 850 deletions.
10 changes: 7 additions & 3 deletions Fushigi/actor_pack/ActorPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private void LoadComponents(SARC.SARC sarc, ActorParam param)
break;
case "ModelExpandRef":
this.ModelExpandParamRef ??= BymlSerialize.Deserialize<ModelExpandParam>(data);
this.ModelExpandParamRef.LoadParentIfExists(filePath =>
{
filePath = GetPathGyml(filePath);
return BymlSerialize.Deserialize<ModelExpandParam>(sarc.OpenFile(filePath));
});
break;
case "DrainPipeRef":
this.DrainPipeRef ??= BymlSerialize.Deserialize<DrainPipe>(data);
Expand All @@ -206,10 +211,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
3 changes: 3 additions & 0 deletions Fushigi/actor_pack/components/GamePhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace Fushigi.actor_pack.components
[Serializable]
public class GamePhysics
{
[BymlProperty("$parent")]
public string parent { get; set; }

[BymlProperty("ControllerSetPath", DefaultValue = "")]
public string mPath { get; set; }
}
Expand Down
15 changes: 15 additions & 0 deletions Fushigi/actor_pack/components/ModelExpandParam.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Fushigi.Byml.Serializer;
using Fushigi.SARC;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,6 +12,20 @@ namespace Fushigi.actor_pack.components
[Serializable]
public class ModelExpandParam
{
public void LoadParentIfExists(Func<string, ModelExpandParam> fileLoader)
{
if (ParentRef == null)
return;

Parent = fileLoader(ParentRef);
Parent.LoadParentIfExists(fileLoader);
}

[BymlProperty(Key = "$parent")]
public string? ParentRef { get; set; }

public ModelExpandParam? Parent { get; set; }

public List<ModelExpandParamSettings> Settings { get; set; }
}

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
9 changes: 8 additions & 1 deletion Fushigi/course/CourseActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace Fushigi.course
{
public enum WonderViewType{
Normal,
WonderOff,
WonderOnly
}
public class CourseActor
{
public CourseActor(BymlHashTable actorNode)
Expand Down Expand Up @@ -222,6 +227,8 @@ public BymlHashTable BuildNode(CourseLinkHolder linkHolder)
public string mPackName;
public string mName;
public string mLayer;
public WonderViewType mWonderView = WonderViewType.Normal;
public bool wonderVisible = true;
public System.Numerics.Vector3 mStartingTrans;
public System.Numerics.Vector3 mTranslation;
public System.Numerics.Vector3 mRotation;
Expand Down Expand Up @@ -260,7 +267,7 @@ public CourseActor this[ulong hash]
get
{
bool exists = TryGetActor(hash, out CourseActor? actor);
Debug.Assert(exists);
//Debug.Assert(exists);
return actor!;
}
}
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
2 changes: 1 addition & 1 deletion Fushigi/env/EnvPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Load(string name)
string file_path = FileUtil.FindContentPath(local_path);
if (!File.Exists(file_path))
{
Debug.Fail(null);
//Debug.Fail(null);
return;
}

Expand Down
4 changes: 4 additions & 0 deletions Fushigi/gl/Bfres/BfresRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public BfresModel(BfresModel bfresModel)
internal void Render(GL gl, BfresRender render, Matrix4x4 transform, Camera camera)
{
foreach (var mesh in Meshes)
{
var m = mesh.LodMeshes[0].BoundingBox;
m.Transform(transform);
BoundingBox.Include(mesh.LodMeshes[0].BoundingBox);
}

if (!IsVisible || !camera.InFrustum(BoundingBox))
return;
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/gl/Bfres/TileBfresRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static Model CreateModel(GL gl, BgUnitInfo bgUnitInfo)
));
}

public void Load(CourseUnitHolder unitHolder, Camera camera)
public void Load(CourseUnitHolder unitHolder)
{
SolidModel.TileManager.Clear();
SemisolidModel.TileManager.Clear();
Expand Down Expand Up @@ -153,9 +153,9 @@ public void Load(CourseUnitHolder unitHolder, Camera camera)

public void Render(GL gl, Camera camera)
{
NoCollisionModel.Render(gl, camera);
SolidModel.Render(gl, camera);
SemisolidModel.Render(gl, camera);
NoCollisionModel.Render(gl, camera);
BridgeModel.Render(gl, camera);
}

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
24 changes: 20 additions & 4 deletions Fushigi/ui/CourseAreaEditContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ public void AddLink(CourseLink link)
LogAdding<CourseLink>($": {link.mSource} -{link.mLinkName}-> {link.mDest}");

//Checks if the the source actor already has links
if(linkList.Any(x => x.mSource == link.mSource)){
if (linkList.Any(x => x.mSource == link.mSource)){

//Looks through the source actor's links
//Then looks through it's links of the same type (If it has any)
//Placing the new link in the right spot
var index = linkList.FindLastIndex(x => x.mSource == link.mSource &&
(!linkList.Any(y => x.mLinkName == link.mLinkName) ||
x.mLinkName == link.mLinkName));

CommitAction(
area.mLinkHolder.mLinks.RevertableInsert(link,
linkList.FindLastIndex(x => x.mSource == link.mSource
&& ((!linkList.Any(y => y.mLinkName == link.mLinkName)) || x.mLinkName == link.mLinkName))+1,
area.mLinkHolder.mLinks.RevertableInsert(link, index+1,
$"{IconUtil.ICON_PLUS_CIRCLE} Add {link.mLinkName} Link")
);
return;
Expand Down Expand Up @@ -215,6 +217,20 @@ public void DeleteWall(CourseUnit unit, Wall wall)
$"{IconUtil.ICON_TRASH} Delete Wall"));
}

public void AddBeltRail(CourseUnit unit, BGUnitRail rail)
{
LogAdding<BGUnitRail>();
CommitAction(unit.mBeltRails.RevertableAdd(rail,
$"{IconUtil.ICON_PLUS_CIRCLE} Add Belt"));
}

public void DeleteBeltRail(CourseUnit unit, BGUnitRail rail)
{
LogDeleting<BGUnitRail>();
CommitAction(unit.mBeltRails.RevertableRemove(rail,
$"{IconUtil.ICON_TRASH} Delete Belt"));
}

private void LogAdding<T>(ulong hash) =>
LogAdding<T>($"[{hash}]");

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 768b990

Please sign in to comment.