-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix assets that modify other sprites. More progress towards SpriteEdi…
…tor.
- Loading branch information
1 parent
36ccc17
commit 5daffa8
Showing
13 changed files
with
231 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
namespace Murder.Editor.Assets; | ||
|
||
public class SpriteEventData | ||
{ | ||
public readonly Dictionary<string, Dictionary<int, string>> Events = new(); | ||
|
||
public readonly Dictionary<string, HashSet<int>> DeletedEvents = new(); | ||
|
||
/// <summary> | ||
/// Apply custom messages to an existing dictionary of events. | ||
/// </summary> | ||
public void FilterEventsForAnimation(string animation, ref Dictionary<int, string> events) | ||
{ | ||
if (Events.TryGetValue(animation, out var customEvents)) | ||
{ | ||
foreach ((int frame, string message) in customEvents) | ||
{ | ||
events[frame] = message; | ||
} | ||
} | ||
|
||
if (DeletedEvents.TryGetValue(animation, out var deletedEvents)) | ||
{ | ||
foreach (int frame in deletedEvents) | ||
{ | ||
events.Remove(frame); | ||
} | ||
} | ||
} | ||
|
||
public Dictionary<int, string> GetEventsForAnimation(string animation) | ||
{ | ||
if (!Events.TryGetValue(animation, out var dictionary)) | ||
{ | ||
dictionary = new(); | ||
Events[animation] = dictionary; | ||
} | ||
|
||
return dictionary; | ||
} | ||
|
||
public void AddEvent(string animation, int frame, string message) | ||
{ | ||
Dictionary<int, string> dict = GetEventsForAnimation(animation); | ||
dict[frame] = message; | ||
|
||
RemoveFromDeletedEvents(animation, frame); | ||
} | ||
|
||
public void RemoveEvent(string animation, int frame) | ||
{ | ||
if (!Events.TryGetValue(animation, out var dictionary)) | ||
{ | ||
AddToDeletedEvent(animation, frame); | ||
return; | ||
} | ||
|
||
bool hadValueDefined = dictionary.Remove(frame); | ||
if (!hadValueDefined) | ||
{ | ||
// Value was previously not tracked here. It is likely added by aseprite. | ||
// So let's override that! | ||
AddToDeletedEvent(animation, frame); | ||
} | ||
} | ||
|
||
private void AddToDeletedEvent(string animation, int frame) | ||
{ | ||
if (!DeletedEvents.TryGetValue(animation, out var dictionary)) | ||
{ | ||
dictionary = new(); | ||
DeletedEvents[animation] = dictionary; | ||
} | ||
|
||
dictionary.Add(frame); | ||
} | ||
|
||
private bool RemoveFromDeletedEvents(string animation, int frame) | ||
{ | ||
if (!DeletedEvents.TryGetValue(animation, out var dictionary)) | ||
{ | ||
return false; | ||
} | ||
|
||
_ = dictionary.Remove(frame); | ||
if (dictionary.Count == 0) | ||
{ | ||
DeletedEvents.Remove(animation); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public SpriteEventData() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.