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+ }
0 commit comments