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

Compatibility upgrade of scripts involving textures #1890

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions UndertaleModTool/Scripts/Builtin Scripts/BorderEnabler.csx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ foreach (var path in Directory.EnumerateFiles(bordersPath))
{
UndertaleEmbeddedTexture newtex = new UndertaleEmbeddedTexture();
newtex.Name = new UndertaleString($"Texture {++lastTextPage}");
newtex.TextureData.Image = GMImage.FromPng(File.ReadAllBytes(path)); // TODO: possibly other formats than PNG in the future, but no Undertale versions currently have them
newtex.TextureData.Image = GMImage.FromPng(File.ReadAllBytes(path)); // Possibly other formats than PNG in the future, but no Undertale versions currently have them
Data.EmbeddedTextures.Add(newtex);
textures.Add(Path.GetFileName(path), newtex);
}
Expand All @@ -84,7 +84,7 @@ foreach (var path in Directory.EnumerateFiles(bordersPath))
Action<string, UndertaleEmbeddedTexture, ushort, ushort, ushort, ushort> AssignBorderBackground = (name, tex, x, y, width, height) =>
{
var bg = Data.Backgrounds.ByName(name);
if (bg == null)
if (bg is null)
{
// The anime border does not exist on PC yet ;)
return;
Expand Down
9 changes: 6 additions & 3 deletions UndertaleModTool/Scripts/Community Scripts/FontEditor.csx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ using ImageMagick;

EnsureDataLoaded();

UndertaleFont font = FontPickerResult(); //GUI dropdown selection list of fonts
if (font == null) return; //the 'Cancel' or 'X' button is hit
UndertaleFont font = FontPickerResult(); // GUI dropdown selection list of fonts
if (font is null)
{
return; // the 'Cancel' or 'X' button is hit
}
using (TextureWorker textureWorker = new())
{
new FontEditorGUI(font, textureWorker).ShowDialog(); //font editor GUI
_ = new FontEditorGUI(font, textureWorker).ShowDialog(); // font editor GUI
Miepee marked this conversation as resolved.
Show resolved Hide resolved
}

class FontEditorGUI : Form
Expand Down
28 changes: 15 additions & 13 deletions UndertaleModTool/Scripts/Community Scripts/ImportGMS2FontData.csx
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,21 @@ Data.EmbeddedTextures.Add(texture);
if (attemptToFixFontNotAppearing)
fontTexGroup.TexturePages.Add(new UndertaleResourceById<UndertaleEmbeddedTexture, UndertaleChunkTXTR>() { Resource = texture });

UndertaleTexturePageItem texturePageItem = new UndertaleTexturePageItem();
texturePageItem.Name = new UndertaleString($"PageItem {Data.TexturePageItems.Count}");
texturePageItem.TexturePage = texture;
texturePageItem.SourceX = 0;
texturePageItem.SourceY = 0;
texturePageItem.SourceWidth = width;
texturePageItem.SourceHeight = height;
texturePageItem.TargetX = 0;
texturePageItem.TargetY = 0;
texturePageItem.TargetWidth = width;
texturePageItem.TargetHeight = height;
texturePageItem.BoundingWidth = width;
texturePageItem.BoundingHeight = height;
UndertaleTexturePageItem texturePageItem = new UndertaleTexturePageItem()
{
Name = new UndertaleString($"PageItem {Data.TexturePageItems.Count}"),
TexturePage = texture,
SourceX = 0,
SourceY = 0,
SourceWidth = width,
SourceHeight = height,
TargetX = 0,
TargetY = 0,
TargetWidth = width,
TargetHeight = height,
BoundingWidth = width,
BoundingHeight = height
};
Data.TexturePageItems.Add(texturePageItem);

font.DisplayName = Data.Strings.MakeString((string)fontData["fontName"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,21 @@ UndertaleTexturePageItem AddNewTexturePageItem(ushort sourceX, ushort sourceY, u
ushort boundingHeight = sourceHeight;
var texturePage = textures["controls.png"];

UndertaleTexturePageItem tpItem = new UndertaleTexturePageItem { SourceX = sourceX, SourceY = sourceY, SourceWidth = sourceWidth, SourceHeight = sourceHeight, TargetX = targetX, TargetY = targetY, TargetWidth = targetWidth, TargetHeight = targetHeight, BoundingWidth = boundingWidth, BoundingHeight = boundingHeight, TexturePage = texturePage };
tpItem.Name = new UndertaleString($"PageItem {Data.TexturePageItems.Count}");
UndertaleTexturePageItem tpItem = new()
{
SourceX = sourceX,
SourceY = sourceY,
SourceWidth = sourceWidth,
SourceHeight = sourceHeight,
TargetX = targetX,
TargetY = targetY,
TargetWidth = targetWidth,
TargetHeight = targetHeight,
BoundingWidth = boundingWidth,
BoundingHeight = boundingHeight,
TexturePage = texturePage,
Name = new UndertaleString($"PageItem {Data.TexturePageItems.Count}")
};
Data.TexturePageItems.Add(tpItem);
return tpItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ foreach (Atlas atlas in packer.Atlasses)
{
var spriteParts = sprFrameRegex.Match(stripped);
spriteName = spriteParts.Groups[1].Value;
int.TryParse(spriteParts.Groups[2].Value, out frame);
Int32.TryParse(spriteParts.Groups[2].Value, out frame);
}
catch (Exception e)
{
Expand Down Expand Up @@ -597,7 +597,7 @@ Pressing ""No"" will cause the program to ignore these images.");

spriteName = spriteParts.Groups[1].Value;

if (!int.TryParse(spriteParts.Groups[2].Value, out int frame))
if (!Int32.TryParse(spriteParts.Groups[2].Value, out int frame))
throw new ScriptException($"{spriteName} has an invalid frame index.");
if (frame < 0)
throw new ScriptException($"{spriteName} is using an invalid numbering scheme. The script has stopped for your own protection.");
Expand Down
6 changes: 3 additions & 3 deletions UndertaleModTool/Scripts/Resource Repackers/ImportMasks.csx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ foreach (string file in dirFiles)
int validFrameNumber = 0;
try
{
validFrameNumber = int.Parse(stripped.Substring(lastUnderscore + 1));
validFrameNumber = Int32.Parse(stripped.Substring(lastUnderscore + 1));
}
catch
{
Expand All @@ -60,7 +60,7 @@ foreach (string file in dirFiles)
int frame = 0;
try
{
frame = int.Parse(stripped.Substring(lastUnderscore + 1));
frame = Int32.Parse(stripped.Substring(lastUnderscore + 1));
}
catch
{
Expand Down Expand Up @@ -96,7 +96,7 @@ await Task.Run(() =>
string stripped = Path.GetFileNameWithoutExtension(file);
int lastUnderscore = stripped.LastIndexOf('_');
string spriteName = stripped.Substring(0, lastUnderscore);
int frame = int.Parse(stripped.Substring(lastUnderscore + 1));
int frame = Int32.Parse(stripped.Substring(lastUnderscore + 1));
UndertaleSprite sprite = Data.Sprites.ByName(spriteName);
int collision_mask_count = sprite.CollisionMasks.Count;
while (collision_mask_count <= frame)
Expand Down
4 changes: 1 addition & 3 deletions UndertaleModTool/Scripts/Resource Unpackers/ExportMasks.csx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Made by Grossley
// Version 1 is from 12/07/2020
// This is no longer that version

using System.Text;
using System;
Expand Down Expand Up @@ -42,7 +40,7 @@ void DumpSprite(UndertaleSprite sprite)
{
for (int i = 0; i < sprite.CollisionMasks.Count; i++)
{
if (sprite.CollisionMasks[i]?.Data != null)
if (sprite.CollisionMasks[i]?.Data is not null)
{
(uint maskWidth, uint maskHeight) = sprite.CalculateMaskDimensions(Data);
TextureWorker.ExportCollisionMaskPNG(sprite.CollisionMasks[i], Path.Combine(texFolder, $"{sprite.Name.Content}_{i}.png"), (int)maskWidth, (int)maskHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ foreach (string file in dirFiles)
int validFrameNumber = 0;
try
{
validFrameNumber = int.Parse(stripped.Substring(lastUnderscore + 1));
validFrameNumber = Int32.Parse(stripped.Substring(lastUnderscore + 1));
}
catch
{
Expand Down Expand Up @@ -309,7 +309,7 @@ foreach (Atlas atlas in packer.Atlasses)
{
lastUnderscore = stripped.LastIndexOf('_');
spriteName = stripped.Substring(0, lastUnderscore);
frame = int.Parse(stripped.Substring(lastUnderscore + 1));
frame = Int32.Parse(stripped.Substring(lastUnderscore + 1));
}
catch (Exception e)
{
Expand Down
Loading