@mathewodwyer/gm-states 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # GM States
2
+
3
+ A minimal finite state machine for GameMaker.
4
+
5
+ Each state is a single function that receives what's happening (enter, exit, step, end step), so all of a state's logic lives in one place.
6
+
7
+ ## Requirements
8
+
9
+ - GameMaker 2026.1 or newer.
10
+
11
+ ## Installation
12
+
13
+ 1. Open **Tools → Package Manager** and make sure `https://registry.npmjs.org/` is listed as a source.
14
+ 2. Search for `@mathewodwyer/gm-states` and install it.
15
+ 3. In the **Prefab Library**, right-click the collection and choose **Add Collection Reference**. This makes `StateMachine` and `state_type` available in your code.
16
+
17
+ ## Quick Start
18
+
19
+ ### 1. Define your states
20
+
21
+ Use any values to identify states. An enum works well:
22
+
23
+ ```gml
24
+ enum player_state
25
+ {
26
+ idle,
27
+ walk,
28
+ }
29
+ ```
30
+
31
+ ### 2. Create the state machine
32
+
33
+ In the object's **Create event**, add each state with a name, its identifier, and an action. The action receives a `state_type` telling it what's happening:
34
+
35
+ ```gml
36
+ sm = new StateMachine();
37
+
38
+ sm.add_state("Idle", player_state.idle, function(type)
39
+ {
40
+ switch (type)
41
+ {
42
+ case state_type.on_enter:
43
+ sprite_index = spr_player_idle;
44
+ break;
45
+
46
+ case state_type.on_step:
47
+ if (keyboard_check(vk_right)) sm.set_state(player_state.walk);
48
+ break;
49
+ }
50
+ });
51
+
52
+ sm.add_state("Walk", player_state.walk, function(type)
53
+ {
54
+ switch (type)
55
+ {
56
+ case state_type.on_enter:
57
+ sprite_index = spr_player_walk;
58
+ break;
59
+
60
+ case state_type.on_step:
61
+ x += 2;
62
+ if (!keyboard_check(vk_right)) sm.set_state(player_state.idle);
63
+ break;
64
+
65
+ case state_type.on_exit:
66
+ // Clean up before leaving the state
67
+ break;
68
+ }
69
+ });
70
+
71
+ sm.set_state(player_state.idle);
72
+ ```
73
+
74
+ Functions declared in the Create event are bound to the instance, so actions can use instance variables such as `x` and `sprite_index` directly.
75
+
76
+ ### 3. Run it
77
+
78
+ **Step event**
79
+
80
+ ```gml
81
+ sm.run_state(state_type.on_step);
82
+ ```
83
+
84
+ **End Step event** (optional)
85
+
86
+ ```gml
87
+ sm.run_state(state_type.on_step_end);
88
+ ```
89
+
90
+ `on_enter` and `on_exit` run automatically whenever `set_state` changes the state. Setting the state it's already in does nothing.
91
+
92
+ ### 4. Debugging
93
+
94
+ ```gml
95
+ draw_text(x, y - 20, sm.get_name()); // "Idle", "Walk", ...
96
+ ```
Binary file
package/licence.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mathew O"Dwyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
- {
2
- "name": "@mathewodwyer/gm-states",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
1
+ {
2
+ "name": "@mathewodwyer/gm-states",
3
+ "version": "2.0.0",
4
+ "description": "A minimal finite state machine for GameMaker.\r\n\r\nEach state is a single function that receives what's happening (enter, exit, step, end step), so all of a state's logic lives in one place.",
5
+ "files": [
6
+ "gm-states-2.0.0.yymps"
7
+ ],
8
+ "keywords": [
9
+ "Prefab",
10
+ "gm-states"
11
+ ],
12
+ "author": "Mathew O'Dwyer",
13
+ "license": "SEE LICENSE IN licence.txt",
14
+ "gm": {
15
+ "destination": "mathewodwyer/gm-states",
16
+ "icon": {
17
+ "mime": "image/png",
18
+ "data": "iVBORw0KGgoAAAANSUhEUgAAAKwAAACsCAYAAADmMUfYAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAGYktHRAD/AP8A/6C9p5MAAAeKSURBVHja7d3JUhNtGMXxo2IWGWDv0rVLB4QwRWUjQ4eIN+LGi7DKe3BWwAmSKFMY3HkvlgOo3VD1ukh1xe9TSUO6+3mft8+/6uykeJL8oHolpwAYMKak09IHMHacCJapimCZqgiWqYpgmaoIlqmKYJmqCJapimCZqgiWqYpgmaoIlqmKYGNscnISS0tLyOVy0qc4neF63+TkpNnf3zfGGNNoNEwulxO/ydGJH6B+v2MNI1qCtXI3btz4A2tYvV4nWoK1Z0dhJVqCtWpRsBItwVqx42AlWoIV3fXr14+NNWxlZYVoCVYHVqIl2FR37dq1nrESLcGqwxq2vLxMtASrAyvREqw6rERLsLGuUqkkjjXs7du3REuwOrASLcH2tImJidSxEi3BqsMa9ubNG6IlWB1YiZZg1WElWoI9cuPj49ZhDXv9+jXREqwOrERLsOqwEi3BGgBmbGxMDdawV69eEW0WwWrESrQZBasZK9FmDOzo6Kh6rGEvX77MMlrxA4iVaAnWZawZRyt+ALH20NLSUtbQih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AodEVYdGRhdGU6dGltZXN0YW1wADIwMjYtMTEtMjlUMDQ6NDg6NDErMDA6MDCibdy4AAAAAElFTkSuQmCC"
19
+ },
20
+ "displayName": "GM States",
21
+ "shortDescription": "A minimal finite state machine for GameMaker.",
22
+ "visible": true,
23
+ "ide_versions": {
24
+ "LTS": ">=2026.1.1"
25
+ },
26
+ "supportedArchitecture": "any",
27
+ "removeDependenciesOnUninstall": "always",
28
+ "notifyOfUpdates": true,
29
+ "requiresRestart": false
30
+ }
6
31
  }