Skip to content

Commit

Permalink
screenshot plugin and whatever
Browse files Browse the repository at this point in the history
well guess what i gotta try now
  • Loading branch information
charlesisfeline committed Mar 1, 2024
1 parent 29894d2 commit 88a7092
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 32 deletions.
6 changes: 4 additions & 2 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<haxelib name="linc_luajit" if="LUA_ALLOWED"/>
<haxelib name="SScript" if="HSCRIPT_ALLOWED"/>
<haxelib name="hxvlc" if="VIDEOS_ALLOWED"/>
<haxelib name="discord_rpc" if="desktop"/>
<haxelib name="discord_rpc" if="desktop cpp"/>
<haxelib name="flxanimate"/>
<haxelib name="tjson" />

Expand All @@ -116,13 +116,15 @@
<!-- Enables a terminal log prompt on debug builds -->
<haxelib name="hxcpp-debug-server" if="debug"/>

<haxelib name="flixel-screenshot-plugin" />

<section unless="mac">
<haxelib name="systools" />
<ndll name="systools" haxelib="systools" />
</section>

<haxedef name="openflPos" />
<haxedef name="hscriptPos" />
<haxedef name="hscriptPos" if="HSCRIPT_ALLOWED" />

<!-- ______________________________ Haxedefines _____________________________ -->

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions hmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"ref": "develop",
"url": "https://github.com/VsFoxaDevs/lime"
},
{
"name": "flixel-screenshot-plugin",
"type": "haxelib",
"version": null
},
{
"name": "haxeui-core",
"type": "haxelib",
Expand Down
12 changes: 5 additions & 7 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import flixel.FlxGame;
import haxe.io.Path;
import openfl.Assets;
import openfl.Lib;
import openfl.display.FPS;
import openfl.display.Sprite;
import openfl.display.Bitmap;
import openfl.events.Event;
import openfl.display.StageScaleMode;
import lime.app.Application;
Expand Down Expand Up @@ -94,12 +94,6 @@ class Main extends Sprite
removeEventListener(Event.ADDED_TO_STAGE, init);

setupGame();

var timer = new haxe.Timer(1);
timer.run = () -> {
coloring();
if (fpsVar.textColor == 0) fpsVar.textColor = -4775566;
} // needs to be done because textcolor beco
}

private function setupGame():Void {
Expand All @@ -114,6 +108,8 @@ class Main extends Sprite
game.width = Math.ceil(stageWidth / game.zoom);
game.height = Math.ceil(stageHeight / game.zoom);
}

flixel.FlxG.plugins.add(new flixel.addons.plugin.ScreenShotPlugin());

#if LUA_ALLOWED Lua.set_callbacks_function(cpp.Callable.fromStaticFunction(psychlua.CallbackHandler.call)); #end
Controls.instance = new Controls();
Expand Down Expand Up @@ -190,6 +186,8 @@ class Main extends Sprite
"I did but error oof - Vencerist",
"Ah bueno adios master - ShadowMario",
"Skibidy bah mmm dada *explodes* - ShadowMario",
"Wow, you're struggling! - CharlesCatYT",
"WHY - CharlesCatYT",
"What have you done, you killed it! - crowplexus",
"Have you checked if the variable exists? - crowplexus",
"Have you even read the wiki before trying that? - crowplexus"
Expand Down
33 changes: 33 additions & 0 deletions source/backend/ArrayUtil.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
package backend;

using StringTools;

