Skip to content

Commit dde08ac

Browse files
committed
we gucci
1 parent 227a9fd commit dde08ac

File tree

12 files changed

+972
-4
lines changed

12 files changed

+972
-4
lines changed

Project.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<set name="LIME_CAIRO" value="0" if="switch" />
2828
<set name="LIME_OPENGL" value="1" if="switch" />
2929
<icon path="art/SwitchIco.png" size='256' if="switch"/>
30+
<haxelib name="hx_libnx"/>
3031

3132
<!-- ____________________________ Window Settings ___________________________ -->
3233

source/Controls.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ class Controls extends FlxActionSet
566566
Control.NOTE_LEFT => [DPAD_LEFT, X, LEFT_STICK_DIGITAL_LEFT, RIGHT_STICK_DIGITAL_LEFT],
567567
Control.NOTE_RIGHT => [DPAD_RIGHT, B, LEFT_STICK_DIGITAL_RIGHT, RIGHT_STICK_DIGITAL_RIGHT],
568568
Control.PAUSE => [START],
569-
Control.RESET => [Y]
569+
//Control.RESET => [Y] // why is this even a thing what the flip man :()
570570
#if CAN_CHEAT
571571
,Control.CHEAT => [X]
572572
#end

source/FreeplayState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class FreeplayState extends MusicBeatState
283283
intendedScore = Highscore.getScore(songs[curSelected].songName, curDifficulty);
284284
// lerpScore = 0;
285285

286-
#if PRELOAD_ALL
286+
#if !switch
287287
FlxG.sound.playMusic(Paths.inst(songs[curSelected].songName), 0);
288288
#end
289289

source/Main.hx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import openfl.media.Video;
1414
import openfl.net.NetConnection;
1515
import openfl.net.NetStream;
1616

