Skip to content

Commit

Permalink
add gameConfig, the idea of directly load game might will unscrapped,…
Browse files Browse the repository at this point in the history
… hscript hotfix update
  • Loading branch information
khuonghoanghuy committed Jan 10, 2025
1 parent 1e635b9 commit f08ade4
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 61 deletions.
4 changes: 3 additions & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- _________________________ Application Settings _________________________ -->

<app title="Cruese Engine" file="Cruese Engine" main="Main" version="2.0" company="JoaTH Team" />
<app title="Cruese Engine" file="Cruese Engine" main="Main" version="2.1" company="JoaTH Team" />

<!--The flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a html file
or you can set the actual size of your file manually at "FlxPreloaderBase-onUpdate-bytesTotal"-->
Expand Down Expand Up @@ -34,6 +34,7 @@

<source path="source" />
<assets path="assets" />
<assets path="gameConfig.json" />

<assets path="mods" embed="false" />

Expand All @@ -46,6 +47,7 @@
<haxelib name="hscript-iris" version="1.1.3" /> <!--using this one is much better!-->
<haxelib name="polymod" version="1.8.0" />
<haxelib name="linc_luajit" /> <!-- as git -->
<haxelib name="tjson" version="1.4.0" />

<!-- ______________________________ Haxedefines _____________________________ -->

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ A game engine using HScript with a scriptable interface to create a complete gam

## Credits
* Huy1234TH - Main of this project, coder and stuff
* Joalor64GH - Additional Coder, also help fixing bug and init polymod
* Joalor64GH - Additional Coder, also help fixing bug and init polymod
8 changes: 7 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# List TODO for Cruese Engine
## v2.1 (Menu Update)
## v2.2 (Menu Update)
- [ ] Rework game menu
- [ ] Fix if the file have switch code but not on the `classes` function, is crash
- [ ] Fix ActionState could not display details error

## v2.1 (HotFix HScript) - DONE
- [X] Fix can't using any `justPress`, `press`, `justRelease`
- [X] Fix could not load the file if missing full function such as `onUpdate`, `onUpdatePost`,...

## v2.0 (Lua update) - DONE
- [X] Added Lua script (is work lmao)
Expand Down
2 changes: 1 addition & 1 deletion docs/Setup-Game.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For beginner work your game, go to the `mods` folder and follow the steps down h
"title": "Template",
"description": "Game Description.",
"author": "You!",
"api_version": "1.0.0",
"api_version": "2.0.0",
"mod_version": "1.0.0",
"license": "Apache 2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion engineVer.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version":"2.0"
"version":"2.1"
}
3 changes: 3 additions & 0 deletions gameConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"playSplashesScreen": true
}
5 changes: 5 additions & 0 deletions haxelibs.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
"type": "git",
"ref": "main",
"url": "https://github.com/AndreiRudenko/linc_luajit.git"
},
{
"name": "tjson",
"type": "haxelib",
"version": "1.4.0"
}
]
}
3 changes: 2 additions & 1 deletion source/ActionState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ActionState extends FlxState
eror.font = text.font;
add(eror);
case "display crash":
var eror:FlxText = new FlxText(text.x, text.y + 50, 0, Std.string(gonnaDisplayThis) + "\nPress `F5` to reload game", 20);
trace(Std.string(gonnaDisplayThis) + "\nPress `F5` to reload game");
var eror:FlxText = new FlxText(text.x, text.y, 0, Std.string(gonnaDisplayThis) + "\nPress `F5` to reload game", 20);
eror.font = text.font;
add(eror);
}
Expand Down
2 changes: 2 additions & 0 deletions source/GameHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.input.keyboard.FlxKey;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import haxe.Http;
Expand Down Expand Up @@ -67,6 +68,7 @@ class GameHandler
}
};
}

public static function getLinkOfFile(fileLink:String)
{
var data = new Http(fileLink);
Expand Down
25 changes: 25 additions & 0 deletions source/GameMenuState.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;

// in progress
// this class will replace the `GameSelectionState` in future
class GameMenuState extends FlxState
{
override function create()
{
super.create();

var bg = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, 0xFF444444);
bg.updateHitbox();
bg.scrollFactor.set();
add(bg);
}

override function update(elapsed:Float)
{
super.update(elapsed);
}
}
54 changes: 6 additions & 48 deletions source/GameSelectionState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ class GameSelectionState extends FlxState
var desc:FlxText;
var iconGame:Array<ModIcon> = [];
var cardGame:FlxSprite;
var aboutButton:FlxSprite;

