Skip to content

Commit 6b948bb

Browse files
"i may be stupid, but i have an idea..."
- made the project.hxp file more efficient, added a isCPlusPlus function and now displays the asset paths being added - fixed a crash for web when discord rpc was disabled - you can now make a text only take a specific type of input (string, int and float)
1 parent 4c99117 commit 6b948bb

File tree

8 files changed

+226
-107
lines changed

8 files changed

+226
-107
lines changed

.vscode/settings.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
},
1313
"haxe.enableExtendedIndentation": true,
1414
"cSpell.words": [
15-
"openeditors",
15+
"CAPSLOCK",
16+
"GRAVEACCENT",
1617
"Haxe",
1718
"IBEAM",
18-
"GRAVEACCENT",
1919
"NUMPADEIGHT",
2020
"NUMPADFIVE",
2121
"NUMPADFOUR",
@@ -27,9 +27,10 @@
2727
"NUMPADPLUS",
2828
"NUMPADSEVEN",
2929
"NUMPADSIX",
30+
"NUMPADSLASH",
3031
"NUMPADTHREE",
3132
"NUMPADTWO",
3233
"NUMPADZERO",
33-
"NUMPADSLASH"
34+
"openeditors"
3435
]
3536
}

project.hxp

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -164,69 +164,53 @@ class Project extends HXProject
164164
*/
165165
function configureApp()
166166
{
167+
//
168+
// METADATA
169+
// ======================================
167170
this.meta.title = TITLE;
168171
this.meta.version = VERSION;
169172
this.meta.packageName = PACKAGE_NAME;
170173
this.meta.company = COMPANY;
174+
this.meta.description = 'A space themed, open world survival sandbox game.';
175+
this.meta.companyId = COMPANY;
176+
this.meta.companyUrl = COMPANY;
171177

172-
this.app.main = MAIN_CLASS;
173-
this.app.file = EXECUTABLE_NAME;
174-
this.app.preloader = PRELOADER;
175-
176-
// Tell Lime where to look for the game's source code
177-
// If for some reason we have multiple source directories, we can add more entries here
178-
this.sources.push(SOURCE_DIR);
178+
//
179+
// CODE
180+
// =================================
181+
this.sources.push(SOURCE_DIR); // Source code location (more than one can be added)
179182

180-
// Tell Lime to run some prebuild and postbuild scripts
183+
//
184+
// PREBUILD & POSTBUILD
185+
// ==================================================
181186
// this.preBuildCallbacks.push(buildHaxeCLICommand(PREBUILD_HX));
182187
// this.postBuildCallbacks.push(buildHaxeCLICommand(POSTBUILD_HX));
183188

189+
//
190+
// APP
191+
// ==========================
192+
this.app.main = MAIN_CLASS;
193+
this.app.preloader = PRELOADER;
194+
this.app.file = EXECUTABLE_NAME;
184195
// These values are only used by the SWF target
185196
// this.app.path
186197
// this.app.init
187198
// this.app.swfVersion
188199
// this.app.url
189200

190-
// These values are only used by... FIREFOX MARKETPLACE WHAT?
191-
// this.meta.description = '';
192-
// this.meta.companyId = COMPANY;
193-
// this.meta.companyUrl = COMPANY;
194-
195-
// Configure the window
196-
// Automatically configure FPS
201+
//
202+
// WINDOW
203+
// =====================================
197204
this.window.fps = 60;
198-
// Set the window size
199-
this.window.width = 960;
200-
this.window.height = 720;
201-
// Set the background color
205+
this.window.width = (!isMobile()) ? 960 : 0;
206+
this.window.height = (!isMobile()) ? 720 : 0;
202207
this.window.background = 0xFF000000;
203-
208+
this.window.fullscreen = true;
209+
this.window.resizable = isWeb();
210+
this.window.orientation = (isDesktop() || isMobile()) ? Orientation.LANDSCAPE : Orientation.AUTO;
204211
this.window.hardware = true;
205212
this.window.vsync = false;
206-
// force / allow high DPI
207-
this.window.allowHighDPI = true;
208-
209-
if (isWeb())
210-
{
211-
this.window.resizable = true;
212-
}
213-
214-
if (isDesktop())
215-
{
216-
this.window.orientation = Orientation.LANDSCAPE;
217-
this.window.fullscreen = false;
218-
this.window.resizable = true;
219-
this.window.vsync = false;
220-
}
221-
222-
if (isMobile())
223-
{
224-
this.window.orientation = Orientation.LANDSCAPE;
225-
this.window.fullscreen = false;
226-
this.window.resizable = false;
227-
this.window.width = 0;
228-
this.window.height = 0;
229-
}
213+
this.window.allowHighDPI = true; // Force / allow high DPI
230214
}
231215

