Skip to content

Commit

Permalink
properly remove actor links and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbo committed Nov 7, 2023
1 parent f099825 commit 889b662
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
23 changes: 23 additions & 0 deletions Fushigi/course/CourseLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public string GetLinkName()
return mLinkName;
}

public bool IsSourceValid(CourseActorHolder actorHolder)
{
return actorHolder.HasHash(mSource.GetHash());
}

public bool IsDestValid(CourseActorHolder actorHolder)
{
return actorHolder.HasHash(mDest.GetHash());
}

CourseActor? mSource;
CourseActor? mDest;
string mLinkName;
Expand Down Expand Up @@ -165,6 +175,19 @@ public List<CourseLink> GetLinks()
return mLinks;
}

public bool IsAnyLinkInvalid(CourseActorHolder holder)
{
foreach (CourseLink link in mLinks)
{
if (!link.IsSourceValid(holder) || !link.IsDestValid(holder))
{
return true;
}
}

return false;
}

public BymlArrayNode SerializeToArray()
{
BymlArrayNode node = new((uint)mLinks.Count);
Expand Down
15 changes: 12 additions & 3 deletions Fushigi/ui/CourseAreaEditContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public bool IsAnySelected<T>()
return mSelectedObjects.Any(x => x is T);
}

public List<CourseLink> GetLinks()
{
return area.mLinkHolder.GetLinks();
}

public void AddActor(CourseActor actor)
{
Expand All @@ -128,6 +132,9 @@ public void AddActor(CourseActor actor)
public void DeleteActor(CourseActor actor)
{
Deselect(actor);
DeleteActorFromGroups(actor.GetHash());
DeleteLinksWithSrcHash(actor.GetHash());
DeleteLinksWithDestHash(actor.GetHash());
mUndoHandler.AddToUndo(area.mActorHolder.GetActors()
.RevertableRemove(actor, $"Removing {actor.mActorName}"));
}
Expand All @@ -140,9 +147,6 @@ public void DeleteSelectedActors()

foreach (var actor in selectedActors)
{
DeleteActorFromGroups(actor.GetHash());
DeleteLinksWithSrcHash(actor.GetHash());
DeleteLinksWithDestHash(actor.GetHash());
DeleteActor(actor);
}

Expand All @@ -169,5 +173,10 @@ public bool IsActorDestForLink(CourseActor actor)
{
return area.mLinkHolder.GetLinkWithDestHash(actor.GetHash()) != null;
}

public bool IsAnyLinkInvalid()
{
return area.mLinkHolder.IsAnyLinkInvalid(area.mActorHolder);
}
}
}
4 changes: 2 additions & 2 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class CourseScene
bool mHasFilledLayers = false;
bool mAllLayersVisible = true;
bool mShowAddActor = false;
string mErroringArea = "";
bool mShowErrors = false;

CourseActor? mSelectedActor = null;
CourseUnit? mSelectedUnit = null;
Expand Down Expand Up @@ -81,6 +79,7 @@ public void DrawUI(GL gl)
{
LinkDeletionCheck();
}


ulong selectionVersionBefore = activeViewport.mEditContext.SelectionVersion;

Expand Down Expand Up @@ -169,6 +168,7 @@ public void Save()
foreach (var area in this.course.GetAreas())
{
Console.WriteLine($"Saving area {area.GetName()}...");

area.Save(resource_table);
}

Expand Down

0 comments on commit 889b662

Please sign in to comment.