Skip to content

Commit

Permalink
Merge pull request #907 from Miepee/assetTagID
Browse files Browse the repository at this point in the history
Combine GetAssetTagID methods into one.
  • Loading branch information
Grossley authored May 12, 2022
2 parents 18be0ff + 42293df commit eee619e
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions UndertaleModLib/Models/UndertaleTags.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace UndertaleModLib.Models;

Expand All @@ -11,67 +12,70 @@ public class UndertaleTags : UndertaleObject
public UndertaleSimpleListString Tags { get; set; }
public Dictionary<int, UndertaleSimpleListString> AssetTags { get; set; }

//TODO: condense these all into one method
public static int GetAssetTagID(UndertaleData data, UndertaleGameObject res)
public static int GetAssetTagID(UndertaleData data, UndertaleNamedResource resource)
{
return ((int)ResourceType.Object << 24) | (data.GameObjects.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleSprite res)
{
return ((int)ResourceType.Sprite << 24) | (data.Sprites.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleSound res)
{
return ((int)ResourceType.Sound << 24) | (data.Sounds.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleRoom res)
{
return ((int)ResourceType.Room << 24) | (data.Rooms.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertalePath res)
{
return ((int)ResourceType.Path << 24) | (data.Paths.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleScript res)
{
// TODO? the indexof might be in terms of code entries or something?
return ((int)ResourceType.Script << 24) | ((data.Scripts.IndexOf(res) + 100000) & 0xFFFFFF);
}
ResourceType type;
IList<UndertaleNamedResource> list;
int offset = 0;

public static int GetAssetTagID(UndertaleData data, UndertaleFont res)
{
return ((int)ResourceType.Font << 24) | (data.Fonts.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleTimeline res)
{
return ((int)ResourceType.Timeline << 24) | (data.Timelines.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleBackground res)
{
return ((int)ResourceType.Background << 24) | (data.Backgrounds.IndexOf(res) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleShader res)
{
return ((int)ResourceType.Shader << 24) | (data.Shaders.IndexOf(res) & 0xFFFFFF);
}
switch (resource)
{
case UndertaleGameObject:
type = ResourceType.Object;
list = (IList<UndertaleNamedResource>) data.GameObjects;
break;
case UndertaleSprite:
type = ResourceType.Sprite;
list = (IList<UndertaleNamedResource>) data.Sprites;
break;
case UndertaleSound:
type = ResourceType.Sound;
list = (IList<UndertaleNamedResource>) data.Sounds;
break;
case UndertaleRoom:
type = ResourceType.Room;
list = (IList<UndertaleNamedResource>) data.Rooms;
break;
case UndertalePath:
type = ResourceType.Path;
list = (IList<UndertaleNamedResource>) data.Paths;
break;
case UndertaleScript:
type = ResourceType.Script;
list = (IList<UndertaleNamedResource>) data.Scripts;
offset = 100000;
break;
case UndertaleFont:
type = ResourceType.Font;
list = (IList<UndertaleNamedResource>) data.Fonts;
break;
case UndertaleTimeline:
type = ResourceType.Timeline;
list = (IList<UndertaleNamedResource>) data.Timelines;
break;
case UndertaleBackground:
type = ResourceType.Background;
list = (IList<UndertaleNamedResource>) data.Backgrounds;
break;
case UndertaleShader:
type = ResourceType.Shader;
list = (IList<UndertaleNamedResource>) data.Shaders;
break;
case UndertaleSequence:
type = ResourceType.Sequence;
list = (IList<UndertaleNamedResource>) data.Sequences;
break;
case UndertaleAnimationCurve:
type = ResourceType.AnimCurve;
list = (IList<UndertaleNamedResource>) data.AnimationCurves;
break;

default: throw new ArgumentException("Invalid resource type!");
}

public static int GetAssetTagID(UndertaleData data, UndertaleSequence res)
{
return ((int)ResourceType.Sequence << 24) | (data.Sequences.IndexOf(res) & 0xFFFFFF);
return ((int)type << 24) | ((list.IndexOf(resource) + offset) & 0xFFFFFF);
}

public static int GetAssetTagID(UndertaleData data, UndertaleAnimationCurve res)
{
return ((int)ResourceType.AnimCurve << 24) | (data.AnimationCurves.IndexOf(res) & 0xFFFFFF);
}

/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
Expand Down

0 comments on commit eee619e

Please sign in to comment.