Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix igms2fd to work with the new changes #1389

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions UndertaleModTool/Scripts/Community Scripts/ImportGMS2FontData.csx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EnsureDataLoaded();

ScriptMessage(@"ImportGMS2FontData by Dobby233Liu
This script can import GM font asset data to your mod
(Designed for the data IDE v2022.6.0.23 generates)
(Designed for the data IDE v2023.8.2.108 generates)
Select the .yy file of the GM font asset you want to import"
);

Expand Down Expand Up @@ -52,13 +52,18 @@ Try renaming the correct texture file to
and putting it in the same directory as the .yy file."
);

bool tginExists = Data.TextureGroupInfo is not null;
// Default to putting the font into the default texgroup
UndertaleTextureGroupInfo fontTexGroup;
if (tginExists)
fontTexGroup = Data.TextureGroupInfo.ByName("Default");
/*
If true, the script will attempt to add the new font (if any) and the new font glyph texture that it created to a texture group
This was an attempt to get fonts that this script creates appear in a specific 2022.3 game, but was proved unnecessary, as the problem was caused by something else
If true, the script will attempt to add the new font (if any) and the new font glyph texture
that it created to a texture group
This was an attempt to get fonts that this script creates appear in a specific 2022.3 game,
but it was proved unnecessary as the problem was caused by something else
*/
bool attemptToFixFontNotAppearing = false; // Data.GM2022_3;
// Default to putting the font into the default texgroup
UndertaleTextureGroupInfo fontTexGroup = Data.TextureGroupInfo.ByName("Default");
bool attemptToFixFontNotAppearing = tginExists && false; // Data.GM2022_3;
Dobby233Liu marked this conversation as resolved.
Show resolved Hide resolved

UndertaleFont font = Data.Fonts.ByName(fontName);
if (font == null)
Expand Down Expand Up @@ -138,6 +143,10 @@ if (fontData.ContainsKey("ascender"))
font.Ascender = (uint)fontData["ascender"];
if (fontData.ContainsKey("ascenderOffset"))
font.AscenderOffset = (int)fontData["ascenderOffset"];
if (fontData.ContainsKey("usesSDF") && (bool)fontData["usesSDF"] && fontData.ContainsKey("sdfSpread"))
font.SDFSpread = (uint)fontData["sdfSpread"];
if (fontData.ContainsKey("lineHeight"))
font.LineHeight = (uint)fontData["lineHeight"];

// FIXME: Too complicated?
List<int> charRangesUppersAndLowers = new();
Expand All @@ -152,7 +161,8 @@ font.RangeStart = (ushort)charRangesUppersAndLowers.DefaultIfEmpty(0).FirstOrDef
font.RangeEnd = (uint)charRangesUppersAndLowers.DefaultIfEmpty(0xFFFF).LastOrDefault();

List<UndertaleFont.Glyph> glyphs = new();
// From what I've seen, the keys of the objects in glyphs is just the character property of the object itself but in string form
// From what I've seen, the keys of the objects in glyphs is just
// the character property of the object itself but in string form
foreach (KeyValuePair<string, JToken> glyphKVEntry in (JObject)fontData["glyphs"])
{
var glyphData = (JObject)glyphKVEntry.Value;
Expand All @@ -173,18 +183,18 @@ font.Glyphs.Clear();
foreach (var glyph in glyphs)
font.Glyphs.Add(glyph);

// TODO: Does this always exist?
glyphs = font.Glyphs.ToList();
// TODO: applyKerning??
foreach (JObject kerningPair in fontData["kerningPairs"]?.Values<JObject>())
{
// Why do I need to do this. Thanks YoYo
var first = (ushort)kerningPair["first"];
var glyph = glyphs.Find(x => x.Character == first);
glyph.Kerning.Add(new UndertaleFont.Glyph.GlyphKerning()
{
Other = (short)kerningPair["second"],
Amount = (short)kerningPair["amount"],
Character = (short)kerningPair["second"],
ShiftModifier = (short)kerningPair["amount"],
});
}

ScriptMessage("Import complete.");
ScriptMessage("Import complete.");