Skip to content

Commit

Permalink
untested but yeah psych 1.0a is coming so
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Mar 30, 2024
1 parent 3147b3b commit 6952de5
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 86 deletions.
7 changes: 7 additions & 0 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import flixel.util.FlxColor;
import lime.app.Application;
import haxe.EnumFlags;
import haxe.Exception;

import backend.ColorBlindness;
import debug.FPSCounter;

#if linux
Expand Down Expand Up @@ -53,6 +55,7 @@ class Main extends Sprite

public static var fpsVar:FPSCounter;
public static var watermark:Sprite;
public static var colorFilter:ColorBlindness;

public static var instance:Main;

Expand Down Expand Up @@ -87,6 +90,10 @@ class Main extends Sprite

if (stage != null) init();
else addEventListener(Event.ADDED_TO_STAGE, init);

#if VIDEOS_ALLOWED
hxvlc.util.Handle.init();
#end
}

private function init(?E:Event):Void {
Expand Down
1 change: 1 addition & 0 deletions source/backend/ClientPrefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import states.StartingState;
public var safeFrames:Float = 10;
public var guitarHeroSustains:Bool = true;
public var discordRPC:Bool = true;
public var colorFilter:String = "NONE";
}

class ClientPrefs {
Expand Down
51 changes: 51 additions & 0 deletions source/backend/ColorBlindness.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package backend;

import backend.ClientPrefs;
import openfl.filters.ColorMatrixFilter;

@:access(flixel.FlxGame)
class ColorBlindness extends ColorMatrixFilter {
public var enabledFilter:Bool = true;

public function new(filterType:String) {
enabledFilter = filterType.toUpperCase() != "NONE";

if (!enabledFilter) return;

var filter:Array<Float> = [];
switch (filterType.toUpperCase()) {
case "DEUTERANOPIA":
filter = [
0.43, 0.72, -.15, 0, 0,
0.34, 0.57, 0.09, 0, 0,
-.02, 0.03, 1, 0, 0,
0, 0, 0, 1, 0,
];
case "PROTANOPIA":
filter = [
0.20, 0.99, -.19, 0, 0,
0.16, 0.79, 0.04, 0, 0,
0.01, -.01, 1, 0, 0,
0, 0, 0, 1, 0,
];
case "TRITANOPIA":
filter = [
0.97, 0.11, -.08, 0, 0,
0.02, 0.82, 0.16, 0, 0,
0.06, 0.88, 0.18, 0, 0,
0, 0, 0, 1, 0,
];
default:
}
super(filter);
}

public static function setColorFilter() {
if (FlxG.game._filters == null) FlxG.game._filters = [];
if (FlxG.game._filters.contains(Main.colorFilter)) FlxG.game._filters.remove(Main.colorFilter);

Main.colorFilter = new ColorBlindness(ClientPrefs.data.colorFilter);
if (ClientPrefs.data.colorFilter != "NONE") FlxG.game._filters.push(Main.colorFilter);
/*else FlxG.game.setFilters([]);*/
}
}
21 changes: 21 additions & 0 deletions source/backend/Song.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ typedef SwagSong =
@:optional var splashSkin:String;
}

//// "what"?
//// a typedef with default values, basically. @crowplexus
@:structInit class ChartNoteData {
public var time: Null<Float> = null;
public var id: Null<Int> = null;
public var type: Null<String> = null;
public var strumLine: Null<Int> = null;
public var isGfNote: Null<Bool> = null;
public var sLen: Null<Float> = null;

public function dispose() {
// will be cleared by the GC later
time = null;
id = null;
type = null;
strumLine = null;
isGfNote = null;
sLen = null;
}
}