class ArrayUtil {
/**
Checks a provided value to see if it is in the provided blacklist
@param value The value you would like to be checked
@param blacklist The provided blacklist you would like to use to check
**/
public static function checkBlacklist(value:String, blacklist:Array<String>):Bool {
for (phrase in blacklist) {
if (value == phrase) {trace(phrase + ' is in the blacklist'); return true; break;}
}
trace(value + ' is not in blacklist');
return false;
}
/**
Essentially takes a double array and only returns the first parts of it.
Ex. [['A', "b"], ['c', "d"]] will only return as ['A', 'c']
@param bigArray Just an Array with more arrays in it.
@return An array that only has the first value of array within an array.
**/
public static function grabFirstVal(bigArray:Array<Array<Dynamic>>):Array<Dynamic> {
var tempArray:Array<Dynamic> = [];
for (item in bigArray) {
if (Std.isOfType(item, Array)) {
tempArray.push(item[0]);
}
}
return tempArray;
}

/**
* Gets the index of a possible new element of an Array of T using an efficient algorithm.
* @param array Array of T to check in
Expand Down
130 changes: 108 additions & 22 deletions source/backend/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package backend;

import flixel.FlxBasic;
import flixel.FlxObject;
import flixel.tweens.FlxEase;
import flixel.FlxG;
import flixel.input.keyboard.FlxKey;
//import flixel.util.FlxSave;

//import flixel.math.FlxPoint;

import openfl.utils.Assets;
import lime.utils.Assets as LimeAssets;
import lime.system.System;

#if sys
import sys.io.File;
Expand All @@ -24,6 +28,34 @@ enum SlideCalcMethod

class CoolUtil
{
/**
Returns the midpoint between 2 numbers. Can be useful for X or Y positions.
@param val1 The initial number
@param val2 The second number
**/
inline public static function midpoint(val1:Float, val2:Float) {
return (val1 + val2) / 2;
}

// sleep function that blocks the main thread
public static inline function blockExecution(time:Float):Void {
var start:Float = Sys.time();
while (Sys.time() - start < time) {"do nothing";}
}

/**
Returns a decimal where the `baseValue` is divided by the `denominator`, in a sense splitting it like a fraction.
Optionally, you can add the `numerator` value to increate the fraction you get back, ex 2/3 instead of 1/3.
@param baseValue The value you want divided
@param denominator The amount to divide by
@param numerator How many pieces of the fraction you want
**/
inline public static function fractionAmount(baseValue:Float, denominator:Float, ?numerator:Float = 1) {
return (baseValue / denominator) * numerator;
}

public static function makeOutlinedGraphic(Width:Int, Height:Int, Color:Int, LineThickness:Int, OutlineColor:Int){
var rectangle = flixel.graphics.FlxGraphic.fromRectangle(Width, Height, OutlineColor, true);
rectangle.bitmap.fillRect(new openfl.geom.Rectangle(LineThickness, LineThickness, Width - LineThickness * 2, Height - LineThickness * 2), Color);
Expand All @@ -38,7 +70,6 @@ class CoolUtil
if(n < l) n = l;
return n;
}


inline public static function quantize(f:Float, snap:Float){
// changed so this actually works lol
Expand All @@ -47,21 +78,54 @@ class CoolUtil
return (m / snap);
}

public static function rotate(x:Float, y:Float, angle:Float, ?point:FlxPoint):FlxPoint
{
/**
* Just a simple function to determine which key was pressed. Good for sequential keypresses. An example of how to use this is by simply adding the value to a string in the update function.
*
* Ex:
* ```
* public var value:String = '';
* override function update(elapsed:Float) {
* value += keypressToString(); // This will add a key to the string everytime a key is pressed
* }
* ```
* @return Key that was pressed as a String
*/
public static function keypressToString():String {
var characterToAdd:String = "";
if (FlxG.keys.justPressed.ANY) {
final key = cast(FlxG.keys.firstJustPressed(), FlxKey);
if (key != FlxKey.NONE){
final upperKeyLol = key.toString().toUpperCase();
characterToAdd += FlxKey.fromStringMap.get(upperKeyLol);
}
}
return characterToAdd;
}

public static function rotate(x:Float, y:Float, angle:Float, ?point:FlxPoint):FlxPoint {
var p = point == null ? FlxPoint.weak() : point;
return p.set((x * Math.cos(angle)) - (y * Math.sin(angle)), (x * Math.sin(angle)) + (y * Math.cos(angle)));
}


/**
Just insert an ease name, like linear or quadOut for example, and it'll return it as an actual FlxEase value instead of a string. Useful if you have something customizable instead of perma set to a ease.
@param easeName The ease you want the function to return
@return FlxEase
@author LunarCleint
**/
inline public static function stringToEase(easeName:String, ?suffix:String = "")
return Reflect.field(FlxEase, easeName + (easeName == "linear" ? "" : suffix));

inline public static function quantizeAlpha(f:Float, interval:Float)
return Std.int((f+interval/2)/interval)*interval;
return Std.int((f + interval / 2) / interval) * interval;

inline public static function capitalize(text:String)
return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();

inline public static function boundTo(value:Float, min:Float, max:Float):Float {
return Math.max(min, Math.min(max, value));
}
inline public static function boundTo(value:Float, min:Float, max:Float):Float {return Math.max(min, Math.min(max, value));}

inline public static function coolTextFile(path:String):Array<String>
{
Expand Down Expand Up @@ -92,8 +156,7 @@ class CoolUtil
return FlxColor.fromRGB(colors[0], colors[1], colors[2], colors[3]);
}

inline public static function listFromString(string:String):Array<String>
{
inline public static function listFromString(string:String):Array<String> {
var daList:Array<String> = string.trim().split('\n');
for (i in 0...daList.length) daList[i] = daList[i].trim();
return daList;
Expand All @@ -103,6 +166,7 @@ class CoolUtil
var size:Float = num;
var data = 0;
var dataTexts = ["B", "KB", "MB", "GB", "TB"];

while (size > 1024 && data < dataTexts.length - 1) {
data++;
size = size / 1024;
Expand All @@ -113,19 +177,43 @@ class CoolUtil
return formatSize + " " + dataTexts[data];
}

inline public static function removeFromString(remove:String = "", string:String = "")
return string.replace(remove, "");
public static function formatAccuracy(value:Float) {
var conversion:Map<String, String> = [
'0' => '0.00',
'0.0' => '0.00',
'0.00' => '0.00',
'00' => '00.00',
'00.0' => '00.00',
'00.00' => '00.00',
'000' => '000.00'
];

var stringVal:String = Std.string(value);
var converVal:String = '';
for (whyTho in 0...stringVal.length) {
if (stringVal.charAt(whyTho) == '.') converVal += '.';
else converVal += '0';
}

var wantedConversion:String = conversion.get(converVal);
var convertedValue:String = '';
for (ohThingy in 0...wantedConversion.length) {
if (stringVal.charAt(ohThingy) == '') convertedValue += wantedConversion.charAt(ohThingy);
else convertedValue += stringVal.charAt(ohThingy);
}

if (convertedValue.length == 0) return '$value';
return convertedValue;
}

inline public static function removeFromString(remove:String = "", string:String = "") return string.replace(remove, "");

public static function removeDuplicates(string:Array<String>):Array<String> {
var tempArray:Array<String> = new Array<String>();
var lastSeen:String = null;
string.sort(function(str1:String, str2:String) {
return (str1 == str2) ? 0 : (str1 > str2) ? 1 : -1;
});
string.sort(function(str1:String, str2:String) {return (str1 == str2) ? 0 : (str1 > str2) ? 1 : -1;});
for (str in string) {
if (str != lastSeen) {
tempArray.push(str);
}
if (str != lastSeen) tempArray.push(str);
lastSeen = str;
}
return tempArray;
Expand Down Expand Up @@ -162,7 +250,6 @@ class CoolUtil
{
if (slowness < 0) slowness = 1;
var slider:Float = (FlxG.sound.music.time / 1000) * (Conductor.bpm / 60);

var slideValue:Float;

switch (calcMethod) {
Expand All @@ -177,12 +264,11 @@ class CoolUtil
return b == 0 ? FlxMath.absInt(a) : GCD(b, a % b);

inline public static function closest2Multiple(num:Float)
return Math.floor(num/2)*2;
return Math.floor(num / 2) * 2;

public static function addZeros(v:String, length:Int, end:Bool = false) {
var r = v;
while(r.length < length)
r = end ? r + '0': '0$r';
while(r.length < length) r = end ? r + '0': '0$r';
return r;
}

Expand Down
19 changes: 19 additions & 0 deletions source/backend/FlxSpriteTools.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package backend;

import flixel.FlxSprite;
import flixel.util.FlxAxes;

enum abstract SpriteAlignment(String) {
var LEFT = "LEFT";
var RIGHT = "RIGHT";
var CENTER = "CENTER";
var TOP = "TOP";
var BOTTOM = "BOTTOM";
}

class FlxSpriteTools {
public static function centerOnSprite(s:FlxSprite, t:FlxSprite, ?axes:FlxAxes = FlxAxes.XY):Void {
if (axes == FlxAxes.XY || axes == FlxAxes.X) s.x = t.x + (t.width / 2) - (s.width / 2);
if (axes == FlxAxes.XY || axes == FlxAxes.Y) s.y = t.y + (t.height / 2) - (s.height / 2);
}
}
3 changes: 3 additions & 0 deletions source/cppthing/CppApi.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class CppAPI
public static function enableVisualStyles()
WindowsData.enableVisualStyles();

public static function _enableCloseButton(why:Bool)
WindowsData.setCloseButtonEnabled(why);

public static function _setWindowLayered()
WindowsData._setWindowLayered();
#end
Expand Down
16 changes: 16 additions & 0 deletions source/cppthing/WindowsData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ class WindowsData
return 0;
}

// kudos to bing chatgpt thing i hate C++
#if windows
@:functionCode('
HWND hwnd = GetActiveWindow();
HMENU hmenu = GetSystemMenu(hwnd, FALSE);
if (enable) {
EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
} else {
EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
}
')
#end
public static function setCloseButtonEnabled(enable:Bool) {
return enable;
}

#if windows
@:functionCode('
int darkMode = mode;
Expand Down
2 changes: 1 addition & 1 deletion source/debug/FPSCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum GLInfo {
RENDERER;
SHADING_LANGUAGE_VERSION;
}
class FPS extends TextField {
class FPSCounter extends TextField {
/**
The current frame rate, expressed using frames-per-second
**/
Expand Down

0 comments on commit 88a7092

Please sign in to comment.