Skip to content

Commit

Permalink
[ QOL Enhancement ] SOOO YEAH...
Browse files Browse the repository at this point in the history
> Added scroll wheel and middle click support to most menus.
  • Loading branch information
Hackx2 committed Jan 7, 2025
1 parent 2ef29e4 commit 5d4ff5e
Show file tree
Hide file tree
Showing 37 changed files with 401 additions and 379 deletions.
15 changes: 15 additions & 0 deletions source/Constants.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import funkin.backend.utils.Paths;

class Constants {
public static inline final SOUND_EXT:String = #if web "mp3" #else "ogg" #end;
public static inline final VIDEO_EXT:String = "mp4";

public static inline final DEFAULT_CHARACTER:String = 'bf'; // if the character is missing.

public static var DEFAULT_FONT(get, null):String = null;
@:noCompletion private inline static function get_DEFAULT_FONT():String {
if (DEFAULT_FONT == null)
DEFAULT_FONT = Paths.font("vcr.ttf");
return DEFAULT_FONT;
}
}
14 changes: 8 additions & 6 deletions source/funkin/backend/funkinLua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ class FunkinLua {
}

// Default character data
set('defaultBoyfriendX', game.defaultCharacterPositions.get("BF").x);
set('defaultBoyfriendY', game.defaultCharacterPositions.get("BF").y);
set('defaultOpponentX', game.defaultCharacterPositions.get("DAD").x);
set('defaultOpponentY', game.defaultCharacterPositions.get("DAD").y);
set('defaultGirlfriendX', game.defaultCharacterPositions.get("GF").x);
set('defaultGirlfriendY', game.defaultCharacterPositions.get("GF").y);
@:privateAccess{
set('defaultBoyfriendX', game.defaultCharacterPositions.get("BF").x);
set('defaultBoyfriendY', game.defaultCharacterPositions.get("BF").y);
set('defaultOpponentX', game.defaultCharacterPositions.get("DAD").x);
set('defaultOpponentY', game.defaultCharacterPositions.get("DAD").y);
set('defaultGirlfriendX', game.defaultCharacterPositions.get("GF").x);
set('defaultGirlfriendY', game.defaultCharacterPositions.get("GF").y);
}

set('boyfriendName', PlayState.SONG.player1);
set('dadName', PlayState.SONG.player2);
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/backend/funkinLua/functions/TextFunctions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TextFunctions