class Song
{
public var song:String;
Expand Down
25 changes: 8 additions & 17 deletions source/debug/FPSCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class FPSCounter extends TextField {

if (ClientPrefs.data.engineVersion) {
text += "\n[ALLEYWAY VER] 1.0b / [PE VER]" + MainMenuState.psychEngineVersion;
text += "\n[VS.FOXA VER] 3.0 SE";
text += "\n[VS.FOXA VER] 3.0+";
}

// #if debug
Expand Down Expand Up @@ -143,37 +143,28 @@ class FPSCounter extends TextField {
cacheCount = currentCount;
set_rainbowEnabled(ClientPrefs.data.rainbowFPS);

#if desktop
#if !debug
if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (75);
else y = 3;
#if desktop #if !debug
if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (75); else y = 3;
#else
if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (150);
else y = 3;
#end
#end
if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (150); else y = 3;
#end #end
}

function obtainMemory():Dynamic {
return System.totalMemory;
}
function obtainMemory():Dynamic {return System.totalMemory;}

private function getGLInfo(info:GLInfo):String {
@:privateAccess
var gl:Dynamic = Lib.current.stage.context3D.gl;

switch (info) {
case RENDERER: return Std.string(gl.getParameter(gl.RENDERER));
case SHADING_LANGUAGE_VERSION:
return Std.string(gl.getParameter(gl.SHADING_LANGUAGE_VERSION));
case SHADING_LANGUAGE_VERSION: return Std.string(gl.getParameter(gl.SHADING_LANGUAGE_VERSION));
}
return '';
}

private var hue:Float = 0;
private function doRainbowThing():Void {
textColor = fromHSL({hue = (hue + (FlxG.elapsed * 100)) % 360; hue;}, 1, 0.8);
}
private function doRainbowThing():Void {textColor = fromHSL({hue = (hue + (FlxG.elapsed * 100)) % 360; hue;}, 1, 0.8);}

// function named fromHSL which takes a hue, saturation, and lightness value and returns a color (0xffRRGGBB)
private static inline function fromHSL(h:Float, s:Float, l:Float) {
Expand Down
76 changes: 40 additions & 36 deletions source/objects/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Character extends FlxSprite {
public var cameraPosition:Array<Float> = [0, 0];
public var healthColorArray:Array<Int> = [255, 0, 0]; // i wonder if i can turn this to hex optionally hmmmmm

public var missingCharacter:Bool = false;
public var missingText:FlxText;
public var hasMissAnimations:Bool = false;
public var vocalsFile:String = '';

Expand Down Expand Up @@ -98,8 +100,11 @@ class Character extends FlxSprite {
#end
{
path = Paths.getSharedPath('characters/' + DEFAULT_CHARACTER + '.json'); //If a character couldn't be found, change him to BF just to prevent a crash
color = FlxColor.BLACK;
alpha = 0.6;
/*color = FlxColor.BLACK;
alpha = 0.6;*/
missingCharacter = true;
missingText = new FlxText(0, 0, 300, 'ERROR:\n$curCharacter.json', 16);
missingText.alignment = CENTER;
}

try {
Expand Down Expand Up @@ -390,50 +395,57 @@ class Character extends FlxSprite {
var lastDanceIdle:Bool = danceIdle;
danceIdle = (animOffsets.exists('danceLeft' + idleSuffix) && animOffsets.exists('danceRight' + idleSuffix));

if(settingCharacterUp)
{
danceEveryNumBeats = (danceIdle ? 1 : 2);
}
else if(lastDanceIdle != danceIdle)
{
if(settingCharacterUp) danceEveryNumBeats = (danceIdle ? 1 : 2);
else if(lastDanceIdle != danceIdle) {
var calc:Float = danceEveryNumBeats;
if(danceIdle)
calc /= 2;
else
calc *= 2;
if(danceIdle) calc /= 2;
else calc *= 2;
danceEveryNumBeats = Math.round(Math.max(calc, 1));
}
settingCharacterUp = false;
}
public function addOffset(name:String, x:Float = 0, y:Float = 0)
{
animOffsets[name] = [x, y];
}
public function quickAnimAdd(name:String, anim:String)
{
animation.addByPrefix(name, anim, 24, false);
}
public function addOffset(name:String, x:Float = 0, y:Float = 0) animOffsets[name] = [x, y];
public function quickAnimAdd(name:String, anim:String) animation.addByPrefix(name, anim, 24, false);

// Atlas support
// special thanks ne_eo for the references, you're the goat!!
public var isAnimateAtlas:Bool = false;
#if flxanimate
public var atlas:FlxAnimate;
public override function draw()
{
if(isAnimateAtlas)
{
public override function draw() {
var lastAlpha:Float = alpha;
var lastColor:FlxColor = color;
if (missingCharacter) {
alpha *= 0.6;
color = FlxColor.BLACK;
}

if (isAnimateAtlas) {
copyAtlasValues();
atlas.draw();
if (missingCharacter) {
alpha = lastAlpha;
color = lastColor;

missingText.x = getMidpoint().x - 150;
missingText.y = getMidpoint().y - 10;
missingText.draw();
}
return;
}
super.draw();
if (missingCharacter) {
alpha = lastAlpha;
color = lastColor;
missingText.x = getMidpoint().x - 150;
missingText.y = getMidpoint().y - 10;
missingText.draw();
}
}

public function copyAtlasValues()
{
@:privateAccess
{
@:privateAccess {
atlas.cameras = cameras;
atlas.scrollFactor = scrollFactor;
atlas.scale = scale;
Expand All @@ -453,16 +465,8 @@ class Character extends FlxSprite {
}
}

public override function destroy()
{
super.destroy();
destroyAtlas();
}
public override function destroy() {super.destroy(); destroyAtlas();}

public function destroyAtlas()
{
if (atlas != null)
atlas = FlxDestroyUtil.destroy(atlas);
}
public function destroyAtlas() if (atlas != null) atlas = FlxDestroyUtil.destroy(atlas);
#end
}
27 changes: 13 additions & 14 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ class FunkinLua {
// build target (windows, mac, linux, android, etc.)
set('buildTarget', getBuildTarget());

for (name => func in customFunctions)
{
if(func != null)
Lua_helper.add_callback(lua, name, func);
}

//
Lua_helper.add_callback(lua, "getRunningScripts", function(){
var runningScripts:Array<String> = [];
Expand Down Expand Up @@ -1130,32 +1124,35 @@ class FunkinLua {
if(spr != null) spr.makeGraphic(width, height, CoolUtil.colorFromString(color));
});
Lua_helper.add_callback(lua, "addAnimationByPrefix", function(obj:String, name:String, prefix:String, framerate:Int = 24, loop:Bool = true) {
var obj:Dynamic = LuaUtils.getObjectDirectly(obj, false);
var obj:FlxSprite = cast LuaUtils.getObjectDirectly(obj, false);
if(obj != null && obj.animation != null)
{
obj.animation.addByPrefix(name, prefix, framerate, loop);
if(obj.animation.curAnim == null)
{
if(obj.playAnim != null) obj.playAnim(name, true);
else obj.animation.play(name, true);
var dyn:Dynamic = cast obj;
if(dyn.playAnim != null) dyn.playAnim(name, true);
else dyn.animation.play(name, true);
}
return true;
}
return false;
});

Lua_helper.add_callback(lua, "addAnimation", function(obj:String, name:String, frames:Array<Int>, framerate:Int = 24, loop:Bool = true) {
var obj:Dynamic = LuaUtils.getObjectDirectly(obj, false);
var obj:FlxSprite = LuaUtils.getObjectDirectly(obj, false);
if(obj != null && obj.animation != null)
{
obj.animation.add(name, frames, framerate, loop);
if(obj.animation.curAnim == null) {
obj.animation.play(name, true);
if(obj.animation.curAnim == null)
{
var dyn:Dynamic = cast obj;
if(dyn.playAnim != null) dyn.playAnim(name, true);
else dyn.animation.play(name, true);
}
return true;
}
return false;
});
}

Lua_helper.add_callback(lua, "addAnimationByIndices", function(obj:String, name:String, prefix:String, indices:Any, framerate:Int = 24, loop:Bool = false) {
return LuaUtils.addAnimByIndices(obj, name, prefix, indices, framerate, loop);
Expand Down Expand Up @@ -1635,6 +1632,8 @@ class FunkinLua {
ShaderFunctions.implement(this);
DeprecatedFunctions.implement(this);

for (name => func in customFunctions) if (func != null) Lua_helper.add_callback(lua, name, func);

try{
var isString:Bool = !FileSystem.exists(scriptName);
var result:Dynamic = null;
Expand Down
9 changes: 3 additions & 6 deletions source/psychlua/ReflectionFunctions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ class ReflectionFunctions
Lua_helper.add_callback(lua, "getProperty", function(variable:String, ?allowMaps:Bool = false)
{
var split:Array<String> = variable.split('.');
if (split.length > 1)
return LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split, true, true, allowMaps), split[split.length - 1], allowMaps);
if (split.length > 1) return LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split, true, true, allowMaps), split[split.length - 1], allowMaps);
return LuaUtils.getVarInArray(LuaUtils.getTargetInstance(), variable, allowMaps);
});
Lua_helper.add_callback(lua, "setProperty", function(variable:String, value:Dynamic, allowMaps:Bool = false)
{
Lua_helper.add_callback(lua, "setProperty", function(variable:String, value:Dynamic, ?allowMaps:Bool = false) {
var split:Array<String> = variable.split('.');
if (split.length > 1)
{
if (split.length > 1) {
LuaUtils.setVarInArray(LuaUtils.getPropertyLoop(split, true, true, allowMaps), split[split.length - 1], value, allowMaps);
return true;
}
Expand Down
Loading

0 comments on commit 6952de5

Please sign in to comment.