Skip to content

Commit ce2511f

Browse files
and i only find out about this now...
- found out about flxinputtext and the uitextbox class now uses that (with modifications of course) - fixed a bug where discord rpc would log its shutting down twice - renamed ms_openeditiors to db_openeditors for better orgnization - added more functions to the datautil class - renamed every class in the ui package with "UI" in the beginning to have more readability - many doc comment tweaks and fixes
1 parent 1c883e8 commit ce2511f

24 files changed

+384
-446
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
},
1313
"haxe.enableExtendedIndentation": true,
1414
"cSpell.words": [
15+
"borderless",
1516
"CAPSLOCK",
17+
"contextmenu",
1618
"GRAVEACCENT",
1719
"Haxe",
1820
"IBEAM",
21+
"keybinds",
1922
"NUMPADEIGHT",
2023
"NUMPADFIVE",
2124
"NUMPADFOUR",

project.hxp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Project extends HXProject
1818
{
1919
//
2020
// METADATA
21-
//
21+
// ===========================
2222

2323
/**
2424
* The game's version number, as a Semantic Versioning string with no prefix.
@@ -92,8 +92,7 @@ class Project extends HXProject
9292

9393
//
9494
// FEATURE FLAGS
95-
// (Inverse feature flags are automatically populated)
96-
// ===========================================================================
95+
// ==========================================
9796

9897
/**
9998
* Allows the game to be displayed in the user's Discord "Activity" box
@@ -149,7 +148,6 @@ class Project extends HXProject
149148
{
150149
info('STARCORE');
151150
info('Setting up build...');
152-
153151
info('Target Version: ' + VERSION);
154152
info('Git Branch: ' + getGitBranch());
155153
info('Git Commit: ' + getGitCommit());
@@ -210,6 +208,7 @@ class Project extends HXProject
210208
this.window.orientation = (isDesktop() || isMobile()) ? Orientation.LANDSCAPE : Orientation.AUTO;
211209
this.window.hardware = true;
212210
this.window.vsync = false;
211+
// this.window.defaultFont = 'assets/fonts/Born2bSportyFS.ttf';
213212
this.window.allowHighDPI = true; // Force / allow high DPI
214213
}
215214

@@ -591,7 +590,7 @@ class Project extends HXProject
591590

592591
public function isRelease():Bool
593592
{
594-
return this.defines.exists("final");
593+
return this.defines.exists('final');
595594
}
596595

597596
public function getHaxedef(name:String):Null<Dynamic>
@@ -663,10 +662,10 @@ class Project extends HXProject
663662
/**
664663
* Add an asset to the game build.
665664
*
666-
* @param path The path the asset is located at.
667-
* @param rename The path the asset should be placed.
665+
* @param path The path the asset is located at.
666+
* @param rename The path the asset should be placed.
668667
* @param library The asset library to add the asset to. `null` = 'default'
669-
* @param embed Whether to embed the asset in the executable.
668+
* @param embed Whether to embed the asset in the executable.
670669
*/
671670
public function addAsset(path:String, ?rename:String, ?library:String, embed:Bool = false):Void
672671
{
@@ -682,12 +681,12 @@ class Project extends HXProject
682681
/**
683682
* Add an entire path of assets to the game build.
684683
*
685-
* @param path The path the assets are located at.
686-
* @param rename The path the assets should be placed.
684+
* @param path The path the assets are located at.
685+
* @param rename The path the assets should be placed.
687686
* @param library The asset library to add the assets to. `null` = 'default'
688687
* @param include An optional array to include specific asset names.
689688
* @param exclude An optional array to exclude specific asset names.
690-
* @param embed Whether to embed the assets in the executable.
689+
* @param embed Whether to embed the assets in the executable.
691690
*/
692691
public function addAssetPath(path:String, ?rename:String, library:String, ?include:Array<String>, ?exclude:Array<String>, embed:Bool = false):Void
693692
{

source/InitState.hx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@ package;
22

33
import flixel.FlxG;
44
import flixel.FlxState;
5-
import flixel.input.keyboard.FlxKey;
5+
66
import flixel.math.FlxMath;
77
import flixel.system.FlxAssets;
88
import flixel.tweens.FlxTween;
99
import lime.app.Application;
1010
import openfl.Lib;
1111
import openfl.display.StageQuality;
1212
import openfl.display.StageScaleMode;
13-
import openfl.events.KeyboardEvent;
1413
import starcore.backend.api.DiscordClient;
1514
import starcore.backend.data.ClientPrefs;
1615
import starcore.backend.util.CacheUtil;
1716
import starcore.backend.util.FlixelUtil;
1817
import starcore.backend.util.LoggerUtil;
1918
import starcore.backend.util.PathUtil;
20-
import starcore.backend.util.SaveUtil;
2119
import starcore.menus.MainMenuState;
2220
import starcore.shaders.*;
2321
#if web
2422
import js.Browser;
2523
#end
24+
#if (web && debug)
25+
import starcore.backend.util.SaveUtil;
26+
import openfl.events.KeyboardEvent;
27+
#end
2628

2729
/**
2830
* The initial state of the game. This is where
@@ -87,7 +89,18 @@ class InitState extends FlxState
8789
FlxAssets.FONT_DEFAULT = PathUtil.ofFont('Born2bSportyFS');
8890

8991
// Set the stage quality
92+
#if !web
93+
FlxG.stage.quality = StageQuality.LOW;
94+
#else
9095
FlxG.stage.quality = StageQuality.MEDIUM;
96+
#end
97+
98+
// Make the window borderless when it is
99+
// not in fullscreen mode
100+
// TODO: Figure out how to make it draggable
101+
#if desktop
102+
Application.current.window.borderless = true;
103+
#end
91104

92105
// Disable the right-click context menu for HTML5
93106
#if html5

source/Main.hx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package;
22

33
import flixel.FlxGame;
4+
import openfl.Lib;
45
import openfl.display.Sprite;
56

67
/**
78
* The main entry point of the game. You don't need to modify this class.
89
* Unless you want to change settings for the game (i.e., window size), you can
910
* add or change the setup by modifying the `InitState.hx` class and
10-
* doing whatever you want from there.
11+
* doing whatever is needed from there.
12+
*
13+
* Otherwise, all other code needs to go into states (or wherever else
14+
* it makes sense to put something).
1115
*/
1216
class Main extends Sprite
1317
{
@@ -30,6 +34,14 @@ class Main extends Sprite
3034
startFullscreen: true
3135
};
3236

37+
/**
38+
* The main function that starts it all.
39+
*/
40+
public static function main():Void
41+
{
42+
Lib.current.addChild(new Main());
43+
}
44+
3345
public function new()
3446
{
3547
super();

source/starcore/backend/Controls.hx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ final class Controls
100100

101101
// Misc. (just pressed)
102102
public var MS_FULLSCREEN_JUST_PRESSED(get, never):Bool;
103-
public var MS_OPENEDITORS_JUST_PRESSED(get, never):Bool;
104103

105104
inline function get_MS_FULLSCREEN_JUST_PRESSED():Bool
106105
return justPressed('ms_fullscreen');
107106

108-
inline function get_MS_OPENEDITORS_JUST_PRESSED():Bool
109-
return justPressed('ms_openeditors');
107+
// Debug (just pressed)
108+
public var DB_OPENEDITORS_JUST_PRESSED(get, never):Bool;
109+
110+
inline function get_DB_OPENEDITORS_JUST_PRESSED():Bool
111+
return justPressed('db_openeditors');
110112

111113
function new() {}
112114

source/starcore/backend/api/DiscordClient.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class DiscordClient
1818
{
1919
#if DISCORD_RPC_ALLOWED
2020
static var presence:DiscordRichPresence = new DiscordRichPresence();
21+
static var isShutDown:Bool = false;
2122
#end
2223

2324
function new() {}
@@ -32,6 +33,8 @@ final class DiscordClient
3233
{
3334
// Log info
3435
LoggerUtil.log('Initializing Discord rich presence');
36+
// Incase the user turns it back on again
37+
isShutDown = false;
3538
// Initialize the client
3639
Discord.Initialize(Constants.DISCORD_APP_ID, null, true, null);
3740
// Start the timer (for the amount of time the player has played the game)
@@ -67,6 +70,8 @@ final class DiscordClient
6770
public static function shutdown():Void
6871
{
6972
#if DISCORD_RPC_ALLOWED
73+
if (isShutDown) return;
74+
isShutDown = true;
7075
LoggerUtil.log('Shutting down Discord rich presence');
7176
Discord.Shutdown();
7277
#end

source/starcore/backend/data/ClientPrefs.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum ShaderModeType
1616
{
1717
DEFAULT; // All shaders applied (excluding Scanline)
1818
FAST; // Grain, Scanline, Hq2x and Tiltshift shaders are applied
19-
MINIMAL; // Grain, Scanline and Hq2x shaders are applied
19+
MINIMAL; // Grain and Hq2x shaders are applied
2020
NONE; // No shaders at all
2121
}
2222

source/starcore/backend/data/Constants.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ final class Constants
3737
'vl_mute' => F12,
3838
// Misc.
3939
'ms_fullscreen' => F11,
40-
'ms_openeditors' => F7
40+
// Debug
41+
'db_openeditors' => F7
4142
];
4243

4344
/**

source/starcore/backend/util/AssetUtil.hx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package starcore.backend.util;
22

3+
import flixel.FlxG;
34
import haxe.Json;
45
import openfl.utils.Assets;
56

@@ -32,13 +33,11 @@ final class AssetUtil
3233
{
3334
var chars:String = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
3435
var result:StringBuf = new StringBuf();
35-
36-
for (i in 0...chars.length)
36+
for (_ in 0...chars.length)
3737
{
3838
var index = Std.int(Math.random() * chars.length);
3939
result.add(chars.charAt(index));
4040
}
41-
4241
return result.toString();
4342
}
4443

@@ -63,7 +62,7 @@ final class AssetUtil
6362
{
6463
for (snd in soundArray)
6564
{
66-
Assets.loadSound(snd);
65+
FlxG.sound.cache(snd);
6766
}
6867
}
6968
}

source/starcore/backend/util/DataUtil.hx

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,79 @@ using StringTools;
88
*/
99
final class DataUtil
1010
{
11+
function new() {}
12+
13+
/**
14+
* Inserts string `toInsert` inside of string `s` based on the index.
15+
*
16+
* ## Example
17+
* ```
18+
* var s:String = 'This is so cool!';
19+
* insertStringAtIndex(s, 'function ', 4); // Output: This function is so cool!
20+
* ```
21+
*
22+
* @param s The string to be changed.
23+
* @param toInsert The string to insert.
24+
* @param index The index to insert `toInsert`.
25+
* @return The modified string.
26+
*/
27+
public static function insertStringAtIndex(s:String, toInsert:String, index:Int):String
28+
{
29+
var toReturn:String = '';
30+
var toConcat:Array<String> = [];
31+
// Add all characters to the list
32+
// (including the string to insert at the wanted index)
33+
for (i in 0...s.length)
34+
{
35+
toConcat.push(s.charAt(i));
36+
if (i == index)
37+
{
38+
toConcat.push(toInsert);
39+
}
40+
}
41+
// Reconstruct the string back with the inserted text
42+
for (char in toConcat)
43+
{
44+
toReturn += char;
45+
}
46+
return toReturn;
47+
}
48+
49+
/**
50+
* Deletes a specific part of text from string `s`
51+
* based on `startIndex` and `endIndex`.
52+
*
53+
* If `startIndex` is greater than `endIndex`, then the numbers are swapped.
54+
*
55+
* ## Example
56+
* ```
57+
* var s:String = 'The word "not" is not deleted!';
58+
* deleteTextFromString(s, 18, 21); // Output: The word "not" is deleted!
59+
* ```
60+
*
61+
* @param s The string to delete text from.
62+
* @param startIndex The starting index to delete text from.
63+
* @param endIndex The ending index to delete text from (inclusive).
64+
* @return The modified string.
65+
*/
66+
public static function deleteTextFromString(s:String, startIndex:Int, endIndex:Int):String
67+
{
68+
var si:Int = (!(startIndex > endIndex)) ? startIndex : endIndex;
69+
var ei:Int = (!(startIndex > endIndex)) ? endIndex : startIndex;
70+
var toReturn:String = '';
71+
for (i in 0...s.length)
72+
{
73+
// If the current character isn't in the range of
74+
// the text to be "deleted", then add the character
75+
// at the end of toReturn
76+
if (!(i >= si && i <= ei))
77+
{
78+
toReturn += s.charAt(i);
79+
}
80+
}
81+
return toReturn;
82+
}
83+
1184
/**
1285
* Removes a word from a string by its index.
1386
*
@@ -30,22 +103,14 @@ final class DataUtil
30103
var sentence:Array<String> = s.trim().split(delimiter);
31104
// Convert it back to a regular string, but
32105
// without the removed word
33-
for (i in 0...sentence.length)
106+
for (word in 0...sentence.length)
34107
{
35-
if (i != index)
108+
if (word != index)
36109
{
37-
toReturn += '${sentence[i]} ';
110+
toReturn += '${sentence[word]} ';
38111
}
39112
}
40-
41-
if (trim)
42-
{
43-
return toReturn.trim();
44-
}
45-
else
46-
{
47-
return toReturn;
48-
}
113+
return (trim) ? toReturn.trim() : return toReturn;
49114
}
50115

51116
/**
@@ -54,11 +119,11 @@ final class DataUtil
54119
*
55120
* @param object The JSON `Dynamic` object to obtain the field from.
56121
* @param field The field to get.
57-
* @param defaultValue The value that is returned if the field does not exist.
122+
* @param defaultValue The value that is returned if the field does not exist. Default value is `null`.
58123
* @return The value found from the said field. If it isn't found, then the
59124
* `defaultValue` parameter is returned instead.
60125
*/
61-
public static inline function getDynamicField(object:Dynamic, field:String, defaultValue:Dynamic):Any
126+
public static inline function getDynamicField(object:Dynamic, field:String, ?defaultValue:Dynamic):Any
62127
{
63128
return (Reflect.hasField(object, field)) ? Reflect.field(object, field) : defaultValue;
64129
}

0 commit comments

Comments
 (0)