Skip to content

Commit

Permalink
started getting notifications in
Browse files Browse the repository at this point in the history
  • Loading branch information
KoloInDaCrib committed Nov 20, 2024
1 parent 81b1c7b commit 76c3eb2
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 23 deletions.
86 changes: 64 additions & 22 deletions source/funkin/ui/debug/char/components/wizard/AddCharFilesDialog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class AddCharFilesDialog extends DefaultWizardDialog
// check if the files even exist
for (thingy in uploadBoxes)
{
if (!FileUtil.doesFileExist(thingy.daField.text) && !openfl.Assets.exists(thingy.daField.text)) return false;
if (!FileUtil.doesFileExist(thingy.daField.text) && !openfl.Assets.exists(thingy.daField.text))
{
CharCreatorUtil.error("Add Files", "Path: " + thingy.daField.text + " doesn't exist. Is the spelling correct?");
return false;
}
}

// we do a little trollin
Expand All @@ -101,12 +105,20 @@ class AddCharFilesDialog extends DefaultWizardDialog
var xmlPath = uploadBox.daField.text.replace(".png", ".xml");

// checking if we even have the correct file types in the correct places
if (Path.extension(imgPath) != "png" || Path.extension(xmlPath) != "xml") return false;
if (Path.extension(imgPath) != "png" || Path.extension(xmlPath) != "xml")
{
CharCreatorUtil.error("Add Files", "The provided Path doesn't end with the supported format, (.png).");
return false;
}

// testing if we could actually use these
var imgBytes = CharCreatorUtil.gimmeTheBytes(imgPath);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(xmlPath);
if (imgBytes == null || xmlBytes == null) return false;
if (imgBytes == null || xmlBytes == null)
{
CharCreatorUtil.error("Add Files", "Error retrieving Bytes from the given Path.");
return false;
}

var tempSprite = new FlxSprite();
try
Expand All @@ -116,6 +128,7 @@ class AddCharFilesDialog extends DefaultWizardDialog
}
catch (e)
{
CharCreatorUtil.error("Add Files", "The provided Bytes cannot be used to make Character Frames.");
tempSprite.destroy();
return false;
}
Expand All @@ -141,12 +154,20 @@ class AddCharFilesDialog extends DefaultWizardDialog
var txtPath = uploadBoxes[0].daField.text.replace(".png", ".txt");

// checking if we even have the correct file types in the correct places
if (Path.extension(imgPath) != "png" || Path.extension(txtPath) != "txt") return false;
if (Path.extension(imgPath) != "png" || Path.extension(txtPath) != "txt")
{
CharCreatorUtil.error("Add Files", "The provided Path doesn't end with the supported format, (.png).");
return false;
}

// testing if we could actually use these
var imgBytes = CharCreatorUtil.gimmeTheBytes(imgPath);
var txtBytes = CharCreatorUtil.gimmeTheBytes(txtPath);
if (imgBytes == null || txtBytes == null) return false;
if (imgBytes == null || txtBytes == null)
{
CharCreatorUtil.error("Add Files", "Error retrieving Bytes from the given Path.");
return false;
}

var tempSprite = new FlxSprite();
try
Expand All @@ -156,6 +177,7 @@ class AddCharFilesDialog extends DefaultWizardDialog
}
catch (e)
{
CharCreatorUtil.error("Add Files", "The provided Bytes cannot be used to make Character Frames.");
tempSprite.destroy();
return false;
}
Expand All @@ -170,13 +192,25 @@ class AddCharFilesDialog extends DefaultWizardDialog
var zipPath = uploadBoxes[0].daField.text;

// checking if we even have the correct file types in the correct places
if (Path.extension(zipPath) != "zip") return false;
if (Path.extension(zipPath) != "zip")
{
CharCreatorUtil.error("Add Files", "The provided Path doesn't end with the supported format, (.zip).");
return false;
}

var zipBytes = CharCreatorUtil.gimmeTheBytes(zipPath);
if (zipBytes == null) return false;
if (zipBytes == null)
{
CharCreatorUtil.error("Add Files", "Error retrieving Bytes from the given Path.");
return false;
}

