Skip to content

Commit

Permalink
Fix a bunch of shit
Browse files Browse the repository at this point in the history
  • Loading branch information
superpowers04 committed Jun 3, 2024
1 parent 491edca commit cc980ad
Show file tree
Hide file tree
Showing 16 changed files with 580 additions and 474 deletions.
14 changes: 7 additions & 7 deletions source/AnimationDebug.hx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class AnimationDebug extends MusicBeatState
var dragdrop = false;
override function beatHit(){
super.beatHit();
if(FlxG.keys.pressed.V && editMode != 2){chara.dance();}
if(FlxG.keys.pressed.V && editMode != 2){chara.dance(curBeat==2);}
if(gf != null) gf.dance();
}
var health:Int = 2;
Expand Down Expand Up @@ -547,7 +547,7 @@ class AnimationDebug extends MusicBeatState
var name = i;
text+='\n"${name}" : { "player${charType + 1}": [${v[0]}, ${v[1]}] }';
}
sys.io.File.saveContent(Sys.getCwd() + "offsets.txt",text);
SELoader.saveContent("offsets.txt",text);
showTempmessage("Saved to output.txt successfully");
FlxG.sound.play(Paths.sound("scrollMenu"), 0.4);

Expand Down Expand Up @@ -632,11 +632,11 @@ class AnimationDebug extends MusicBeatState
charJson.cam_pos = [0,0];

chara.x -= characterX;
if(charType == 2){
chara.y -= 300;
}else{
chara.y -= characterY;
}
// if(charType == 2){
// chara.y -= 300;
// }else{
chara.y -= characterY;
// }
chara.y = -chara.y;