17+
#if switch
18+
import nx.NXMain;
19+
import nx.NXGame;
20+
#end
21+
1722
class Main extends Sprite
1823
{
1924
var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
@@ -73,18 +78,28 @@ class Main extends Sprite
7378

7479
if (zoom == -1)
7580
{
81+
#if switch
82+
zoom = 1;
83+
#else
7684
var ratioX:Float = stageWidth / gameWidth;
7785
var ratioY:Float = stageHeight / gameHeight;
7886
zoom = Math.min(ratioX, ratioY);
7987
gameWidth = Math.ceil(stageWidth / zoom);
8088
gameHeight = Math.ceil(stageHeight / zoom);
89+
#end
8190
}
8291

8392
#if !debug
8493
initialState = TitleState;
8594
#end
8695

96+
#if switch
97+
Sys.setCwd("romfs:/");
98+
NXMain.init();
99+
addChild(new NXGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
100+
#else
87101
addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
102+
#end
88103

89104
#if !mobile
90105
fpsCounter = new FPS(10, 3, 0xFFFFFF);

source/PlayState.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class PlayState extends MusicBeatState
174174
camHUD.bgColor.alpha = 0;
175175

176176
FlxG.cameras.reset(camGame);
177+
FlxG.cameras.setDefaultDrawTarget(camGame, true);
177178
FlxG.cameras.add(camHUD, false);
178179

179180
persistentUpdate = true;

source/TitleState.hx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class TitleState extends MusicBeatState
371371
if (FlxG.keys.justPressed.F)
372372
FlxG.fullscreen = !FlxG.fullscreen;
373373

374-
var pressedEnter:Bool = FlxG.keys.justPressed.ENTER;
374+
var pressedEnter:Bool = FlxG.keys.justPressed.ENTER || controls.ACCEPT;
375375

376376
#if mobile
377377
for (touch in FlxG.touches.list)
@@ -394,6 +394,14 @@ class TitleState extends MusicBeatState
394394
#end
395395
}
396396

397+
#if switch
398+
if (NXMain.nxController != null) {
399+
if (NXMain.nxController.isJustPressed(NXControlButton.A) ||
400+
NXMain.nxController.isJustPressed(NXControlButton.PLUS))
401+
pressedEnter = true;
402+
}
403+
#end
404+
397405
if (pressedEnter && !transitioning && skippedIntro)
398406
{
399407
if (FlxG.sound.music != null)

source/import.hx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
import Paths;
1+
#if !macro
2+
import cpp.*;
3+
4+
// Nintendo Switch imports
5+
#if switch
6+
import switchLib.Result;
7+
import switchLib.Types.ResultType;
8+
import switchLib.runtime.Pad;
9+
import switchLib.services.Hid;
10+
import switchLib.arm.Counter;
11+
import switchLib.services.Applet;
12+
13+
import nx.NXMain;
14+
import nx.NXGame;
15+
import nx.controls.NXController;
16+
import nx.controls.NXControlButton;
17+
import nx.controls.NXVibrationHD;
18+
#end
19+
20+
// Flixel
21+
import flixel.FlxG;
22+
import flixel.FlxSprite;
23+
import flixel.math.FlxMath;
24+
import flixel.util.FlxColor;
25+
import flixel.util.FlxTimer;
26+
import flixel.text.FlxText;
27+
import flixel.tweens.FlxEase;
28+
import flixel.tweens.FlxTween;
29+
import flixel.group.FlxSpriteGroup;
30+
import flixel.group.FlxGroup.FlxTypedGroup;
31+
32+
#if sys
33+
import sys.*;
34+
import sys.io.*;
35+
#end
36+
37+
using StringTools;
38+
#end

source/nx/NXGame.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package nx;
2+
3+
import flixel.FlxGame;
4+
5+
class NXGame extends FlxGame {
6+
override public function update() {
7+
NXMain.update();
8+
super.update();
9+
}
10+
}

source/nx/NXMain.hx

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package nx;
2+
3+
import nx.controls.NXController;
4+
5+
/**
6+
* States of the applet
7+
*/
8+
enum AppletStateMode {
9+
/**
10+
* The applet/program is in focus
11+
*/
12+
APP_IN_FOCUS;
13+
14+
/**
15+
* The applet/program is out of focus
16+
*/
17+
APP_OUT_OF_FOCUS;
18+
19+
/**
20+
* The applet/program is suspended (In HOME menu or the console is sleeping)
21+
*/
22+
APP_SUSPENDED;
23+
24+
/**
25+
* Unknown state
26+
*/
27+
APP_UNKNOWN;
28+
}
29+
30+
/**
31+
* Main class for Nintendo Switch functionality
32+
*
33+
* Ported from Switch-Funkin
34+
*/
35+
class NXMain {
36+
/**
37+
* Controller manager for Nintendo Switch controllers
38+
*/
39+
public static var nxController:NXController = null;
40+
41+
/**
42+
* Initialize Nintendo Switch systems
43+
*/
44+
public static function init() {
45+
#if switch
46+
nxController = new NXController();
47+
#end
48+
}
49+
50+
/**
51+
* Update Nintendo Switch systems - called every frame
52+
*/
53+
public static function update() {
54+
#if switch
55+
if (nxController != null) {
56+
nxController.update();
57+
}
58+
#end
59+
}
60+
61+
/**
62+
* Clean up Nintendo Switch systems
63+
*/
64+
public static function destroy() {
65+
#if switch
66+
if (nxController != null) {
67+
nxController.destroy();
68+
}
69+
#end
70+
}
71+
72+
/**
73+
* Checks if the console is docked (TV mode)
74+
*/
75+
public static var IS_DOCKED(get, never):Bool;
76+
private static function get_IS_DOCKED():Bool {
77+
#if switch
78+
return Applet.appletGetOperationMode() == AppletOperationMode.AppletOperationMode_Console;
79+
#else
80+
return false;
81+
#end
82+
}
83+
84+
/**
85+
* The current applet state
86+
*/
87+
public static var appState(get, never):AppletStateMode;
88+
private static function get_appState():AppletStateMode {
89+
#if switch
90+
return switch (Applet.appletGetFocusState()) {
91+
case AppletFocusState.AppletFocusState_InFocus: AppletStateMode.APP_IN_FOCUS;
92+
case AppletFocusState.AppletFocusState_OutOfFocus: AppletStateMode.APP_OUT_OF_FOCUS;
93+
case AppletFocusState.AppletFocusState_Background: AppletStateMode.APP_SUSPENDED;
94+
default: AppletStateMode.APP_UNKNOWN;
95+
}
96+
#else
97+
return AppletStateMode.APP_UNKNOWN;
98+
#end
99+
}
100+
101+
/**
102+
* Checks if the application is running in Applet mode (limited memory)
103+
* @return Bool
104+
*/
105+
public static function isRunningAsApplet():Bool {
106+
#if switch
107+
return Applet.appletGetAppletType() != AppletType.AppletType_Application
108+
&& Applet.appletGetAppletType() != AppletType.AppletType_SystemApplication;
109+
#else
110+
return false;
111+
#end
112+
}
113+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package nx.controls;
2+
3+
/**
4+
* Joycon type (left or right)
5+
*/
6+
enum NXJoyCon {
7+
LEFT;
8+
RIGHT;
9+
}
10+
11+
/**
12+
* A list of all possible buttons of Nintendo Switch controllers
13+
*
14+
* Ported from Vupx Engine
15+
*
16+
* Author: Slushi
17+
*/
18+
19+
enum NXControlButton {
20+
A;
21+
B;
22+
X;
23+
Y;
24+
STICK_L;
25+
STICK_R;
26+
L;
27+
R;
28+
ZL;
29+
ZR;
30+
PLUS;
31+
MINUS;
32+
LEFT;
33+
UP;
34+
RIGHT;
35+
DOWN;
36+
STICK_L_LEFT;
37+
STICK_L_UP;
38+
STICK_L_RIGHT;
39+
STICK_L_DOWN;
40+
STICK_R_LEFT;
41+
STICK_R_UP;
42+
STICK_R_RIGHT;
43+
STICK_R_DOWN;
44+
LEFT_SL;
45+
LEFT_SR;
46+
RIGHT_SL;
47+
RIGHT_SR;
48+
PALMA;
49+
VERIFICATION;
50+
HANDHELD_LEFT_B;
51+
LAGON_C_LEFT;
52+
LAGON_C_UP;
53+
LAGON_C_RIGHT;
54+
LAGON_C_DOWN;
55+
ANY_LEFT;
56+
ANY_UP;
57+
ANY_RIGHT;
58+
ANY_DOWN;
59+
ANY_SL;
60+
ANY_SR;
61+
}

0 commit comments

Comments
 (0)