232216
/**
@@ -271,15 +255,15 @@ class Project extends HXProject
271255
switch (this.platformType)
272256
{
273257
case PlatformType.DESKTOP:
274-
info('Platform Type: Desktop');
258+
info('Target Platform Type: Desktop');
275259
case PlatformType.MOBILE:
276-
info('Platform Type: Mobile');
260+
info('Target Platform Type: Mobile');
277261
case PlatformType.WEB:
278-
info('Platform Type: Web');
262+
info('Target Platform Type: Web');
279263
case PlatformType.CONSOLE:
280-
info('Platform Type: Console');
264+
info('Target Platform Type: Console');
281265
default:
282-
error('Unknown platform type (got ${platformType})');
266+
error('Unknown target platform type (got ${platformType})');
283267
}
284268

285269
// Print whether we are using HXCPP, HashLink, or something else
@@ -307,10 +291,14 @@ class Project extends HXProject
307291
{
308292
info('Target Language: C#');
309293
}
310-
else
294+
else if (isCPlusPlus())
311295
{
312296
info('Target Language: C++');
313297
}
298+
else
299+
{
300+
info('Target Language: Unknown');
301+
}
314302

315303
for (arch in this.architectures)
316304
{
@@ -431,9 +419,9 @@ class Project extends HXProject
431419

432420
// Convert the game to run on other platforms
433421
addHaxelib('lime');
434-
// Many frontend and backend utilities for the games display
422+
// Many frontend and backend utilities for the game's display
435423
addHaxelib('openfl');
436-
// Game library
424+
// Core game library
437425
addHaxelib('flixel');
438426
// Additional utilities for Flixel
439427
addHaxelib('flixel-addons');
@@ -462,8 +450,6 @@ class Project extends HXProject
462450

463451
function configureAssets()
464452
{
465-
// info('ADDING ASSET PATHS');
466-
467453
// Add font assets
468454
addAssetPath('assets/fonts', 'assets/fonts', 'default', ['*.ttf'], []);
469455

@@ -494,6 +480,8 @@ class Project extends HXProject
494480
addAssetPath('assets/shared/music', 'assets/shared/music', 'default', ['*.ogg'], ['*.mp3']);
495481
addAssetPath('assets/shared/sounds', 'assets/shared/sounds', 'default', ['*.ogg'], ['*.mp3']);
496482
}
483+
484+
info('-------------------------------------------------------------');
497485
}
498486

499487
/**
@@ -586,6 +574,11 @@ class Project extends HXProject
586574
return this.targetFlags.exists('cs');
587575
}
588576

577+
public function isCPlusPlus():Bool
578+
{
579+
return this.defines.exists('cpp'); // Why in defines and not target flags...
580+
}
581+
589582
public function isDisplay():Bool
590583
{
591584
return this.command == 'display';
@@ -723,7 +716,7 @@ class Project extends HXProject
723716
}
724717
else
725718
{
726-
// info(' Adding asset path ${path}...');
719+
info('Adding asset path ${path}...');
727720
}
728721

729722
for (file in sys.FileSystem.readDirectory(path))
@@ -854,14 +847,6 @@ class Project extends HXProject
854847
// LOGGING FUNCTIONS
855848
// ==============================
856849

857-
/**
858-
* Display an error message. This should stop the build process.
859-
*/
860-
public function error(message:String):Void
861-
{
862-
Log.error('${message}');
863-
}
864-
865850
/**
866851
* Display an info message. This should not interfere with the build process.
867852
*/
@@ -872,6 +857,14 @@ class Project extends HXProject
872857
Log.info('[INFO] ${message}');
873858
}
874859
}
860+
861+
/**
862+
* Display an error message. This should stop the build process.
863+
*/
864+
public function error(message:String):Void
865+
{
866+
Log.error('${message}');
867+
}
875868
}
876869

