ANSIUtil.hx code style cleanup, plus use ANSI logging in registry classes!

This commit is contained in:
EliteMasterEric
2025-12-22 10:01:48 -08:00
committed by Kade
parent 612b5d8009
commit 70e5ad8874
31 changed files with 790 additions and 279 deletions
+2 -2
View File
@@ -135,11 +135,11 @@ class Main extends Sprite
Handle.initAsync(function(success:Bool):Void {
if (success)
{
trace(' HXVLC '.bold().bg_white() + ' LibVLC instance initialized!');
trace(' HXVLC '.bold().bg_orange() + ' LibVLC instance initialized!');
}
else
{
trace(' HXVLC '.bold().bg_white() + ' LibVLC instance failed to initialize!');
trace(' HXVLC '.bold().bg_orange() + ' LibVLC instance failed to initialize!');
}
});
#end
+1 -1
View File
@@ -30,7 +30,7 @@ class Postbuild
sys.FileSystem.deleteFile(BUILD_TIME_FILE);
Sys.println(' INFO '.bold().bg_blue() + ' Build took: ${format(end - start)}');
Sys.println(' INFO '.info() + ' Build took: ${format(end - start)}');
}
}
+1 -1
View File
@@ -166,7 +166,7 @@ class WaveformData
var ratio = newSamplesPerPoint / samplesPerPoint;
if (ratio == 1) return result;
if (ratio < 1) trace(' WARNING '.bg_yellow().bold() + ' Downsampling will result in a low precision.');
if (ratio < 1) trace(' WARNING '.warning() + ' Downsampling will result in a low precision.');
var inputSampleCount = this.lenSamples();
var outputSampleCount = Std.int(inputSampleCount * ratio);
+6 -6
View File
@@ -78,7 +78,7 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
// SCRIPTED ENTRIES
//
var scriptedEntryClassNames:Array<String> = getScriptedClassNames();
log('Parsing ${scriptedEntryClassNames.length} scripted entries...');
log(' INFO '.info() + 'Parsing ${scriptedEntryClassNames.length} scripted entries...');
for (entryCls in scriptedEntryClassNames)
{
@@ -112,7 +112,7 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
var unscriptedEntryIds:Array<String> = entryIdList.filter(function(entryId:String):Bool {
return !entries.exists(entryId);
});
log('Parsing ${unscriptedEntryIds.length} unscripted entries...');
log(' INFO '.info() + 'Parsing ${unscriptedEntryIds.length} unscripted entries...');
for (entryId in unscriptedEntryIds)
{
try
@@ -120,14 +120,14 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
var entry:Null<T> = createEntry(entryId);
if (entry != null)
{
trace(' Loaded entry data: ${entry}');
log('Loaded entry data: ${entry}');
entries.set(entry.id, entry);
}
}
catch (e)
{
// Print the error.
trace(' Failed to load entry data: ${entryId}');
log(' WARNING '.warning() + ' Failed to load entry data: ${entryId}');
trace(e);
continue;
}
@@ -224,7 +224,7 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
function log(message:String):Void
{
trace('[' + registryId + '] ' + message);
trace(' $registryId '.bold().bg_note_down() + ' $message');
}
function loadEntryFile(id:String):JsonFile
@@ -333,7 +333,7 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
function printErrors(errors:Array<json2object.Error>, id:String = ''):Void
{
trace('[${registryId}] Failed to parse entry data: ${id}');
trace(' $registryId '.bold().bg_note_down() + ' ERROR '.error() + 'Failed to parse entry data: ${id}');
for (error in errors)
{
+10 -10
View File
@@ -12,27 +12,27 @@ class DataError
switch (error)
{
case IncorrectType(vari, expected, pos):
trace(' Expected field "$vari" to be of type "$expected".');
trace(' ERROR '.error() + 'Expected field "$vari" to be of type "$expected".');
printPos(pos);
case IncorrectEnumValue(value, expected, pos):
trace(' Invalid enum value (expected "$expected", got "$value")');
trace(' ERROR '.error() + 'Invalid enum value (expected "$expected", got "$value")');
printPos(pos);
case InvalidEnumConstructor(value, expected, pos):
trace(' Invalid enum constructor (epxected "$expected", got "$value")');
trace(' ERROR '.error() + 'Invalid enum constructor (epxected "$expected", got "$value")');
printPos(pos);
case UninitializedVariable(vari, pos):
trace(' Uninitialized variable "$vari"');
trace(' ERROR '.error() + 'Uninitialized variable "$vari"');
printPos(pos);
case UnknownVariable(vari, pos):
trace(' Unknown variable "$vari"');
trace(' ERROR '.error() + 'Unknown variable "$vari"');
printPos(pos);
case ParserError(message, pos):
trace(' Parsing error: ${message}');
trace(' ERROR '.error() + 'Parsing error: ${message}');
printPos(pos);
case CustomFunctionException(e, pos):
if (Std.isOfType(e, String))
{
trace(' ${e}');
trace(' ERROR '.error() + '${e}');
}
else
{
@@ -49,11 +49,11 @@ class DataError
switch (Type.typeof(e))
{
case TClass(c):
trace(' [${Type.getClassName(c)}] ${e.toString()}');
trace(' ERROR '.error() + '(${Type.getClassName(c)}) ${e.toString()}');
case TEnum(c):
trace(' [${Type.getEnumName(c)}] ${e.toString()}');
trace(' ERROR '.error() + '(${Type.getEnumName(c)}) ${e.toString()}');
default:
trace(' [${Type.typeof(e)}] ${e.toString()}');
trace(' ERROR '.error() + '(${Type.typeof(e)}) ${e.toString()}');
}
}
+35 -26
View File
@@ -51,7 +51,7 @@ class CharacterDataParser
{
// Clear any stages that are cached if there were any.
clearCharacterCache();
trace('[CHARACTER] Parsing all entries...');
log(' INFO '.info() + 'Parsing all entries...');
//
// UNSCRIPTED CHARACTERS
@@ -60,7 +60,7 @@ class CharacterDataParser
var unscriptedCharIds:Array<String> = charIdList.filter(function(charId:String):Bool {
return !characterCache.exists(charId);
});
trace(' Fetching data for ${unscriptedCharIds.length} characters...');
log('Fetching data for ${unscriptedCharIds.length} characters...');
for (charId in unscriptedCharIds)
{
try
@@ -68,7 +68,7 @@ class CharacterDataParser
var charData:Null<CharacterData> = parseCharacterData(charId);
if (charData != null)
{
trace(' Loaded character data: ${charId}');
log('Loaded character "${charId}"');
characterCache.set(charId, charData);
}
}
@@ -88,19 +88,19 @@ class CharacterDataParser
var scriptedCharClassNames1:Array<String> = ScriptedSparrowCharacter.listScriptClasses();
if (scriptedCharClassNames1.length > 0)
{
trace(' Instantiating ${scriptedCharClassNames1.length} (Sparrow) scripted characters...');
log('Instantiating ${scriptedCharClassNames1.length} (Sparrow) scripted characters...');
for (charCls in scriptedCharClassNames1)
{
try
{
var character:SparrowCharacter = ScriptedSparrowCharacter.init(charCls, DEFAULT_CHAR_ID);
trace(' Initialized character ${character.characterName}');
log('Loaded character ${character.characterName} (scripted: $charCls)');
characterScriptedClass.set(character.characterId, charCls);
}
catch (e)
{
trace(' FAILED to instantiate scripted Sparrow character: ${charCls}');
trace(e);
log(' ERROR '.error() + 'Failed to initialize scripted Sparrow character: $charCls');
log(' ERROR '.error() + '$e');
}
}
}
@@ -108,18 +108,19 @@ class CharacterDataParser
var scriptedCharClassNames2:Array<String> = ScriptedPackerCharacter.listScriptClasses();
if (scriptedCharClassNames2.length > 0)
{
trace(' Instantiating ${scriptedCharClassNames2.length} (Packer) scripted characters...');
log('Instantiating ${scriptedCharClassNames2.length} (Packer) scripted characters...');
for (charCls in scriptedCharClassNames2)
{
try
{
var character:PackerCharacter = ScriptedPackerCharacter.init(charCls, DEFAULT_CHAR_ID);
log('Loaded character ${character.characterName} (scripted: $charCls)');
characterScriptedClass.set(character.characterId, charCls);
}
catch (e)
{
trace(' FAILED to instantiate scripted Packer character: ${charCls}');
trace(e);
log(' ERROR '.error() + 'Failed to initialize scripted Packer character: $charCls');
log(' ERROR '.error() + '$e');
}
}
}
@@ -127,18 +128,19 @@ class CharacterDataParser
var scriptedCharClassNames3:Array<String> = ScriptedMultiSparrowCharacter.listScriptClasses();
if (scriptedCharClassNames3.length > 0)
{
trace(' Instantiating ${scriptedCharClassNames3.length} (Multi-Sparrow) scripted characters...');
log('Instantiating ${scriptedCharClassNames3.length} (Multi-Sparrow) scripted characters...');
for (charCls in scriptedCharClassNames3)
{
try
{
var character:MultiSparrowCharacter = ScriptedMultiSparrowCharacter.init(charCls, DEFAULT_CHAR_ID);
log('Loaded character ${character.characterName} (scripted: $charCls)');
characterScriptedClass.set(character.characterId, charCls);
}
catch (e)
{
trace(' FAILED to instantiate scripted Multi-Sparrow character: ${charCls}');
trace(e);
log(' ERROR '.error() + 'Failed to initialize scripted Multi-Sparrow character: $charCls');
log(' ERROR '.error() + '$e');
}
}
}
@@ -146,18 +148,19 @@ class CharacterDataParser
var scriptedCharClassNames4:Array<String> = ScriptedAnimateAtlasCharacter.listScriptClasses();
if (scriptedCharClassNames4.length > 0)
{
trace(' Instantiating ${scriptedCharClassNames4.length} (Animate Atlas) scripted characters...');
log('Instantiating ${scriptedCharClassNames4.length} (Animate Atlas) scripted characters...');
for (charCls in scriptedCharClassNames4)
{
try
{
var character:AnimateAtlasCharacter = ScriptedAnimateAtlasCharacter.init(charCls, DEFAULT_CHAR_ID);
log('Loaded character ${character.characterName} (scripted: $charCls)');
characterScriptedClass.set(character.characterId, charCls);
}
catch (e)
{
trace(' FAILED to instantiate scripted Animate Atlas character: ${charCls}');
trace(e);
log(' ERROR '.error() + 'Failed to initialize scripted Animate Atlas character: $charCls');
log(' ERROR '.error() + '$e');
}
}
}
@@ -165,18 +168,19 @@ class CharacterDataParser
var scriptedCharClassNames5:Array<String> = ScriptedMultiAnimateAtlasCharacter.listScriptClasses();
if (scriptedCharClassNames5.length > 0)
{
trace(' Instantiating ${scriptedCharClassNames5.length} (Multi-Animate Atlas) scripted characters...');
log('Instantiating ${scriptedCharClassNames5.length} (Multi-Animate Atlas) scripted characters...');
for (charCls in scriptedCharClassNames5)
{
try
{
var character:MultiAnimateAtlasCharacter = ScriptedMultiAnimateAtlasCharacter.init(charCls, DEFAULT_CHAR_ID);
log('Loaded character ${character.characterName} (scripted: $charCls)');
characterScriptedClass.set(character.characterId, charCls);
}
catch (e)
{
trace(' FAILED to instantiate scripted Multi-Animate Atlas character: ${charCls}');
trace(e);
log(' ERROR '.error() + 'Failed to initialize scripted Multi-Animate Atlas character: $charCls');
log(' ERROR '.error() + '$e');
}
}
}
@@ -194,24 +198,24 @@ class CharacterDataParser
if (scriptedCharClassNames.length > 0)
{
trace(' Instantiating ${scriptedCharClassNames.length} (Base) scripted characters...');
log('Instantiating ${scriptedCharClassNames.length} (Base) scripted characters...');
for (charCls in scriptedCharClassNames)
{
var character:BaseCharacter = ScriptedBaseCharacter.init(charCls, DEFAULT_CHAR_ID, Custom);
if (character == null)
{
trace(' Failed to instantiate scripted character: ${charCls}');
log(' ERROR '.error() + 'Failed to initialize scripted character: $charCls');
continue;
}
else
{
trace(' Successfully instantiated scripted character: ${charCls}');
log('Loaded character ${character.characterName} (scripted: $charCls)');
characterScriptedClass.set(character.characterId, charCls);
}
}
}
trace(' Successfully loaded ${Lambda.count(characterCache)} stages.');
log(' INFO '.info() + 'Successfully loaded ${characterCache.size()} stages.');
}
/**
@@ -270,7 +274,7 @@ class CharacterDataParser
case CharacterRenderType.MultiAnimateAtlas:
char = new MultiAnimateAtlasCharacter(charId);
default:
trace(' WARNING '.bold().bg_yellow() + ' Creating character with undefined renderType ${charData.renderType}');
trace(' WARNING '.warning() + ' Creating character with undefined renderType ${charData.renderType}');
char = new BaseCharacter(charId, CharacterRenderType.Custom);
}
}
@@ -338,7 +342,7 @@ class CharacterDataParser
if (!Assets.exists(Paths.image(charPath)))
{
trace(' WARNING '.bold().bg_yellow() + ' Character ${char} has no freeplay icon.');
trace(' WARNING '.warning() + ' Character ${char} has no freeplay icon.');
return null;
}
@@ -355,7 +359,7 @@ class CharacterDataParser
if (idleFrame == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Character ${char} has no idle in their freeplay icon.');
trace(' WARNING '.warning() + ' Character ${char} has no idle in their freeplay icon.');
return null;
}
@@ -652,6 +656,11 @@ class CharacterDataParser
// All good!
return input;
}
static function log(message:String):Void
{
trace(' CHARACTER '.bold().bg_note_down() + ' $message');
}
}
/**
+4 -4
View File
@@ -56,7 +56,7 @@ using funkin.data.song.migrator.SongDataMigrator;
// SCRIPTED ENTRIES
//
var scriptedEntryClassNames:Array<String> = getScriptedClassNames();
log('Parsing ${scriptedEntryClassNames.length} scripted entries...');
log(' INFO '.info() + 'Parsing ${scriptedEntryClassNames.length} scripted entries...');
for (entryCls in scriptedEntryClassNames)
{
@@ -99,15 +99,15 @@ using funkin.data.song.migrator.SongDataMigrator;
var entry:Null<Song> = createEntry(entryId);
if (entry != null)
{
trace(' Loaded entry data: ${entry}');
log('Loaded entry data: ${entry}');
entries.set(entry.id, entry);
}
}
catch (e:Dynamic)
{
// Print the error.
trace(' Failed to load entry data: ${entryId}');
trace(e);
log(' ERROR '.error() + 'Failed to load entry data: ${entryId}');
log(' ERROR '.error() + e);
continue;
}
}
-1
View File
@@ -254,7 +254,6 @@ class FunkinCamera extends FlxCamera
function disposeTextures():Void
{
trace('disposing textures');
for (bitmap in grabbed)
{
bitmap.dispose();
+1 -1
View File
@@ -68,7 +68,7 @@ class PolymodErrorHandler
static function logError(message:String):Void
{
trace(' ERROR '.bg_red().bold() + ' ${message}');
trace(' ERROR '.error() + ' ${message}');
}
static function logWarn(message:String):Void
@@ -337,7 +337,7 @@ class BaseCharacter extends Bopper
{
if (PlayState.instance.iconP1 == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Player 1 health icon not found!');
trace(' WARNING '.warning() + ' Player 1 health icon not found!');
return;
}
PlayState.instance.iconP1.configure(_data?.healthIcon);
@@ -347,7 +347,7 @@ class BaseCharacter extends Bopper
{
if (PlayState.instance.iconP2 == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Player 2 health icon not found!');
trace(' WARNING '.warning() + ' Player 2 health icon not found!');
return;
}
PlayState.instance.iconP2.configure(_data?.healthIcon);
@@ -67,7 +67,7 @@ class SetHealthIconSongEvent extends SongEvent
PlayState.instance.iconP2.configure(healthIconData);
}
default:
trace(' WARNING '.bold().bg_yellow() + ' Unknown character index: ' + data.value.char);
trace(' WARNING '.warning() + ' Unknown character index: ' + data.value.char);
}
}
+21 -18
View File
@@ -154,7 +154,7 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
{
if (!validateVariationId(vari))
{
trace(' WARNING '.bold().bg_yellow() + ' Variation id "$vari" is invalid, skipping...');
log(' WARNING '.bold().bg_yellow() + ' Variation id "$vari" is invalid, skipping...');
continue;
}
@@ -162,19 +162,19 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
if (variMeta != null)
{
_metadata.set(variMeta.variation, variMeta);
trace(' Loaded variation: $vari');
log('Loaded variation: $vari');
}
else
{
FlxG.log.warn('[SONG] Failed to load variation metadata (${id}:${vari}), is the path correct?');
trace(' FAILED to load variation: $vari');
log('FAILED to load variation: $vari');
}
}
}
if (_metadata.size() == 0)
{
trace(' WARNING '.bold().bg_yellow() + ' Could not find song data for songId: $id');
log(' WARNING '.warning() + ' Could not find song data for songId: $id');
return;
}
@@ -302,7 +302,7 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
// If there are no difficulties in the metadata, there's a problem.
if (metadata.playData.difficulties.length == 0)
{
trace('[SONG] Warning: Song $id (variation ${metadata.variation}) has no difficulties listed in metadata!');
log(' WARNING '.warning() + 'Song $id (variation ${metadata.variation}) has no difficulties listed in metadata!');
continue;
}
@@ -351,36 +351,35 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
clearCharts();
}
trace('Caching ${variations.length} chart files for song $id');
for (variation in variations)
for (vari in variations)
{
var version:Null<thx.semver.Version> = SongRegistry.instance.fetchEntryChartVersion(id, variation);
var version:Null<thx.semver.Version> = SongRegistry.instance.fetchEntryChartVersion(id, vari);
if (version == null) continue;
var chart:Null<SongChartData> = SongRegistry.instance.parseEntryChartDataWithMigration(id, variation, version);
var chart:Null<SongChartData> = SongRegistry.instance.parseEntryChartDataWithMigration(id, vari, version);
if (chart == null) continue;
applyChartData(chart, variation);
applyChartData(chart, vari);
}
trace('Done caching charts.');
log('Cached ${variations.length} chart data files for song "$id"');
}
function applyChartData(chartData:SongChartData, variation:String):Void
function applyChartData(chartData:SongChartData, vari:String):Void
{
var chartNotes = chartData.notes;
for (diffId in chartNotes.keys())
{
// Retrieve the cached difficulty data. This one could potentially be null.
var nullDiff:Null<SongDifficulty> = getDifficulty(diffId, variation);
var nullDiff:Null<SongDifficulty> = getDifficulty(diffId, vari);
// if the difficulty doesn't exist, create a new one, and then proceed to fill it with data.
// I mostly do this since I don't wanna throw around ? everywhere for null check lol?
var difficulty:SongDifficulty = nullDiff ?? new SongDifficulty(this, diffId, variation);
var difficulty:SongDifficulty = nullDiff ?? new SongDifficulty(this, diffId, vari);
if (nullDiff == null)
{
trace('Fabricated new difficulty for $diffId.');
var metadata = _metadata.get(variation);
difficulties.get(variation)?.set(diffId, difficulty);
var metadata = _metadata.get(vari);
difficulties.get(vari)?.set(diffId, difficulty);
if (metadata != null)
{
@@ -668,7 +667,6 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
static function _fetchData(id:String):Null<SongMetadata>
{
trace('Fetching song metadata for $id');
var version:Null<thx.semver.Version> = SongRegistry.instance.fetchEntryMetadataVersion(id);
if (version == null) return null;
return SongRegistry.instance.parseEntryMetadataWithMigration(id, Constants.DEFAULT_VARIATION, version);
@@ -695,6 +693,11 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
return VARIATION_REGEX.match(variation);
}
static function log(message:String):Void
{
trace(' SONG '.bold().bg_note_down() + ' $message');
}
}
class SongDifficulty
@@ -817,7 +820,7 @@ class SongDifficulty
{
for (voice in buildVoiceList())
{
trace('Caching vocal track: $voice');
trace(' SONG '.bold().bg_note_down() + ' Caching vocal track "$voice" for song "${song.id}"');
funkin.FunkinMemory.cacheSound(voice);
}
}
+4 -4
View File
@@ -47,7 +47,7 @@ class Save implements ConsoleClass
public static function load():Save
{
trace("[SAVE] Loading save...");
trace(' SAVE '.bold().bg_note_down() + ' Loading save...');
// Bind save data.
final loadedSave:Save = loadFromSlot(Constants.BASE_SAVE_SLOT);
@@ -404,9 +404,9 @@ class Save implements ConsoleClass
{
if (!data.unlocks.charactersSeen.contains(character))
{
trace('Character seen: ' + character);
trace(' SAVE '.bold().bg_note_down() + 'Seen character "$character" in Character Select!');
data.unlocks.charactersSeen.push(character);
trace('New characters seen list: ' + data.unlocks.charactersSeen);
trace(' SAVE '.bold().bg_note_down() + 'New list of characters seen: ${data.unlocks.charactersSeen}');
Save.system.flush();
}
}
@@ -517,7 +517,7 @@ class Save implements ConsoleClass
var song = data.scores.songs.get(songId);
if (song == null)
{
trace('Could not find song data for $songId $difficultyId $variation');
trace(' SAVE '.bold().bg_note_down() + ' WARNING '.warning() + 'Could not find song data for $songId $difficultyId $variation');
song = [];
data.scores.songs.set(songId, song);
}
+1 -1
View File
@@ -40,7 +40,7 @@ class PixelatedIcon extends FlxFilteredSprite
if (!Assets.exists(Paths.image(charPath)))
{
trace(' WARNING '.bold().bg_yellow() + ' Character ${char} has no freeplay icon.');
trace(' WARNING '.warning() + ' Character ${char} has no freeplay icon.');
this.visible = false;
return;
}
@@ -21,13 +21,13 @@ class CreditsDataHandler
{
if (data == null)
{
Sys.println(' INFO '.bold().bg_blue() + ' CreditsData(NULL)');
Sys.println(' INFO '.info() + ' CreditsData(NULL)');
return;
}
if (data.entries == null || data.entries.length == 0)
{
Sys.println(' INFO '.bold().bg_blue() + ' CreditsData(EMPTY)');
Sys.println(' INFO '.info() + ' CreditsData(EMPTY)');
return;
}
@@ -38,7 +38,7 @@ class CreditsDataHandler
lineCount += entry?.body?.length ?? 0;
}
Sys.println(' INFO '.bold().bg_blue() + ' CreditsData($entryCount entries containing $lineCount lines)');
Sys.println(' INFO '.info() + ' CreditsData($entryCount entries containing $lineCount lines)');
}
#end
+4 -4
View File
@@ -12,12 +12,12 @@ class CreditsDataMacro
public static macro function loadCreditsData():haxe.macro.Expr.ExprOf<CreditsData>
{
#if !display
Sys.println(' INFO '.bold().bg_blue() + ' Hardcoding credits data...');
Sys.println(' INFO '.info() + ' Hardcoding credits data...');
var json = CreditsDataMacro.fetchJSON();
if (json == null)
{
Context.info(' WARNING '.bold().bg_yellow() + ' Could not fetch JSON data for credits.', Context.currentPos());
Context.info(' WARNING '.warning() + ' Could not fetch JSON data for credits.', Context.currentPos());
return macro $v{CreditsDataHandler.getFallback()};
}
@@ -25,7 +25,7 @@ class CreditsDataMacro
if (creditsData == null)
{
Context.info(' WARNING '.bold().bg_yellow() + ' Could not parse JSON data for credits.', Context.currentPos());
Context.info(' WARNING '.warning() + ' Could not parse JSON data for credits.', Context.currentPos());
return macro $v{CreditsDataHandler.getFallback()};
}
@@ -66,7 +66,7 @@ class CreditsDataMacro
}
catch (e)
{
trace(' ERROR '.bg_red().bold() + ' Failed to parse JSON data for credits.');
trace(' ERROR '.error() + ' Failed to parse JSON data for credits.');
trace(e);
return null;
}
@@ -2857,7 +2857,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
{
if (notePreviewViewport == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Tried to set note preview viewport bounds, but notePreviewViewport is null!');
trace(' WARNING '.warning() + ' Tried to set note preview viewport bounds, but notePreviewViewport is null!');
return;
}
@@ -84,7 +84,7 @@ class ChartEditorBaseDialog extends Dialog
if (_overlay == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Dialog overlay is null, skipping overlay fade...');
trace(' WARNING '.warning() + ' Dialog overlay is null, skipping overlay fade...');
return;
}
@@ -149,7 +149,7 @@ class ChartEditorWelcomeDialog extends ChartEditorBaseDialog
if (songName == null) songName = songData.getDifficulty()?.songName;
if (songName == null) // Still null?
{
trace(' WARNING '.bold().bg_yellow() + ' Could not fetch song name for ${targetSongId}');
trace(' WARNING '.warning() + ' Could not fetch song name for ${targetSongId}');
continue;
}
@@ -257,6 +257,7 @@ class ChartEditorWelcomeDialog extends ChartEditorBaseDialog
// Open the "Import Chart" dialog
chartEditorState.openImportChartWizard('osumania', false);
}
/**
* Called when the user clicks the "Import Chart: StepMania" link in the dialog.
* Reassign this function to change the behavior.
@@ -206,7 +206,7 @@ class ChartEditorAudioHandler
}
else
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to parse waveform data for vocal track.');
trace(' WARNING '.warning() + ' Failed to parse waveform data for vocal track.');
}
state.audioVocalTrackGroup.playerVoicesOffset = state.currentVocalOffsetPlayer;
@@ -224,7 +224,7 @@ class ChartEditorAudioHandler
}
else
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to parse waveform data for vocal track.');
trace(' WARNING '.warning() + ' Failed to parse waveform data for vocal track.');
}
state.audioVocalTrackGroup.opponentVoicesOffset = state.currentVocalOffsetOpponent;
@@ -311,7 +311,7 @@ class ChartEditorAudioHandler
var data:Null<Bytes> = state.audioInstTrackData.get('default');
if (data == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to access inst track ($key)');
trace(' WARNING '.warning() + ' Failed to access inst track ($key)');
continue;
}
zipEntries.push(FileUtil.makeZIPEntryFromBytes('Inst.ogg', data));
@@ -321,7 +321,7 @@ class ChartEditorAudioHandler
var data:Null<Bytes> = state.audioInstTrackData.get(key);
if (data == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to access inst track ($key)');
trace(' WARNING '.warning() + ' Failed to access inst track ($key)');
continue;
}
zipEntries.push(FileUtil.makeZIPEntryFromBytes('Inst-${key}.ogg', data));
@@ -346,7 +346,7 @@ class ChartEditorAudioHandler
var data:Null<Bytes> = state.audioVocalTrackData.get(key);
if (data == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to access vocal track ($key)');
trace(' WARNING '.warning() + ' Failed to access vocal track ($key)');
continue;
}
zipEntries.push(FileUtil.makeZIPEntryFromBytes('Voices-${key}.ogg', data));
@@ -523,7 +523,7 @@ class ChartEditorImportExportHandler
var onSave:Array<String>->Void = function(paths:Array<String>) {
if (paths.length != 1)
{
trace(' WARNING '.bold().bg_yellow() + ' Could not get save path.');
trace(' WARNING '.warning() + ' Could not get save path.');
state.applyWindowTitle();
}
else
+2 -2
View File
@@ -402,7 +402,7 @@ class FreeplayState extends MusicBeatSubState
if (level == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Could not find level with id (${levelId})');
trace(' WARNING '.warning() + ' Could not find level with id (${levelId})');
continue;
}
@@ -412,7 +412,7 @@ class FreeplayState extends MusicBeatSubState
if (song == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Could not find song with id (${songId})');
trace(' WARNING '.warning() + ' Could not find song with id (${songId})');
continue;
}
@@ -120,8 +120,7 @@ class FunkinPreloader extends FlxBasePreloader
{
super(Constants.PRELOADER_MIN_STAGE_TIME);
// We can't even call trace() yet, until Flixel loads.
trace('Initializing custom preloader...');
trace(' PRELOADER '.bold().bg_note_left() + ' Starting custom preloader...');
}
override function create():Void
@@ -143,7 +142,7 @@ class FunkinPreloader extends FlxBasePreloader
this._width = Lib.current.stage.stageWidth;
this._height = Lib.current.stage.stageHeight;
trace('Preloader size: ' + this._width + 'x' + this._height);
trace(' PRELOADER '.bold().bg_note_left() + ' Resolution: ${this._width}x${this._height}');
// Scale assets to the screen size.
// Desktop is always 1:1 scale, mobile needs DPI normalization for consistent positioning
@@ -879,7 +878,10 @@ class FunkinPreloader extends FlxBasePreloader
var percentage:Int = Math.floor(percent * 100);
progressRightText.text = '$percentage%';
if (currentState.getProgressLeftText() != null) trace('Preloader state: ' + currentState + ' (' + percentage + '%, ' + elapsed + 's)');
if (currentState.getProgressLeftText() != null)
{
trace(' PRELOADER '.bold().bg_note_left() + ' $currentState ($percentage%, $elapsed sec)');
}
super.update(percent);
}
+333 -84
View File
@@ -2,56 +2,83 @@ package funkin.util;
/**
* Enum abstract representing ANSI codes for text colors, background colors, and text styles.
* TODO: Add more colors?
*/
// TODO: Add more colors maybe?
@SuppressWarnings([
"checkstyle:FieldDocComment",
"checkstyle:MemberName",
"checkstyle:TypeDocComment"
])
enum abstract AnsiCode(String) from String to String
{
var RESET = '\x1b[0m';
var BOLD = '\x1b[1m';
var DIM = '\x1b[2m';
var UNDERLINE = '\x1b[4m';
var BLINK = '\x1b[5m';
var INVERSE = '\x1b[7m';
var HIDDEN = '\x1b[8m';
var STRIKETHROUGH = '\x1b[9m';
public var RESET = '\x1b[0m';
public var BOLD = '\x1b[1m';
public var DIM = '\x1b[2m';
public var UNDERLINE = '\x1b[4m';
public var BLINK = '\x1b[5m';
public var INVERSE = '\x1b[7m';
public var HIDDEN = '\x1b[8m';
public var STRIKETHROUGH = '\x1b[9m';
var BLACK = '\x1b[30m';
var RED = '\x1b[31m';
var GREEN = '\x1b[32m';
var YELLOW = '\x1b[33m';
var BLUE = '\x1b[34m';
var MAGENTA = '\x1b[35m';
var CYAN = '\x1b[36m';
var WHITE = '\x1b[37m';
// 30-37 set foreground to standard colors
public var BLACK = '\x1b[30m';
public var RED = '\x1b[31m';
public var GREEN = '\x1b[32m';
public var YELLOW = '\x1b[33m';
public var BLUE = '\x1b[34m';
public var MAGENTA = '\x1b[35m';
public var CYAN = '\x1b[36m';
public var WHITE = '\x1b[37m';
var BG_BLACK = '\x1b[40m';
var BG_RED = '\x1b[41m';
var BG_GREEN = '\x1b[42m';
var BG_YELLOW = '\x1b[43m';
var BG_BLUE = '\x1b[44m';
var BG_MAGENTA = '\x1b[45m';
var BG_CYAN = '\x1b[46m';
var BG_WHITE = '\x1b[47m';
var BG_ORANGE = '\x1b[48;5;208m';
// 38 has two modes
// [38;2;#m uses one of 256 colors
public var ORANGE = '\x1b[38;5;208m';
var BRIGHT_BLACK = '\x1b[90m';
var BRIGHT_RED = '\x1b[91m';
var BRIGHT_GREEN = '\x1b[92m';
var BRIGHT_YELLOW = '\x1b[93m';
var BRIGHT_BLUE = '\x1b[94m';
var BRIGHT_MAGENTA = '\x1b[95m';
var BRIGHT_CYAN = '\x1b[96m';
var BRIGHT_WHITE = '\x1b[97m';
// [38;2;RR;GG;BBm uses 24-bit color RGB
public var NOTE_LEFT = '\x1b[38;2;255;34;170m';
public var NOTE_DOWN = '\x1b[38;2;0;238;255m';
public var NOTE_UP = '\x1b[38;2;0;204;0m';
public var NOTE_RIGHT = '\x1b[38;2;204;17;17m';
var BG_BRIGHT_BLACK = '\x1b[100m';
var BG_BRIGHT_RED = '\x1b[101m';
var BG_BRIGHT_GREEN = '\x1b[102m';
var BG_BRIGHT_YELLOW = '\x1b[103m';
var BG_BRIGHT_BLUE = '\x1b[104m';
var BG_BRIGHT_MAGENTA = '\x1b[105m';
var BG_BRIGHT_CYAN = '\x1b[106m';
var BG_BRIGHT_WHITE = '\x1b[107m';
// 40-47 set background to standard colors
public var BG_BLACK = '\x1b[40m';
public var BG_RED = '\x1b[41m';
public var BG_GREEN = '\x1b[42m';
public var BG_YELLOW = '\x1b[43m';
public var BG_BLUE = '\x1b[44m';
public var BG_MAGENTA = '\x1b[45m';
public var BG_CYAN = '\x1b[46m';
public var BG_WHITE = '\x1b[47m';
// 48 has two modes
// [48;2;#m uses one of 256 colors
public var BG_ORANGE = '\x1b[48;5;208m';
// [48;2;RR;GG;BBm uses 24-bit color RGB
public var BG_NOTE_LEFT = '\x1b[48;2;255;34;170m';
public var BG_NOTE_DOWN = '\x1b[48;2;0;238;255m';
public var BG_NOTE_UP = '\x1b[48;2;0;204;0m';
public var BG_NOTE_RIGHT = '\x1b[48;2;204;17;17m';
// 90-97 sets a bright foreground color (non-standard)
public var BRIGHT_BLACK = '\x1b[90m';
public var BRIGHT_RED = '\x1b[91m';
public var BRIGHT_GREEN = '\x1b[92m';
public var BRIGHT_YELLOW = '\x1b[93m';
public var BRIGHT_BLUE = '\x1b[94m';
public var BRIGHT_MAGENTA = '\x1b[95m';
public var BRIGHT_CYAN = '\x1b[96m';
public var BRIGHT_WHITE = '\x1b[97m';
// 100-107 sets a bright background color (non-standard)
public var BG_BRIGHT_BLACK = '\x1b[100m';
public var BG_BRIGHT_RED = '\x1b[101m';
public var BG_BRIGHT_GREEN = '\x1b[102m';
public var BG_BRIGHT_YELLOW = '\x1b[103m';
public var BG_BRIGHT_BLUE = '\x1b[104m';
public var BG_BRIGHT_MAGENTA = '\x1b[105m';
public var BG_BRIGHT_CYAN = '\x1b[106m';
public var BG_BRIGHT_WHITE = '\x1b[107m';
}
/**
@@ -89,173 +116,391 @@ class AnsiUtil
#end
}
// Common combos
/**
* Makes the string display as ERROR text.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function error(str:String):String
return AnsiUtil.bold(AnsiUtil.bg_red(str));
/**
* Makes the string display as WARNING text.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function warning(str:String):String
return AnsiUtil.bold(AnsiUtil.bg_yellow(str));
/**
* Makes the string display as INFO text.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function info(str:String):String
return AnsiUtil.bold(AnsiUtil.bg_blue(str));
// Text styles
/** Makes the string bold. */
/**
* Makes the string bold.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bold(str:String):String
return apply(str, AnsiCode.BOLD);
/** Makes the string dim/faint. */
/**
* Makes the string dim/faint.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function dim(str:String):String
return apply(str, AnsiCode.DIM);
/** Underlines the string. */
/**
* Underlines the string.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function underline(str:String):String
return apply(str, AnsiCode.UNDERLINE);
/** Makes the string blink. (Not widely supported on modern terminals.) */
/**
* Makes the string blink. (Not widely supported on modern terminals.)
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function blink(str:String):String
return apply(str, AnsiCode.BLINK);
/** Inverts the foreground and background colors of the string. */
/**
* Inverts the foreground and background colors of the string.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function inverse(str:String):String
return apply(str, AnsiCode.INVERSE);
/** Hides the string (renders it invisible in many terminals). */
/**
* Hides the string (renders it invisible in many terminals).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function hidden(str:String):String
return apply(str, AnsiCode.HIDDEN);
/** Applies a strikethrough effect to the string. */
/**
* Applies a strikethrough effect to the string.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function strikethrough(str:String):String
return apply(str, AnsiCode.STRIKETHROUGH);
// Foreground colors
/** Colors the string black. */
/**
* Colors the string black.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function black(str:String):String
return apply(str, AnsiCode.BLACK);
/** Colors the string red. */
/**
* Colors the string red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function red(str:String):String
return apply(str, AnsiCode.RED);
/** Colors the string green. */
/**
* Colors the string green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function green(str:String):String
return apply(str, AnsiCode.GREEN);
/** Colors the string yellow. */
/**
* Colors the string yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function yellow(str:String):String
return apply(str, AnsiCode.YELLOW);
/** Colors the string blue. */
/**
* Colors the string blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function blue(str:String):String
return apply(str, AnsiCode.BLUE);
/** Colors the string magenta. */
/**
* Colors the string magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function magenta(str:String):String
return apply(str, AnsiCode.MAGENTA);
/** Colors the string cyan. */
/**
* Colors the string cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function cyan(str:String):String
return apply(str, AnsiCode.CYAN);
/** Colors the string white. */
/**
* Colors the string white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function white(str:String):String
return apply(str, AnsiCode.WHITE);
// Background colors
/** Sets the background color to black. */
/**
* Sets the background color to black.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_black(str:String):String
return apply(str, AnsiCode.BG_BLACK);
/** Sets the background color to red. */
/**
* Sets the background color to red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_red(str:String):String
return apply(str, AnsiCode.BG_RED);
/** Sets the background color to green. */
/**
* Sets the background color to green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_green(str:String):String
return apply(str, AnsiCode.BG_GREEN);
/** Sets the background color to yellow. */
/**
* Sets the background color to yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_yellow(str:String):String
return apply(str, AnsiCode.BG_YELLOW);
/** Sets the background color to blue. */
/**
* Sets the background color to blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_blue(str:String):String
return apply(str, AnsiCode.BG_BLUE);
/** Sets the background color to magenta. */
/**
* Sets the background color to magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_magenta(str:String):String
return apply(str, AnsiCode.BG_MAGENTA);
/** Sets the background color to cyan. */
/**
* Sets the background color to cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_cyan(str:String):String
return apply(str, AnsiCode.BG_CYAN);
/** Sets the background color to white. */
/**
* Sets the background color to white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_white(str:String):String
return apply(str, AnsiCode.BG_WHITE);
/** Sets the background color to orange (256-color mode). */
/**
* Sets the background color to orange (256-color mode).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_orange(str:String):String
return apply(str, AnsiCode.BG_ORANGE);
/**
* Sets the background color to the color of a Left note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_left(str:String):String
return apply(str, AnsiCode.BG_NOTE_LEFT);
/**
* Sets the background color to the color of a Down note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_down(str:String):String
return apply(str, AnsiCode.BG_NOTE_DOWN);
/**
* Sets the background color to the color of a Up note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_up(str:String):String
return apply(str, AnsiCode.BG_NOTE_UP);
/**
* Sets the background color to the color of a Right note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_right(str:String):String
return apply(str, AnsiCode.BG_NOTE_RIGHT);
// Bright foreground colors
/** Colors the string bright black (gray). */
/**
* Colors the string bright black (gray).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_black(str:String):String
return apply(str, AnsiCode.BRIGHT_BLACK);
/** Colors the string bright red. */
/**
* Colors the string bright red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_red(str:String):String
return apply(str, AnsiCode.BRIGHT_RED);
/** Colors the string bright green. */
/**
* Colors the string bright green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_green(str:String):String
return apply(str, AnsiCode.BRIGHT_GREEN);
/** Colors the string bright yellow. */
/**
* Colors the string bright yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_yellow(str:String):String
return apply(str, AnsiCode.BRIGHT_YELLOW);
/** Colors the string bright blue. */
/**
* Colors the string bright blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_blue(str:String):String
return apply(str, AnsiCode.BRIGHT_BLUE);
/** Colors the string bright magenta. */
/**
* Colors the string bright magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_magenta(str:String):String
return apply(str, AnsiCode.BRIGHT_MAGENTA);
/** Colors the string bright cyan. */
/**
* Colors the string bright cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_cyan(str:String):String
return apply(str, AnsiCode.BRIGHT_CYAN);
/** Colors the string bright white. */
/**
* Colors the string bright white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_white(str:String):String
return apply(str, AnsiCode.BRIGHT_WHITE);
// Bright backgrounds
/** Sets the background color to bright black (gray). */
/**
* Sets the background color to bright black (gray).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_black(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_BLACK);
/** Sets the background color to bright red. */
/**
* Sets the background color to bright red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_red(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_RED);
/** Sets the background color to bright green. */
/**
* Sets the background color to bright green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_green(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_GREEN);
/** Sets the background color to bright yellow. */
/**
* Sets the background color to bright yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_yellow(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_YELLOW);
/** Sets the background color to bright blue. */
/**
* Sets the background color to bright blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_blue(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_BLUE);
/** Sets the background color to bright magenta. */
/**
* Sets the background color to bright magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_magenta(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_MAGENTA);
/** Sets the background color to bright cyan. */
/**
* Sets the background color to bright cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_cyan(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_CYAN);
/** Sets the background color to bright white. */
/**
* Sets the background color to bright white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_white(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_WHITE);
@@ -280,6 +525,7 @@ class AnsiUtil
*
* @return `true` if ANSI codes are supported, `false` otherwise.
*/
@SuppressWarnings(["checkstyle:SimplifyBooleanExpression"])
public static function isColorCodesSupported():Bool
{
if (codesSupported == null)
@@ -289,7 +535,10 @@ class AnsiUtil
{
final term:Null<String> = getEnvSafe('TERM');
if (term == 'dumb') codesSupported = false;
if (term == 'dumb')
{
codesSupported = false;
}
else
{
if (codesSupported != true && term != null)
+1 -1
View File
@@ -21,7 +21,7 @@ class CLIUtil
gameDir = Path.addTrailingSlash(extension.androidtools.content.Context.getExternalFilesDir());
#elseif ios
// Why? Because for some reason lime.system.System.documentsDirectory is returning a directory that's different and we're unable to read or write from, so it's disabled and no solution is found...
trace(' WARNING '.bold().bg_yellow() + ' : Reseting the Current Working Directory is unavailable on iOS targets');
trace(' WARNING '.warning() + ' : Reseting the Current Working Directory is unavailable on iOS targets');
gameDir = cwd;
#elseif mac
gameDir = Path.addTrailingSlash(Path.join([Path.directory(Sys.programPath()), '../Resources/']));
+1 -1
View File
@@ -15,7 +15,7 @@ class FramesJSFLParser
var text:String = Assets.getText(path);
if (text == null)
{
trace(' ERROR '.bg_red().bold() + ' Could not load FramesJSFL data asset from path $path');
trace(' ERROR '.error() + ' Could not load FramesJSFL data asset from path $path');
return null;
}
+3 -3
View File
@@ -41,7 +41,7 @@ class VersionUtil
if (thx.Types.isAnonymousObject(versionData.version))
{
// This is bad! versionData.version should be an array!
trace('[SAVE] Version data repair required! (got ${versionData.version})');
trace(' SAVE '.bold().bg_note_down() + 'Version data repair required! (got ${versionData.version})');
// Turn the objects back into arrays.
// I'd use DynamicsT.values but IDK if it maintains order
versionData.version = [versionData.version[0], versionData.version[1], versionData.version[2]];
@@ -57,12 +57,12 @@ class VersionUtil
versionData.pre = preDataFixed;
var fixedVersion:thx.semver.Version = versionData;
trace('[SAVE] Fixed version: ${fixedVersion}');
trace(' SAVE '.bold().bg_note_down() + 'Resolved version: ${fixedVersion}');
return fixedVersion;
}
else
{
trace('[SAVE] Version data repair not required (got ${version})');
trace(' SAVE '.bold().bg_note_down() + 'Save data migration/repair not required (got ${version})');
// No need for repair.
return version;
}
+1 -2
View File
@@ -35,7 +35,6 @@ class ConsoleMacro
public static function registerClass(className:String):Void
{
classes.push(className);
trace("Registered console class: " + className);
}
#if macro
@@ -59,7 +58,7 @@ class ConsoleMacro
};
fields.push(initField);
Sys.println(' INFO '.bold().bg_blue() + ' Generated console registration for: $cl');
Sys.println(' INFO '.info() + ' Generated console registration for: $cl');
return fields;
}
#end
+2 -2
View File
@@ -19,7 +19,7 @@ class GitCommit
if (process.exitCode() != 0)
{
var message = process.stderr.readAll().toString();
haxe.macro.Context.info(' WARNING '.bold().bg_yellow() + ' Could not determine current git commit; is this a proper Git repository?', pos);
haxe.macro.Context.info(' WARNING '.warning() + ' Could not determine current git commit; is this a proper Git repository?', pos);
}
// read the output of the process
@@ -51,7 +51,7 @@ class GitCommit
if (branchProcess.exitCode() != 0)
{
var message = branchProcess.stderr.readAll().toString();
haxe.macro.Context.info(' WARNING '.bold().bg_yellow() + ' Could not determine current git commit; is this a proper Git repository?', pos);
haxe.macro.Context.info(' WARNING '.warning() + ' Could not determine current git commit; is this a proper Git repository?', pos);
}
var branchName:String = branchProcess.stdout.readLine();
@@ -521,7 +521,7 @@ class ScreenshotPlugin extends FlxBasic
if (pngData == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to encode PNG data');
trace(' WARNING '.warning() + ' Failed to encode PNG data');
previousScreenshotName = null;
// Just in case
unsavedScreenshotBuffer.shift();
@@ -545,7 +545,7 @@ class ScreenshotPlugin extends FlxBasic
if (pngData == null)
{
trace(' WARNING '.bold().bg_yellow() + ' Failed to encode PNG data');
trace(' WARNING '.warning() + ' Failed to encode PNG data');
previousScreenshotName = null;
return;
}
+333 -84
View File
@@ -2,56 +2,83 @@ package tools;
/**
* Enum abstract representing ANSI codes for text colors, background colors, and text styles.
* TODO: Add more colors?
*/
// TODO: Add more colors maybe?
@SuppressWarnings([
"checkstyle:FieldDocComment",
"checkstyle:MemberName",
"checkstyle:TypeDocComment"
])
enum abstract AnsiCode(String) from String to String
{
var RESET = '\x1b[0m';
var BOLD = '\x1b[1m';
var DIM = '\x1b[2m';
var UNDERLINE = '\x1b[4m';
var BLINK = '\x1b[5m';
var INVERSE = '\x1b[7m';
var HIDDEN = '\x1b[8m';
var STRIKETHROUGH = '\x1b[9m';
public var RESET = '\x1b[0m';
public var BOLD = '\x1b[1m';
public var DIM = '\x1b[2m';
public var UNDERLINE = '\x1b[4m';
public var BLINK = '\x1b[5m';
public var INVERSE = '\x1b[7m';
public var HIDDEN = '\x1b[8m';
public var STRIKETHROUGH = '\x1b[9m';
var BLACK = '\x1b[30m';
var RED = '\x1b[31m';
var GREEN = '\x1b[32m';
var YELLOW = '\x1b[33m';
var BLUE = '\x1b[34m';
var MAGENTA = '\x1b[35m';
var CYAN = '\x1b[36m';
var WHITE = '\x1b[37m';
// 30-37 set foreground to standard colors
public var BLACK = '\x1b[30m';
public var RED = '\x1b[31m';
public var GREEN = '\x1b[32m';
public var YELLOW = '\x1b[33m';
public var BLUE = '\x1b[34m';
public var MAGENTA = '\x1b[35m';
public var CYAN = '\x1b[36m';
public var WHITE = '\x1b[37m';
var BG_BLACK = '\x1b[40m';
var BG_RED = '\x1b[41m';
var BG_GREEN = '\x1b[42m';
var BG_YELLOW = '\x1b[43m';
var BG_BLUE = '\x1b[44m';
var BG_MAGENTA = '\x1b[45m';
var BG_CYAN = '\x1b[46m';
var BG_WHITE = '\x1b[47m';
var BG_ORANGE = '\x1b[48;5;208m';
// 38 has two modes
// [38;2;#m uses one of 256 colors
public var ORANGE = '\x1b[38;5;208m';
var BRIGHT_BLACK = '\x1b[90m';
var BRIGHT_RED = '\x1b[91m';
var BRIGHT_GREEN = '\x1b[92m';
var BRIGHT_YELLOW = '\x1b[93m';
var BRIGHT_BLUE = '\x1b[94m';
var BRIGHT_MAGENTA = '\x1b[95m';
var BRIGHT_CYAN = '\x1b[96m';
var BRIGHT_WHITE = '\x1b[97m';
// [38;2;RR;GG;BBm uses 24-bit color RGB
public var NOTE_LEFT = '\x1b[38;2;255;34;170m';
public var NOTE_DOWN = '\x1b[38;2;0;238;255m';
public var NOTE_UP = '\x1b[38;2;0;204;0m';
public var NOTE_RIGHT = '\x1b[38;2;204;17;17m';
var BG_BRIGHT_BLACK = '\x1b[100m';
var BG_BRIGHT_RED = '\x1b[101m';
var BG_BRIGHT_GREEN = '\x1b[102m';
var BG_BRIGHT_YELLOW = '\x1b[103m';
var BG_BRIGHT_BLUE = '\x1b[104m';
var BG_BRIGHT_MAGENTA = '\x1b[105m';
var BG_BRIGHT_CYAN = '\x1b[106m';
var BG_BRIGHT_WHITE = '\x1b[107m';
// 40-47 set background to standard colors
public var BG_BLACK = '\x1b[40m';
public var BG_RED = '\x1b[41m';
public var BG_GREEN = '\x1b[42m';
public var BG_YELLOW = '\x1b[43m';
public var BG_BLUE = '\x1b[44m';
public var BG_MAGENTA = '\x1b[45m';
public var BG_CYAN = '\x1b[46m';
public var BG_WHITE = '\x1b[47m';
// 48 has two modes
// [48;2;#m uses one of 256 colors
public var BG_ORANGE = '\x1b[48;5;208m';
// [48;2;RR;GG;BBm uses 24-bit color RGB
public var BG_NOTE_LEFT = '\x1b[48;2;255;34;170m';
public var BG_NOTE_DOWN = '\x1b[48;2;0;238;255m';
public var BG_NOTE_UP = '\x1b[48;2;0;204;0m';
public var BG_NOTE_RIGHT = '\x1b[48;2;204;17;17m';
// 90-97 sets a bright foreground color (non-standard)
public var BRIGHT_BLACK = '\x1b[90m';
public var BRIGHT_RED = '\x1b[91m';
public var BRIGHT_GREEN = '\x1b[92m';
public var BRIGHT_YELLOW = '\x1b[93m';
public var BRIGHT_BLUE = '\x1b[94m';
public var BRIGHT_MAGENTA = '\x1b[95m';
public var BRIGHT_CYAN = '\x1b[96m';
public var BRIGHT_WHITE = '\x1b[97m';
// 100-107 sets a bright background color (non-standard)
public var BG_BRIGHT_BLACK = '\x1b[100m';
public var BG_BRIGHT_RED = '\x1b[101m';
public var BG_BRIGHT_GREEN = '\x1b[102m';
public var BG_BRIGHT_YELLOW = '\x1b[103m';
public var BG_BRIGHT_BLUE = '\x1b[104m';
public var BG_BRIGHT_MAGENTA = '\x1b[105m';
public var BG_BRIGHT_CYAN = '\x1b[106m';
public var BG_BRIGHT_WHITE = '\x1b[107m';
}
/**
@@ -89,173 +116,391 @@ class AnsiUtil
#end
}
// Common combos
/**
* Makes the string display as ERROR text.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function error(str:String):String
return AnsiUtil.bold(AnsiUtil.bg_red(str));
/**
* Makes the string display as WARNING text.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function warning(str:String):String
return AnsiUtil.bold(AnsiUtil.bg_yellow(str));
/**
* Makes the string display as INFO text.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function info(str:String):String
return AnsiUtil.bold(AnsiUtil.bg_blue(str));
// Text styles
/** Makes the string bold. */
/**
* Makes the string bold.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bold(str:String):String
return apply(str, AnsiCode.BOLD);
/** Makes the string dim/faint. */
/**
* Makes the string dim/faint.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function dim(str:String):String
return apply(str, AnsiCode.DIM);
/** Underlines the string. */
/**
* Underlines the string.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function underline(str:String):String
return apply(str, AnsiCode.UNDERLINE);
/** Makes the string blink. (Not widely supported on modern terminals.) */
/**
* Makes the string blink. (Not widely supported on modern terminals.)
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function blink(str:String):String
return apply(str, AnsiCode.BLINK);
/** Inverts the foreground and background colors of the string. */
/**
* Inverts the foreground and background colors of the string.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function inverse(str:String):String
return apply(str, AnsiCode.INVERSE);
/** Hides the string (renders it invisible in many terminals). */
/**
* Hides the string (renders it invisible in many terminals).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function hidden(str:String):String
return apply(str, AnsiCode.HIDDEN);
/** Applies a strikethrough effect to the string. */
/**
* Applies a strikethrough effect to the string.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function strikethrough(str:String):String
return apply(str, AnsiCode.STRIKETHROUGH);
// Foreground colors
/** Colors the string black. */
/**
* Colors the string black.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function black(str:String):String
return apply(str, AnsiCode.BLACK);
/** Colors the string red. */
/**
* Colors the string red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function red(str:String):String
return apply(str, AnsiCode.RED);
/** Colors the string green. */
/**
* Colors the string green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function green(str:String):String
return apply(str, AnsiCode.GREEN);
/** Colors the string yellow. */
/**
* Colors the string yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function yellow(str:String):String
return apply(str, AnsiCode.YELLOW);
/** Colors the string blue. */
/**
* Colors the string blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function blue(str:String):String
return apply(str, AnsiCode.BLUE);
/** Colors the string magenta. */
/**
* Colors the string magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function magenta(str:String):String
return apply(str, AnsiCode.MAGENTA);
/** Colors the string cyan. */
/**
* Colors the string cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function cyan(str:String):String
return apply(str, AnsiCode.CYAN);
/** Colors the string white. */
/**
* Colors the string white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function white(str:String):String
return apply(str, AnsiCode.WHITE);
// Background colors
/** Sets the background color to black. */
/**
* Sets the background color to black.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_black(str:String):String
return apply(str, AnsiCode.BG_BLACK);
/** Sets the background color to red. */
/**
* Sets the background color to red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_red(str:String):String
return apply(str, AnsiCode.BG_RED);
/** Sets the background color to green. */
/**
* Sets the background color to green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_green(str:String):String
return apply(str, AnsiCode.BG_GREEN);
/** Sets the background color to yellow. */
/**
* Sets the background color to yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_yellow(str:String):String
return apply(str, AnsiCode.BG_YELLOW);
/** Sets the background color to blue. */
/**
* Sets the background color to blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_blue(str:String):String
return apply(str, AnsiCode.BG_BLUE);
/** Sets the background color to magenta. */
/**
* Sets the background color to magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_magenta(str:String):String
return apply(str, AnsiCode.BG_MAGENTA);
/** Sets the background color to cyan. */
/**
* Sets the background color to cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_cyan(str:String):String
return apply(str, AnsiCode.BG_CYAN);
/** Sets the background color to white. */
/**
* Sets the background color to white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_white(str:String):String
return apply(str, AnsiCode.BG_WHITE);
/** Sets the background color to orange (256-color mode). */
/**
* Sets the background color to orange (256-color mode).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_orange(str:String):String
return apply(str, AnsiCode.BG_ORANGE);
/**
* Sets the background color to the color of a Left note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_left(str:String):String
return apply(str, AnsiCode.BG_NOTE_LEFT);
/**
* Sets the background color to the color of a Down note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_down(str:String):String
return apply(str, AnsiCode.BG_NOTE_DOWN);
/**
* Sets the background color to the color of a Up note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_up(str:String):String
return apply(str, AnsiCode.BG_NOTE_UP);
/**
* Sets the background color to the color of a Right note.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_note_right(str:String):String
return apply(str, AnsiCode.BG_NOTE_RIGHT);
// Bright foreground colors
/** Colors the string bright black (gray). */
/**
* Colors the string bright black (gray).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_black(str:String):String
return apply(str, AnsiCode.BRIGHT_BLACK);
/** Colors the string bright red. */
/**
* Colors the string bright red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_red(str:String):String
return apply(str, AnsiCode.BRIGHT_RED);
/** Colors the string bright green. */
/**
* Colors the string bright green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_green(str:String):String
return apply(str, AnsiCode.BRIGHT_GREEN);
/** Colors the string bright yellow. */
/**
* Colors the string bright yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_yellow(str:String):String
return apply(str, AnsiCode.BRIGHT_YELLOW);
/** Colors the string bright blue. */
/**
* Colors the string bright blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_blue(str:String):String
return apply(str, AnsiCode.BRIGHT_BLUE);
/** Colors the string bright magenta. */
/**
* Colors the string bright magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_magenta(str:String):String
return apply(str, AnsiCode.BRIGHT_MAGENTA);
/** Colors the string bright cyan. */
/**
* Colors the string bright cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_cyan(str:String):String
return apply(str, AnsiCode.BRIGHT_CYAN);
/** Colors the string bright white. */
/**
* Colors the string bright white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bright_white(str:String):String
return apply(str, AnsiCode.BRIGHT_WHITE);
// Bright backgrounds
/** Sets the background color to bright black (gray). */
/**
* Sets the background color to bright black (gray).
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_black(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_BLACK);
/** Sets the background color to bright red. */
/**
* Sets the background color to bright red.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_red(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_RED);
/** Sets the background color to bright green. */
/**
* Sets the background color to bright green.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_green(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_GREEN);
/** Sets the background color to bright yellow. */
/**
* Sets the background color to bright yellow.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_yellow(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_YELLOW);
/** Sets the background color to bright blue. */
/**
* Sets the background color to bright blue.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_blue(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_BLUE);
/** Sets the background color to bright magenta. */
/**
* Sets the background color to bright magenta.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_magenta(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_MAGENTA);
/** Sets the background color to bright cyan. */
/**
* Sets the background color to bright cyan.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_cyan(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_CYAN);
/** Sets the background color to bright white. */
/**
* Sets the background color to bright white.
* @param str The input string to format.
* @return The formatted string.
*/
public static inline function bg_bright_white(str:String):String
return apply(str, AnsiCode.BG_BRIGHT_WHITE);
@@ -280,6 +525,7 @@ class AnsiUtil
*
* @return `true` if ANSI codes are supported, `false` otherwise.
*/
@SuppressWarnings(["checkstyle:SimplifyBooleanExpression"])
public static function isColorCodesSupported():Bool
{
if (codesSupported == null)
@@ -289,7 +535,10 @@ class AnsiUtil
{
final term:Null<String> = getEnvSafe('TERM');
if (term == 'dumb') codesSupported = false;
if (term == 'dumb')
{
codesSupported = false;
}
else
{
if (codesSupported != true && term != null)