LuaUtils.destroyObject(tag);
var leText:FlxText = new FlxText(x, y, width, text, 16);
leText.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
leText.setFormat(Constants.DEFAULT_FONT, 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
if(PlayState.instance != null) leText.cameras = [PlayState.instance.camHUD];
leText.scrollFactor.set();
leText.borderSize = 2;
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/backend/funkinLua/luaStuff/ModchartText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ModchartText extends flixel.text.FlxText
public function new(x:Float, y:Float, text:String, width:Float)
{
super(x, y, width, text, 16);
setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
setFormat(Constants.DEFAULT_FONT, 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
cameras = [PlayState.instance.camHUD];
scrollFactor.set();
borderSize = 2;
Expand Down
211 changes: 100 additions & 111 deletions source/funkin/backend/utils/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@ import flash.media.Sound;
@:access(openfl.display.BitmapData)
class Paths
{
inline public static var SOUND_EXT = #if web "mp3" #else "ogg" #end;
inline public static var VIDEO_EXT = "mp4";

public static function excludeAsset(key:String)
{
if (!dumpExclusions.contains(key))
dumpExclusions.push(key);
}

public static var dumpExclusions:Array<String> = [
'assets/music/freakyMenu.$SOUND_EXT',
'assets/shared/music/breakfast.$SOUND_EXT',
'assets/shared/music/tea-time.$SOUND_EXT',
'assets/music/freakyMenu.${Constants.SOUND_EXT}',
'assets/shared/music/breakfast.${Constants.SOUND_EXT}',
'assets/shared/music/tea-time.${Constants.SOUND_EXT}',
];

/// haya I love you for the base cache dump I took to the max
Expand Down Expand Up @@ -106,29 +103,31 @@ class Paths
}

public static function getPath(file:String, ?type:AssetType = TEXT, ?parentfolder:String, ?modsAllowed:Bool = true):String
{
#if MODS_ALLOWED
if (modsAllowed)
{
#if MODS_ALLOWED
if(modsAllowed)
{
var customFile:String = file;
if (parentfolder != null) customFile = '$parentfolder/$file';

var modded:String = modFolders(customFile);
if(FileSystem.exists(modded)) return modded;
}
#end

var customFile:String = file;
if (parentfolder != null)
return getFolderPath(file, parentfolder);

if (currentLevel != null && currentLevel != 'shared')
{
var levelPath = getFolderPath(file, currentLevel);
if (OpenFlAssets.exists(levelPath, type))
return levelPath;
}
return getSharedPath(file);
customFile = '$parentfolder/$file';

var modded:String = modFolders(customFile);
if (FileSystem.exists(modded))
return modded;
}
#end

if (parentfolder != null)
return getFolderPath(file, parentfolder);

if (currentLevel != null && currentLevel != 'shared')
{
var levelPath = getFolderPath(file, currentLevel);
if (OpenFlAssets.exists(levelPath, type))
return levelPath;
}
return getSharedPath(file);
}

static public function getLibraryPath(file:String, library = "shared")
{
Expand Down Expand Up @@ -195,7 +194,7 @@ class Paths
return file;
}
#end
return 'assets/videos/$key.$VIDEO_EXT';
return 'assets/videos/$key.$Constants.VIDEO_EXT';
}

inline static public function soundRandom(key:String, min:Int, max:Int, ?modsAllowed:Bool = true)
Expand All @@ -218,12 +217,14 @@ class Paths
// trace('songKey test: $songKey');
return returnSound(songKey, 'songs', modsAllowed, false);
}

public static var currentTrackedAssets:Map<String, FlxGraphic> = [];

static public function image(key:String, ?parentFolder:String = null, ?allowGPU:Bool = true):FlxGraphic
{
key = 'images/$key';
if(key.lastIndexOf('.') < 0) key += '.png';
if (key.lastIndexOf('.') < 0)
key += '.png';

var bitmap:BitmapData = null;
if (currentTrackedAssets.exists(key))
Expand All @@ -239,8 +240,7 @@ class Paths
if (bitmap == null)
{
var file:String = getPath(key, IMAGE, parentFolder, true);
#if MODS_ALLOWED
if (FileSystem.exists(file))
#if MODS_ALLOWED if (FileSystem.exists(file))
bitmap = BitmapData.fromFile(file);
else #end if (OpenFlAssets.exists(file, IMAGE))
bitmap = OpenFlAssets.getBitmapData(file);
Expand Down Expand Up @@ -277,14 +277,14 @@ class Paths
}

inline static public function getTextFromFile(key:String, ?ignoreMods:Bool = false):String
{
var path:String = getPath(key, TEXT, true);
#if sys
return (FileSystem.exists(path)) ? File.getContent(path) : null;
#else
return (OpenFlAssets.exists(path, TEXT)) ? Assets.getText(path) : null;
#end
}
{
var path:String = getPath(key, TEXT, true);
#if sys
return (FileSystem.exists(path)) ? File.getContent(path) : null;
#else
return (OpenFlAssets.exists(path, TEXT)) ? Assets.getText(path) : null;
#end
}

inline static public function font(key:String)
{
Expand Down Expand Up @@ -344,49 +344,52 @@ class Paths
}

inline static public function getSparrowAtlas(key:String, ?parentFolder:String = null, ?allowGPU:Bool = true):FlxAtlasFrames
{
var imageLoaded:FlxGraphic = image(key, parentFolder, allowGPU);
#if MODS_ALLOWED
var xmlExists:Bool = false;

var xml:String = modsXml(key);
if(FileSystem.exists(xml)) xmlExists = true;

return FlxAtlasFrames.fromSparrow(imageLoaded, (xmlExists ? File.getContent(xml) : getPath('images/$key.xml', TEXT, parentFolder)));
#else
return FlxAtlasFrames.fromSparrow(imageLoaded, getPath('images/$key.xml', TEXT, parentFolder));
#end
}

inline static public function getPackerAtlas(key:String, ?parentFolder:String = null, ?allowGPU:Bool = true):FlxAtlasFrames
{
var imageLoaded:FlxGraphic = image(key, parentFolder, allowGPU);
#if MODS_ALLOWED
var txtExists:Bool = false;

var txt:String = modsTxt(key);
if(FileSystem.exists(txt)) txtExists = true;

return FlxAtlasFrames.fromSpriteSheetPacker(imageLoaded, (txtExists ? File.getContent(txt) : getPath('images/$key.txt', TEXT, parentFolder)));
#else
return FlxAtlasFrames.fromSpriteSheetPacker(imageLoaded, getPath('images/$key.txt', TEXT, parentFolder));
#end
}

inline static public function getAsepriteAtlas(key:String, ?parentFolder:String = null, ?allowGPU:Bool = true):FlxAtlasFrames
{
var imageLoaded:FlxGraphic = image(key, parentFolder, allowGPU);
#if MODS_ALLOWED
var jsonExists:Bool = false;

var json:String = modsImagesJson(key);
if(FileSystem.exists(json)) jsonExists = true;

return FlxAtlasFrames.fromTexturePackerJson(imageLoaded, (jsonExists ? File.getContent(json) : getPath('images/$key.json', TEXT, parentFolder)));
#else
return FlxAtlasFrames.fromTexturePackerJson(imageLoaded, getPath('images/$key.json', TEXT, parentFolder));
#end
}
{
var imageLoaded:FlxGraphic = image(key, parentFolder, allowGPU);
#if MODS_ALLOWED
var xmlExists:Bool = false;

var xml:String = modsXml(key);
if (FileSystem.exists(xml))
xmlExists = true;

return FlxAtlasFrames.fromSparrow(imageLoaded, (xmlExists ? File.getContent(xml) : getPath('images/$key.xml', TEXT, parentFolder)));
#else
return FlxAtlasFrames.fromSparrow(imageLoaded, getPath('images/$key.xml', TEXT, parentFolder));
#end
}

inline static public function getPackerAtlas(key:String, ?parentFolder:String = null, ?allowGPU:Bool = true):FlxAtlasFrames
{
var imageLoaded:FlxGraphic = image(key, parentFolder, allowGPU);
#if MODS_ALLOWED
var txtExists:Bool = false;

var txt:String = modsTxt(key);
if (FileSystem.exists(txt))
txtExists = true;

return FlxAtlasFrames.fromSpriteSheetPacker(imageLoaded, (txtExists ? File.getContent(txt) : getPath('images/$key.txt', TEXT, parentFolder)));
#else
return FlxAtlasFrames.fromSpriteSheetPacker(imageLoaded, getPath('images/$key.txt', TEXT, parentFolder));
#end
}

inline static public function getAsepriteAtlas(key:String, ?parentFolder:String = null, ?allowGPU:Bool = true):FlxAtlasFrames
{
var imageLoaded:FlxGraphic = image(key, parentFolder, allowGPU);
#if MODS_ALLOWED
var jsonExists:Bool = false;

var json:String = modsImagesJson(key);
if (FileSystem.exists(json))
jsonExists = true;

return FlxAtlasFrames.fromTexturePackerJson(imageLoaded, (jsonExists ? File.getContent(json) : getPath('images/$key.json', TEXT, parentFolder)));
#else
return FlxAtlasFrames.fromTexturePackerJson(imageLoaded, getPath('images/$key.json', TEXT, parentFolder));
#end
}

inline static public function formatToSongPath(path:String)
{
Expand All @@ -396,72 +399,58 @@ class Paths
var path = invalidChars.split(path.replace(' ', '-')).join("-");
return hideChars.split(path).join("").toLowerCase();
}

public static var currentTrackedSounds:Map<String, Sound> = [];

public static function returnSound(key:String, ?path:String, ?modsAllowed:Bool = true, ?beepOnNull:Bool = true)
{
var file:String = getPath(key + '.$SOUND_EXT', SOUND, path, modsAllowed);
var file:String = getPath(key + '.${Constants.SOUND_EXT}', SOUND, path, modsAllowed);

//trace('precaching sound: $file');
if(!currentTrackedSounds.exists(file))
// trace('precaching sound: $file');
if (!currentTrackedSounds.exists(file))
{
#if sys
if(FileSystem.exists(file))
if (FileSystem.exists(file))
currentTrackedSounds.set(file, Sound.fromFile(file));
#else
if(OpenFlAssets.exists(file, SOUND))
if (OpenFlAssets.exists(file, SOUND))
currentTrackedSounds.set(file, OpenFlAssets.getSound(file));
#end
else if(beepOnNull)
{
trace('SOUND NOT FOUND: $key, PATH: $path');
FlxG.log.error('SOUND NOT FOUND: $key, PATH: $path');
return FlxAssets.getSound('flixel/sounds/beep');
}
else if (beepOnNull)
{
trace('SOUND NOT FOUND: $key, PATH: $path');
FlxG.log.error('SOUND NOT FOUND: $key, PATH: $path');
return FlxAssets.getSound('flixel/sounds/beep');
}
}
localTrackedAssets.push(file);
return currentTrackedSounds.get(file);
}

#if MODS_ALLOWED
inline static public function mods(key:String = '')
{
return 'mods/' + key;
}

inline static public function modsFont(key:String)
{
return modFolders('fonts/' + key);
}

inline static public function modsJson(key:String)
{
return modFolders('data/' + key + '.json');
}

inline static public function modsVideo(key:String)
{
return modFolders('videos/' + key + '.' + VIDEO_EXT);
}
return modFolders('videos/' + key + '.' + Constants.VIDEO_EXT);

inline static public function modsSounds(path:String, key:String)
{
return modFolders(path + '/' + key + '.' + SOUND_EXT);
}
return modFolders(path + '/' + key + '.' + Constants.SOUND_EXT);

inline static public function modsImages(key:String)
{
return modFolders('images/' + key + '.png');
}

inline static public function modsXml(key:String)
{
return modFolders('images/' + key + '.xml');
}

inline static public function modsTxt(key:String)
{
return modFolders('images/' + key + '.txt');
}

inline static public function modsImagesJson(key:String)
return modFolders('images/' + key + '.json');
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/game/editors/CharacterEditorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CharacterEditorState extends MusicBeatState implements FlxUIEventHandler.F
{
this._char = char;
this._goToPlayState = goToPlayState;
if(this._char == null) this._char = Character.DEFAULT_CHARACTER;
if(this._char == null) this._char = Constants.DEFAULT_CHARACTER;

super();
}
Expand Down
Loading

0 comments on commit 5d4ff5e

Please sign in to comment.