877870
/**

source/InitState.hx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package;
22

3+
import flixel.input.keyboard.FlxKey;
34
import starcore.backend.util.SaveUtil;
45
import openfl.events.KeyboardEvent;
56
import flixel.FlxG;
@@ -129,8 +130,7 @@ class InitState extends FlxState
129130
Application.current.window.onFocusIn.add(() ->
130131
{
131132
// Bring the volume back up when the window is focused again
132-
var minimizeVolume:Bool = ClientPrefs.getOption('minimizeVolume');
133-
if (minimizeVolume && !CacheUtil.isWindowFocused)
133+
if (ClientPrefs.getOption('minimizeVolume') && !CacheUtil.isWindowFocused)
134134
{
135135
// Set back to one decimal place (0.1) when the screen gains focus again
136136
// (note that if the user had the volume all the way down, it will be set to zero)
@@ -146,8 +146,7 @@ class InitState extends FlxState
146146
Application.current.window.onFocusOut.add(() ->
147147
{
148148
// Minimize the volume when the window loses focus
149-
var minimizeVolume:Bool = ClientPrefs.getOption('minimizeVolume');
150-
if (minimizeVolume && CacheUtil.isWindowFocused)
149+
if (ClientPrefs.getOption('minimizeVolume') && CacheUtil.isWindowFocused)
151150
{
152151
// Set the last volume used to the current volume
153152
CacheUtil.lastVolumeUsed = FlxG.sound.volume;
@@ -161,6 +160,8 @@ class InitState extends FlxState
161160
});
162161
#end
163162

163+
// Delete all save data if CTRL + BACKSPACE
164+
// is pressed on debug mode in the web version
164165
#if (web && debug)
165166
FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, (_) ->
166167
{
@@ -171,6 +172,15 @@ class InitState extends FlxState
171172
});
172173
#end
173174

175+
// Enable/disable caps lock
176+
FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, (_) ->
177+
{
178+
if (FlxG.keys.justPressed.CAPSLOCK)
179+
{
180+
CacheUtil.capsLockEnabled = !CacheUtil.capsLockEnabled;
181+
}
182+
});
183+
174184
// Do shit like saving the user's data when the game closes
175185
Application.current.window.onClose.add(() ->
176186
{

source/starcore/backend/api/DiscordClient.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import lime.app.Application;
1616
*/
1717
final class DiscordClient
1818
{
19+
#if DISCORD_RPC_ALLOWED
1920
static var presence:DiscordRichPresence = new DiscordRichPresence();
21+
#end
2022

2123
function new() {}
2224

source/starcore/backend/data/Constants.hx

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package starcore.backend.data;
22

3-
import starcore.backend.data.ClientPrefs.ShaderModeType;
43
import flixel.input.keyboard.FlxKey;
54
import flixel.util.FlxColor;
5+
import starcore.backend.data.ClientPrefs.ShaderModeType;
66
import starcore.backend.util.PathUtil;
77

88
/**
@@ -177,10 +177,10 @@ final class Constants
177177
// ===========================
178178

179179
/**
180-
* The allowed characters that can be added to text in a
180+
* The allowed alphabetic characters that can be added to text in a
181181
* `starcore.ui.TextBox` object.
182182
*/
183-
public static final ALLOWED_TEXT_BOX_CHARACTERS:Array<FlxKey> = [
183+
public static final ALLOWED_TEXT_BOX_ALPHABET_CHARACTERS:Array<FlxKey> = [
184184
A,
185185
B,
186186
C,
@@ -245,6 +245,62 @@ final class Constants
245245
NUMPADSLASH
246246
];
247247

248+
/**
249+
* The allowed floating point number characters that can be added to text in a
250+
* `starcore.ui.TextBox` object.
251+
*/
252+
public static final ALLOWED_TEXT_BOX_FLOAT_CHARACTERS:Array<FlxKey> = [
253+
ONE,
254+
TWO,
255+
THREE,
256+
FOUR,
257+
FIVE,
258+
SIX,
259+
SEVEN,
260+
EIGHT,
261+
NINE,
262+
ZERO,
263+
PERIOD,
264+
NUMPADZERO,
265+
NUMPADONE,
266+
NUMPADTWO,
267+
NUMPADTHREE,
268+
NUMPADFOUR,
269+
NUMPADFIVE,
270+
NUMPADSIX,
271+
NUMPADSEVEN,
272+
NUMPADEIGHT,
273+
NUMPADNINE,
274+
NUMPADPERIOD
275+
];
276+
277+
/**
278+
* The allowed integer characters that can be added to text in a
279+
* `starcore.ui.TextBox` object.
280+
*/
281+
public static final ALLOWED_TEXT_BOX_INT_CHARACTERS:Array<FlxKey> = [
282+
ONE,
283+
TWO,
284+
THREE,
285+
FOUR,
286+
FIVE,
287+
SIX,
288+
SEVEN,
289+
EIGHT,
290+
NINE,
291+
ZERO,
292+
NUMPADZERO,
293+
NUMPADONE,
294+
NUMPADTWO,
295+
NUMPADTHREE,
296+
NUMPADFOUR,
297+
NUMPADFIVE,
298+
NUMPADSIX,
299+
NUMPADSEVEN,
300+
NUMPADEIGHT,
301+
NUMPADNINE
302+
];
303+
248304
//
249305
// API
250306
// =============================

source/starcore/backend/util/CacheUtil.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ final class CacheUtil
5050
*/
5151
public static var vcrMario85Filter:VCRMario85Shader;
5252

53+
/**
54+
* Is caps lock enabled?
55+
*/
56+
public static var capsLockEnabled:Bool = false; // TODO: Find a better way to do this.
57+
5358
function new() {}
5459
}

0 commit comments

Comments
 (0)