errorStage = 5; // Position
Expand Down
8 changes: 4 additions & 4 deletions source/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1036,10 +1036,10 @@ class CharAnimController extends FlxAnimationController{
* FOR GF DANCING SHIT
*/
public function dance(Forced:Bool = false,beatDouble:Bool = false,useDanced:Bool = true) {
if (amPreview){
playAnim((dance_idle || charType == 2 ? 'danceRight' : 'idle'));
return;
}
// if (amPreview){
// playAnim((dance_idle || charType == 2 ? 'danceRight' : 'idle'));
// return;
// }
if(dance_idle){
if (animation.curAnim != null && !animation.curAnim.name.startsWith("dance") && !animHasFinished) return;
if (useDanced){
Expand Down
4 changes: 2 additions & 2 deletions source/ErrorSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ErrorSubState extends MusicBeatSubstate {
FlxG.state.persistentUpdate = false;
cam = new FlxCamera();
FlxG.cameras.add(cam);
FlxG.cameras.setDefaultDrawTarget(cam,true);
// FlxG.cameras.setDefaultDrawTarget(cam,true);
cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
bg.alpha = 0;
Expand All @@ -83,7 +83,7 @@ class ErrorSubState extends MusicBeatSubstate {
#if android
'Tap the left of the screen to return to the main menu or the right of the screen to reload'
#else
'Press ENTER to return to the main menu, R to reload the state or O to open your options.'
'Press ENTER to return to the main menu,\n R to reload the state or O to open your options.'
#end );
contText.size = 24;
// contText.x -= contText.width * 0.5;
Expand Down
134 changes: 55 additions & 79 deletions source/HSBrTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import sys.io.File;
import flash.display.BitmapData;
import Xml;
import sys.FileSystem;
import SELoader;
#if FLXRUNTIMESHADER
import flixel.addons.display.FlxRuntimeShader;
#end
Expand All @@ -33,11 +34,7 @@ using StringTools;

class HSBrTools {
public var path:String;
public var spriteArray:Map<String,FlxGraphic> = [];
public var bitmapArray:Map<String,BitmapData> = [];
public var xmlArray:Map<String,String> = [];
public var textArray:Map<String,String> = [];
public var soundArray:Map<String,Sound> = [];
public var cache:InternalCache;
// public var dumpGraphics:Bool = false; // If true, All FlxGraphics will be dumped upon creation, trades off bitmap editability for less memory usage


Expand All @@ -48,7 +45,8 @@ class HSBrTools {
var id = "Unspecified script";
var hasSettings:Bool = false;
public function new(_path:String,?id:String = ""){
path = _path;
path = SELoader.getPath(_path);
cache = new InternalCache('SCRIPT-'+id);
if (!path.endsWith('/')) path = path + "/";
if(id != "" && SELoader.exists('mods/scriptOptions/$id.json')){
hasSettings = true;
Expand Down Expand Up @@ -79,15 +77,16 @@ class HSBrTools {
// handleError('${id}: Image "${path}${pngPath}" doesn\'t exist!');
// return new FlxSprite(x, y); // Prevents the script from throwing a null error or something
// }
return new FlxSprite(x, y).loadGraphic(loadGraphic(pngPath));
if(!pngPath.endsWith('.png')) pngPath+=".png";
return cache.loadFlxSprite(x,y,'${path}${pngPath}');
}
public function loadGraphic(pngPath:String):FlxGraphic{
if(!SELoader.exists('${path}${pngPath}')){
handleError('${id}: "${path}${pngPath}" doesn\'t exist!');
return FlxGraphic.fromRectangle(0,0,0); // Prevents the script from throwing a null error or something
}
if(spriteArray[pngPath] == null) cacheGraphic(pngPath);
return spriteArray[pngPath];
// if(!SELoader.exists('${path}${pngPath}')){
// handleError('${id}: "${path}${pngPath}" doesn\'t exist!');
// return FlxGraphic.fromRectangle(0,0,0); // Prevents the script from throwing a null error or something
// }
if(!pngPath.endsWith('.png')) pngPath+=".png";
return cache.loadGraphic('${path}${pngPath}');
}

public function loadSparrowFrames(pngPath:String):FlxAtlasFrames{
Expand All @@ -112,25 +111,10 @@ class HSBrTools {
return spr;
}
public function loadSparrowSprite(x:Int,y:Int,pngPath:String,?anim:String = "",?loop:Bool = false,?fps:Int = 24):FlxSprite{
var spr = new FlxSprite(x, y);
spr.frames= loadSparrowFrames(pngPath);
if (anim != ""){
spr.animation.addByPrefix(anim,anim,fps,loop);
spr.animation.play(anim);
}
return spr;
return loadAtlasSprite(x,y,pngPath,anim,loop,fps);
}
public function reset(){
for(graphic in spriteArray){
try{
graphic.destroy();
}catch(e){}
}
spriteArray.clear();
bitmapArray.clear();
soundArray.clear();
textArray.clear();
xmlArray.clear();
cache.clear();
// spriteArray = [];
// bitmapArray = [];
// xmlArray = [];
Expand All @@ -142,33 +126,30 @@ class HSBrTools {
return SELoader.exists('${path}${textPath}');
}
public function loadText(textPath:String):String{
if(textArray[textPath] == null) textArray[textPath] = SELoader.loadText('${path}${textPath}');
return textArray[textPath];
return cache.loadText('${path}${textPath}');
}
// The above but hits the xml cache instead
public function loadXML(textPath:String):String{
if(xmlArray[textPath] == null) xmlArray[textPath] = SELoader.loadXML('${path}${textPath}');
return xmlArray[textPath];
return SELoader.cleanXML(cache.loadText('${path}${textPath}'));
}
public function loadShader(textPath:String,?glslVersion:Dynamic = 120)#if(FLXRUNTIMESHADER) :Null<FlxRuntimeShader> #end{
#if !FLXRUNTIMESHADER
// #if !FLXRUNTIMESHADER

handleError('Shaders aren\'t supported enabled on this build of the game!');
return null;
#else
if(textArray[textPath + ".vert"] == null && SELoader.exists('${path}${textPath}.vert')) textArray[textPath + ".vert"] = SELoader.loadText('${path}${textPath}.vert');
if(textArray[textPath + ".frag"] == null && SELoader.exists('${path}${textPath}.frag')) textArray[textPath + ".frag"] = SELoader.loadText('${path}${textPath}.frag');
try{
var shader = new FlxRuntimeShader(textArray[textPath + ".vert"],textArray[textPath + ".frag"],Std.string(glslVersion));
// if(init) shader.initialise(); // If the shader uses custom variables, this can prevent loading a broken shader
return shader;

}catch(e){
handleError('${id}: Unable to load shader "${textPath}": ${e.message}');
trace(e.message);
}
return null;
#end
// #else
// if(textArray[textPath + ".vert"] == null && SELoader.exists('${path}${textPath}.vert')) textArray[textPath + ".vert"] = SELoader.loadText('${path}${textPath}.vert');
// if(textArray[textPath + ".frag"] == null && SELoader.exists('${path}${textPath}.frag')) textArray[textPath + ".frag"] = SELoader.loadText('${path}${textPath}.frag');
// try{
// var shader = new FlxRuntimeShader(textArray[textPath + ".vert"],textArray[textPath + ".frag"],Std.string(glslVersion));
// // if(init) shader.initialise(); // If the shader uses custom variables, this can prevent loading a broken shader
// return shader;

// }catch(e){
// handleError('${id}: Unable to load shader "${textPath}": ${e.message}');
// trace(e.message);
// }
// return null;
// #end
}
// public function saveText(textPath:String,text:String):Bool{
// File.saveContent('${path}${textPath}',text);
Expand All @@ -179,9 +160,8 @@ class HSBrTools {


public function loadSound(soundPath:String):FlxSound{
if(soundArray[soundPath] == null) soundArray[soundPath] = SELoader.loadSound('${path}${soundPath}');
@:privateAccess{
return new FlxSound().loadEmbedded(soundArray[soundPath]);
return new FlxSound().loadEmbedded(cache.loadSound('${path}${soundPath}'));
}
}
public function loadFlxSound(soundPath:String) return loadSound(soundPath);
Expand All @@ -194,49 +174,45 @@ class HSBrTools {
}

public function unloadSound(soundPath:String){
soundArray[soundPath] = null;
}
public function unloadText(pngPath:String){
textArray[pngPath] = null;
cache.unloadSound('${path}$soundPath');
}
public function unloadShader(pngPath:String){
textArray[pngPath + ".vert"] = null;
textArray[pngPath + ".frag"] = null;
// textArray[pngPath + ".vert"] = null;
// textArray[pngPath + ".frag"] = null;
}
public function unloadText(pngPath:String){
cache.unloadText('${path}$pngPath');
}
public function unloadXml(pngPath:String){
xmlArray[pngPath] = null;
cache.unloadText('${path}$pngPath');
}
public function unloadSprite(pngPath:String){
spriteArray[pngPath] = null;
cache.unloadText('${path}$pngPath');
}

public function cacheSound(soundPath:String){
if(soundArray[soundPath] == null) {
if(!SELoader.exists('${path}${soundPath}')){
trace('${id} : CacheSound: "${path}${soundPath}" doesn\'t exist!');
return;
}
soundArray[soundPath] = SELoader.loadSound('${path}${soundPath}');
}
cache.cacheSound('${path}${soundPath}');

}
public function cacheGraphic(pngPath:String,?dumpGraphic:Bool = false){ // DOES NOT CHECK IF FILE IS VALID!

if(bitmapArray[pngPath] == null) bitmapArray[pngPath] = SELoader.loadBitmap('${path}${pngPath}');
// if(bitmapArray[pngPath] == null) bitmapArray[pngPath] = SELoader.loadBitmap('${path}${pngPath}');

if(spriteArray[pngPath] == null) spriteArray[pngPath] = FlxGraphic.fromBitmapData(bitmapArray[pngPath]);
if(spriteArray[pngPath] == null) return handleError('${id} : cacheGraphic: Unable to load $pngPath into a FlxGraphic!');
spriteArray[pngPath].destroyOnNoUse = false;
// if(spriteArray[pngPath] == null) spriteArray[pngPath] = FlxGraphic.fromBitmapData(bitmapArray[pngPath]);
// if(cache.cacheGraphic(pngPath) == null) return handleError('${id} : cacheGraphic: Unable to load $pngPath into a FlxGraphic!');
// spriteArray[pngPath].destroyOnNoUse = false;
cache.cacheGraphic('${path}$pngPath');
// if(dumpGraphic || dumpGraphics) spriteArray[pngPath].dump();

}
public function cacheSprite(pngPath:String,?dump:Bool = false){

if(spriteArray[pngPath] == null) {
if(!SELoader.exists('${path}${pngPath}.png')){
handleError('${id} : CacheSprite: "${path}${pngPath}.png" doesn\'t exist!');
return;
}
cacheGraphic('${pngPath}.png',dump);
}
cache.cacheSprite('${path}$pngPath');
// if(spriteArray[pngPath] == null) {
// if(!SELoader.exists('${path}${pngPath}.png')){
// handleError('${id} : CacheSprite: "${path}${pngPath}.png" doesn\'t exist!');
// return;
// }
// cacheGraphic('${pngPath}.png',dump);
// }
}
}
52 changes: 26 additions & 26 deletions source/MusicBeatState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -495,37 +495,37 @@ class DebugOverlay extends FlxTypedGroup<FlxSprite>{
var objectPosBack:FlxSpriteLockScale;
function getTopObject():Dynamic{
var id = parent.members.length - 1;
var controlPressed = FlxG.keys.pressed.CONTROL;
while (id >= 0 && obj == null) {
try{
var _ob:Dynamic = parent.members[id];
if(_ob != null && FlxG.mouse.overlaps(_ob)){
if(!FlxG.keys.pressed.SHIFT && _ob.members != null){
var _id:Int = Std.int(_ob.members.length-1);
var _inob:Dynamic = null;
while (_id >= 0 && obj == null) {
try{
_inob = _ob.members[_id];
_id--;

if(_inob == null) continue;
if(_inob.members != null){
_id = Std.int(_inob.members.length-1);
_ob = _inob;
continue;
}
if(FlxG.mouse.overlaps(_inob)){
obj = cast (_inob,FlxSprite);
break;
}

}catch(e){obj = null;}
}

if(obj != null && !FlxG.keys.pressed.CONTROL) return obj;
}else{
if(FlxG.keys.pressed.SHIFT || _ob.members == null){
obj = cast (_ob,FlxSprite);
if(obj != null && !FlxG.keys.pressed.CONTROL) return obj;
if(obj != null && !controlPressed) return obj;
continue;
}
var _id:Int = Std.int(_ob.members.length-1);
var _inob:Dynamic = null;
while (_id >= 0 && obj == null) {
try{
_inob = _ob.members[_id];
_id--;
if(_inob == null) continue;
if(_inob.members != null){
_id = Std.int(_inob.members.length-1);
_ob = _inob;
continue;
}
if(FlxG.mouse.overlaps(_inob)){
obj = cast (_inob,FlxSprite);
break;
}

}catch(e){obj = null;}
}

if(obj != null && !controlPressed) return obj;
// trace('Funni click on ${obj}');
// break;
}
Expand Down Expand Up @@ -602,7 +602,7 @@ class DebugOverlay extends FlxTypedGroup<FlxSprite>{
updateObjText('CamScrollPos:${Std.int(FlxG.camera.scroll.x * 100) * 0.01},${Std.int(FlxG.camera.scroll.y * 100) * 0.01} Zoom:${Std.int(FlxG.camera.zoom * 100) * 0.01}');
}
}
if(FlxG.justPressed.THREE){
if(FlxG.keys.justPressed.THREE){
trace(objectPosText.text);
}
}
Expand Down
Loading

0 comments on commit cc980ad

Please sign in to comment.