override function create()
{
super.create();

GameHandler.resizeApp(640, 480); // based
GameHandler.resizeApp(640, 480);

var grid:FlxBackdrop = new FlxBackdrop(FlxGridOverlay.createGrid(80, 80, 160, 160, true, 0x33FFFFFF, 0x0));
grid.velocity.set(40, 40);
Expand Down Expand Up @@ -91,36 +90,25 @@ class GameSelectionState extends FlxState
versionDisplay.cameras = [camHUD];
add(versionDisplay);

aboutButton = new FlxSprite(16.3, -10.5);
aboutButton.frames = Paths.getSparrowAtlas("gameUI/aboutButton");
aboutButton.animation.addByPrefix("idle", "about_button0000");
aboutButton.animation.addByPrefix("selected", "about_button0", 24, false);
aboutButton.animation.addByPrefix("finishedAnim", "about_button0007", 24, false);
aboutButton.animation.play("idle");
aboutButton.cameras = [camHUD];
// add(aboutButton);

changeSelection();
// selectGame();
FlxG.camera.follow(camFollow, null, 0.15);
}

override function update(elapsed:Float)
{
super.update(elapsed);

if (FlxG.keys.justPressed.F5)
{
PolyHandler.reload();
FlxG.resetState();
}
handleKey();
// handleButton();
}

function handleKey()
{
var keys = FlxG.keys.justPressed;
if (keys.F5)
{
PolyHandler.reload();
FlxG.resetState();
}
if (keys.UP || keys.DOWN)
{
changeSelection((keys.UP) ? -1 : 1);
Expand All @@ -138,43 +126,13 @@ class GameSelectionState extends FlxState
FlxG.switchState(new CreditsState());
}
}
/*var gameSet:Dynamic = null;

// For `gameSet.json`
function selectGame()
{
gameSet = Json.parse("mods/gameSet.json");
if (gameSet.allowToLoadRN == true)
{
if (PolyHandler.getMods().contains(gameSet.gameLoad))
trace(PolyHandler.getMods().contains(gameSet.gameLoad));
// switchToGame();
}
}*/
function switchToGame()
{
PlayState.trackerFolder = curSelected;
FlxG.switchState(new PlayState());
}

function handleButton()
{
var mouse = FlxG.mouse;
if (mouse.overlaps(aboutButton))
{
aboutButton.animation.play("selected", true);
aboutButton.animation.finishCallback = function(name:String)
{
if (name == "selected")
aboutButton.animation.play("finishedAnim", true);
};
if (mouse.justPressed)
{
openSubState(new AboutClass());
}
}
}

function changeSelection(change:Int = 0)
{
curSelected = FlxMath.wrap(curSelected + change, 0, PolyHandler.trackedMods.length - 1);
Expand Down
5 changes: 4 additions & 1 deletion source/HScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class HScript extends Iris
{
return new FlxTypedGroup<Dynamic>();
});
set("FlxColor", GameHandler.colorWorkaround());
set("FlxKey", KeyWorkaround);
set("game", PlayState.instance);
set("state", FlxG.state);
set("add", FlxG.state.add);
Expand All @@ -86,9 +88,10 @@ class HScript extends Iris
}

// stop from warming missing function
// just found that i was using != instead of ==
public function callFunction(funcName:String, funcArgs:Array<Dynamic>)
{
if (funcName != null || !exists(funcName))
if (funcName == null || !exists(funcName))
return null;
return call(funcName, funcArgs);
}
Expand Down
17 changes: 14 additions & 3 deletions source/InitialState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@ package;
import flixel.FlxG;
import flixel.FlxState;
import haxe.Json;
import openfl.Assets;
import openfl.Lib;
import tjson.TJSON;

typedef InitialData =
{
playSplashesScreen:Bool,
}

// it checks if there are mods or not
// if there are mods, switch to game selector
class InitialState extends FlxState
{
public static var mustUpdate:Bool = false;
public static var daJson:Dynamic;
public static var gameConfig:InitialData;

override function create()
{
PolyHandler.reload();
updateCheck();

gameConfig = TJSON.parse(Assets.getText("gameConfig.json"));

if (PolyHandler.trackedMods.length > 0)
{
FlxG.switchState(new SplashesState());
if (!gameConfig.playSplashesScreen)
FlxG.switchState(new GameSelectionState());
else if (gameConfig.playSplashesScreen)
FlxG.switchState(new SplashesState());
}
else
{
Expand Down
Loading

0 comments on commit f08ade4

Please sign in to comment.