var zipFiles = FileUtil.readZIPFromBytes(zipBytes);
if (zipFiles.length == 0) return false;
if (zipFiles.length == 0)
{
CharCreatorUtil.error("Add Files", "The provided .zip file has no content.");
return false;
}

params.files = [];
var hasAnimData:Bool = false;
Expand All @@ -191,7 +225,11 @@ class AddCharFilesDialog extends DefaultWizardDialog
{
var fileData = entry.data.toString();
var animData:AnimAtlas = haxe.Json.parse(CharCreatorUtil.normalizeJSONText(fileData));
if (animData == null) return false;
if (animData == null)
{
CharCreatorUtil.error("Add Files", "Error parsing the Animation.json File.");
return false;
}

hasAnimData = true;
}
Expand All @@ -200,37 +238,41 @@ class AddCharFilesDialog extends DefaultWizardDialog
{
var fileData = entry.data.toString();
var spritemapData:AnimateAtlas = haxe.Json.parse(CharCreatorUtil.normalizeJSONText(fileData));
if (spritemapData == null) return false;
if (spritemapData == null)
{
CharCreatorUtil.error("Add Files", "Error parsing the Spritemap.json File.");
return false;
}

hasSpritemapData = true;
}

if (entry.fileName.startsWith("spritemap") && entry.fileName.endsWith(".png"))
{
if (BitmapData.fromBytes(entry.data) == null) return false;
if (BitmapData.fromBytes(entry.data) == null)
{
CharCreatorUtil.error("Add Files", "Error parsing the Spritemap.png File.");
return false;
}
hasImageData = true;
}
}

if (hasAnimData && hasSpritemapData && hasImageData) params.files.push({name: zipPath, bytes: zipBytes});
return hasAnimData && hasSpritemapData && hasImageData;

if (!(hasAnimData && hasSpritemapData && hasImageData))
{
CharCreatorUtil.error("Add Files", "Insufficient amount of Files in the .zip File.");
return false;
}

return true;
default:
return false;
}

return false;
}

function recursiveUploadBox():Void
{
var uploadBox = new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG);
uploadBox.daField.onChange = _ -> {
uploadBox.daField.onChange = null;
recursiveUploadBox();
};
addAssetsBox.addComponent(uploadBox);
}
}

class AddAssetBox extends HBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ class ConfirmDialog extends DefaultWizardDialog
}

override public function isNextStepAvailable()
{
CharCreatorUtil.info("Character Generating Wizard", "Generating Character based on the files...");
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ class StartWizardDialog extends DefaultWizardDialog

override public function isNextStepAvailable()
{
return ((params.generateCharacter || params.generatePlayerData) && params.characterID != "");
if ((!params.generateCharacter || !params.generatePlayerData))
{
CharCreatorUtil.error("Start", "Please choose to Generate at least one thing.");
return false;
}

if (params.characterID == "")
{
CharCreatorUtil.error("Start", "Missing the Character ID.");
return false;
}

return true;
}

override public function showDialog(modal:Bool = true)
Expand Down
22 changes: 22 additions & 0 deletions source/funkin/ui/debug/char/util/CharCreatorUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package funkin.ui.debug.char.util;
import haxe.io.Path;
import haxe.ui.core.Screen;
import haxe.ui.focus.FocusManager;
import haxe.ui.notifications.NotificationType;
import haxe.ui.notifications.NotificationManager;

class CharCreatorUtil
{
Expand Down Expand Up @@ -42,4 +44,24 @@ class CharCreatorUtil
path = path.replace(cwd, "");
return !Path.isAbsolute(path) && path.indexOf(checkFor) != -1;
}

public static function error(title:String, body:String)
{
NotificationManager.instance.addNotification(
{
title: title,
body: body,
type: NotificationType.Error
});
}

public static function info(title:String, body:String)
{
NotificationManager.instance.addNotification(
{
title: title,
body: body,
type: NotificationType.Info
});
}
}

0 comments on commit 76c3eb2

Please sign in to comment.