@killscript/sdk 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KILLSCRIPT contributors
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/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @killscript/sdk
2
+
3
+ Compile-time settings, controls and optional convenience wrappers for
4
+ KILLSCRIPT TypeScript modules. Use it through the `killscript` CLI.
5
+
6
+ ```ts
7
+ import {
8
+ Keyboard,
9
+ agents,
10
+ defineControls,
11
+ defineSettings,
12
+ scheduler,
13
+ setting,
14
+ } from "@killscript/sdk/client";
15
+
16
+ const settings = defineSettings("camera", {
17
+ enabled: true,
18
+ speed: setting(5, { min: 1, max: 20 }),
19
+ });
20
+ const controls = defineControls("camera", { toggle: Keyboard.F6 });
21
+
22
+ controls.toggle.onPressed(() => { settings.enabled = !settings.enabled; });
23
+ scheduler.frame(() => {
24
+ if (settings.enabled) agents.local();
25
+ });
26
+ ```
27
+
28
+ The SDK also provides ordered Reflex message batching, prefixed/rate-limited
29
+ logging, control interactions and chords, cancellable scheduling, agent
30
+ selections, configured world visuals and lifecycle scopes. Each helper is
31
+ lowered to native KILLSCRIPT calls or a small generated Lua helper; the raw API
32
+ always remains available.
33
+
34
+ Settings, controls and wrappers are compiler macros: they lower to the native
35
+ game API and do not ship an SDK framework in the generated Lua. The raw API is
36
+ always available through `@killscript/types`.
37
+
38
+ Use `@killscript/sdk/client` for client features, `@killscript/sdk/server` for
39
+ Reflex, and the root entry for shared settings, typed networking, array helpers
40
+ and math helpers. Read the [SDK documentation](https://silentbless.github.io/killscript/).
41
+ Licensed under MIT.
@@ -0,0 +1,148 @@
1
+ // src/internal.ts
2
+ var compilerMacro = /* @__PURE__ */ Symbol.for("killscript.compiler-macro");
3
+ function macroOnly(name) {
4
+ throw new Error(
5
+ `${name} is a KILLSCRIPT compiler macro and cannot be executed directly. Run the project through the killscript CLI.`
6
+ );
7
+ }
8
+
9
+ // src/settings.ts
10
+ function setting(defaultValue, options) {
11
+ return {
12
+ [compilerMacro]: "setting",
13
+ defaultValue,
14
+ ...options === void 0 ? {} : { options }
15
+ };
16
+ }
17
+ ((setting2) => {
18
+ function choice(choices, defaultValue, options) {
19
+ return {
20
+ [compilerMacro]: "setting",
21
+ kind: "choice",
22
+ choices,
23
+ defaultValue,
24
+ ...options === void 0 ? {} : { options }
25
+ };
26
+ }
27
+ setting2.choice = choice;
28
+ function flags(choices, defaultFlags = [], options) {
29
+ return {
30
+ [compilerMacro]: "setting",
31
+ kind: "flags",
32
+ choices,
33
+ defaultFlags,
34
+ defaultValue: 0,
35
+ ...options === void 0 ? {} : { options }
36
+ };
37
+ }
38
+ setting2.flags = flags;
39
+ function color(value, options) {
40
+ const rgba = parseColor(value);
41
+ return {
42
+ [compilerMacro]: "setting",
43
+ kind: "color",
44
+ rgba,
45
+ defaultValue: macroOnly("setting.color value"),
46
+ ...options === void 0 ? {} : { options }
47
+ };
48
+ }
49
+ setting2.color = color;
50
+ })(setting || (setting = {}));
51
+ function defineSettings(..._args) {
52
+ return macroOnly("defineSettings");
53
+ }
54
+ function parseColor(value) {
55
+ if (typeof value !== "string") {
56
+ return [value[0], value[1], value[2], value[3] ?? 1];
57
+ }
58
+ const normalized = value.startsWith("#") ? value.slice(1) : value;
59
+ if (!/^[\da-f]{6}([\da-f]{2})?$/i.test(normalized)) {
60
+ throw new Error(`Invalid color '${value}'. Use #RRGGBB or #RRGGBBAA.`);
61
+ }
62
+ return [
63
+ Number.parseInt(normalized.slice(0, 2), 16) / 255,
64
+ Number.parseInt(normalized.slice(2, 4), 16) / 255,
65
+ Number.parseInt(normalized.slice(4, 6), 16) / 255,
66
+ normalized.length === 8 ? Number.parseInt(normalized.slice(6, 8), 16) / 255 : 1
67
+ ];
68
+ }
69
+
70
+ // src/arrays.ts
71
+ var arrays = {
72
+ forEach(values, callback) {
73
+ macroOnly("arrays.forEach");
74
+ },
75
+ some(values, predicate) {
76
+ return macroOnly("arrays.some");
77
+ },
78
+ every(values, predicate) {
79
+ return macroOnly("arrays.every");
80
+ },
81
+ find(values, predicate) {
82
+ return macroOnly("arrays.find");
83
+ },
84
+ map(values, transform) {
85
+ return macroOnly("arrays.map");
86
+ },
87
+ filter(values, predicate) {
88
+ return macroOnly("arrays.filter");
89
+ },
90
+ toArray(values) {
91
+ return macroOnly("arrays.toArray");
92
+ },
93
+ first(values) {
94
+ return macroOnly("arrays.first");
95
+ },
96
+ last(values) {
97
+ return macroOnly("arrays.last");
98
+ }
99
+ };
100
+
101
+ // src/logging.ts
102
+ function logger(name) {
103
+ return macroOnly("logger");
104
+ }
105
+
106
+ // src/math.ts
107
+ var vector2 = {
108
+ add(left, right) {
109
+ return macroOnly("vector2.add");
110
+ },
111
+ subtract(left, right) {
112
+ return macroOnly("vector2.subtract");
113
+ }
114
+ };
115
+ var vector3 = {
116
+ add(left, right) {
117
+ return macroOnly("vector3.add");
118
+ },
119
+ subtract(left, right) {
120
+ return macroOnly("vector3.subtract");
121
+ }
122
+ };
123
+ var quaternion = {
124
+ multiply(left, right) {
125
+ return macroOnly("quaternion.multiply");
126
+ },
127
+ rotate(rotation, value) {
128
+ return macroOnly("quaternion.rotate");
129
+ }
130
+ };
131
+
132
+ // src/network.ts
133
+ function defineNetwork(..._args) {
134
+ return macroOnly("defineNetwork");
135
+ }
136
+
137
+ export {
138
+ compilerMacro,
139
+ macroOnly,
140
+ setting,
141
+ defineSettings,
142
+ arrays,
143
+ logger,
144
+ vector2,
145
+ vector3,
146
+ quaternion,
147
+ defineNetwork
148
+ };
@@ -0,0 +1,237 @@
1
+ import { i as compilerMacro, S as Scope, A as AgentSelection } from './index-C8VwPmhn.js';
2
+ export { C as ChoiceDefinition, a as ColorDefinition, F as FlagsDefinition, L as Logger, M as MessageMap, N as NetworkChannel, b as SettingDefinition, c as SettingOptions, d as SettingsHandle, e as arrays, f as defineNetwork, g as defineSettings, l as logger, q as quaternion, s as setting, v as vector2, h as vector3 } from './index-C8VwPmhn.js';
3
+
4
+ type ControlType = "Button" | "Value" | "PassThrough";
5
+ interface Binding {
6
+ readonly path: string;
7
+ readonly interactions?: string;
8
+ readonly processors?: string;
9
+ readonly groups?: string;
10
+ }
11
+ interface ControlDefinition {
12
+ readonly [compilerMacro]: "control";
13
+ readonly type: ControlType;
14
+ readonly binding: Binding;
15
+ }
16
+ type ControlInput = string | ControlDefinition;
17
+ interface ControlHandle {
18
+ onPressed(callback: () => void): void;
19
+ /** Watches the polled state and calls back on both press and release. */
20
+ onChanged(callback: (pressed: boolean) => void): EventSubscription;
21
+ /** Calls back when a pressed action is released. */
22
+ onReleased(callback: () => void): EventSubscription;
23
+ /** Calls back on every client frame while the action is pressed. */
24
+ whilePressed(callback: () => void): EventSubscription;
25
+ isPressed(): boolean;
26
+ native(): InputAction | undefined;
27
+ }
28
+ type InputReference = ControlHandle | InputAction;
29
+ interface ToggleState {
30
+ readonly value: boolean;
31
+ set(value: boolean): void;
32
+ flip(): boolean;
33
+ }
34
+ type ControlsHandle<TSchema extends Record<string, ControlInput>> = {
35
+ readonly [TKey in keyof TSchema]: ControlHandle;
36
+ };
37
+ declare function control(binding: string | Binding, options?: {
38
+ readonly type?: ControlType;
39
+ }): ControlDefinition;
40
+ declare namespace control {
41
+ function raw(definition: Omit<ControlDefinition, typeof compilerMacro>): ControlDefinition;
42
+ function hold(binding: string | Binding, duration?: number): ControlDefinition;
43
+ function tap(binding: string | Binding, duration?: number): ControlDefinition;
44
+ function multiTap(binding: string | Binding, tapCount?: number, maxDelay?: number): ControlDefinition;
45
+ function onRelease(binding: string | Binding): ControlDefinition;
46
+ }
47
+ declare function defineControls<const TSchema extends Record<string, ControlInput>>(schema: TSchema): ControlsHandle<TSchema>;
48
+ declare function defineControls<const TNamespace extends string, const TSchema extends Record<string, ControlInput>>(namespace: TNamespace, schema: TSchema): ControlsHandle<TSchema>;
49
+ declare const input: {
50
+ anyPressed(actions: readonly InputReference[]): boolean;
51
+ allPressed(actions: readonly InputReference[]): boolean;
52
+ onAnyPressed(actions: readonly InputReference[], callback: () => void): EventSubscription;
53
+ onChord(actions: readonly InputReference[], callback: () => void): EventSubscription;
54
+ toggle(action: InputReference, initialValue?: boolean, callback?: (value: boolean) => void): ToggleState;
55
+ };
56
+ declare const Keyboard: {
57
+ readonly A: string;
58
+ readonly B: string;
59
+ readonly C: string;
60
+ readonly D: string;
61
+ readonly E: string;
62
+ readonly F: string;
63
+ readonly G: string;
64
+ readonly H: string;
65
+ readonly I: string;
66
+ readonly J: string;
67
+ readonly K: string;
68
+ readonly L: string;
69
+ readonly M: string;
70
+ readonly N: string;
71
+ readonly O: string;
72
+ readonly P: string;
73
+ readonly Q: string;
74
+ readonly R: string;
75
+ readonly S: string;
76
+ readonly T: string;
77
+ readonly U: string;
78
+ readonly V: string;
79
+ readonly W: string;
80
+ readonly X: string;
81
+ readonly Y: string;
82
+ readonly Z: string;
83
+ readonly F1: string;
84
+ readonly F2: string;
85
+ readonly F3: string;
86
+ readonly F4: string;
87
+ readonly F5: string;
88
+ readonly F6: string;
89
+ readonly F7: string;
90
+ readonly F8: string;
91
+ readonly F9: string;
92
+ readonly F10: string;
93
+ readonly F11: string;
94
+ readonly F12: string;
95
+ readonly Space: string;
96
+ readonly Enter: string;
97
+ readonly Escape: string;
98
+ readonly Tab: string;
99
+ readonly Backspace: string;
100
+ readonly LeftShift: string;
101
+ readonly RightShift: string;
102
+ readonly LeftCtrl: string;
103
+ readonly RightCtrl: string;
104
+ readonly LeftAlt: string;
105
+ readonly RightAlt: string;
106
+ readonly Up: string;
107
+ readonly Down: string;
108
+ readonly Left: string;
109
+ readonly Right: string;
110
+ readonly Digit0: string;
111
+ readonly Digit1: string;
112
+ readonly Digit2: string;
113
+ readonly Digit3: string;
114
+ readonly Digit4: string;
115
+ readonly Digit5: string;
116
+ readonly Digit6: string;
117
+ readonly Digit7: string;
118
+ readonly Digit8: string;
119
+ readonly Digit9: string;
120
+ readonly Home: string;
121
+ readonly End: string;
122
+ readonly PageUp: string;
123
+ readonly PageDown: string;
124
+ readonly Insert: string;
125
+ readonly Delete: string;
126
+ readonly CapsLock: string;
127
+ readonly Comma: string;
128
+ readonly Period: string;
129
+ readonly Slash: string;
130
+ readonly Semicolon: string;
131
+ readonly Quote: string;
132
+ readonly Backquote: string;
133
+ readonly Minus: string;
134
+ readonly Equals: string;
135
+ readonly LeftBracket: string;
136
+ readonly RightBracket: string;
137
+ readonly Backslash: string;
138
+ };
139
+ declare const Mouse: {
140
+ readonly Left: "<Mouse>/leftButton";
141
+ readonly Right: "<Mouse>/rightButton";
142
+ readonly Middle: "<Mouse>/middleButton";
143
+ readonly Back: "<Mouse>/backButton";
144
+ readonly Forward: "<Mouse>/forwardButton";
145
+ readonly Scroll: "<Mouse>/scroll";
146
+ readonly Delta: "<Mouse>/delta";
147
+ readonly Position: "<Mouse>/position";
148
+ };
149
+ declare const Gamepad: {
150
+ readonly South: "<Gamepad>/buttonSouth";
151
+ readonly East: "<Gamepad>/buttonEast";
152
+ readonly West: "<Gamepad>/buttonWest";
153
+ readonly North: "<Gamepad>/buttonNorth";
154
+ readonly LeftShoulder: "<Gamepad>/leftShoulder";
155
+ readonly RightShoulder: "<Gamepad>/rightShoulder";
156
+ readonly LeftTrigger: "<Gamepad>/leftTrigger";
157
+ readonly RightTrigger: "<Gamepad>/rightTrigger";
158
+ readonly LeftStick: "<Gamepad>/leftStick";
159
+ readonly RightStick: "<Gamepad>/rightStick";
160
+ readonly LeftStickPress: "<Gamepad>/leftStickPress";
161
+ readonly RightStickPress: "<Gamepad>/rightStickPress";
162
+ readonly Dpad: "<Gamepad>/dpad";
163
+ readonly DpadUp: "<Gamepad>/dpad/up";
164
+ readonly DpadDown: "<Gamepad>/dpad/down";
165
+ readonly DpadLeft: "<Gamepad>/dpad/left";
166
+ readonly DpadRight: "<Gamepad>/dpad/right";
167
+ readonly Start: "<Gamepad>/start";
168
+ readonly Select: "<Gamepad>/select";
169
+ };
170
+
171
+ interface LineOptions {
172
+ readonly points: readonly Vector3[];
173
+ readonly color?: Color;
174
+ readonly width?: number;
175
+ readonly progress?: number;
176
+ readonly patternEnabled?: boolean;
177
+ readonly patternRepeat?: number;
178
+ readonly patternTexture?: Texture;
179
+ readonly occludedBrightness?: number;
180
+ readonly occludedTransparency?: number;
181
+ /** Automatically removes the object after this many seconds. */
182
+ readonly duration?: number;
183
+ }
184
+ interface OverlayOptions {
185
+ readonly position: Vector3;
186
+ readonly size: Vector3;
187
+ readonly color?: Color;
188
+ readonly fillBase?: number;
189
+ readonly occlusionEnabled?: boolean;
190
+ readonly visible?: boolean;
191
+ /** Automatically removes the object after this many seconds. */
192
+ readonly duration?: number;
193
+ }
194
+ declare const visuals: {
195
+ line(options: LineOptions): LineRenderer | undefined;
196
+ overlay(options: OverlayOptions): SurfaceOverlay | undefined;
197
+ remove(object: WorldObject | undefined): void;
198
+ };
199
+
200
+ interface ClientScope extends Scope {
201
+ /** Tracks a world visual and removes it when dispose() is called. */
202
+ world<T extends WorldObject | undefined>(object: T): T;
203
+ }
204
+ declare function scope(): ClientScope;
205
+ declare const agents: {
206
+ local(): Agent | undefined;
207
+ localOrSpectated(): Agent | undefined;
208
+ all(): LuaArray<Agent>;
209
+ allies(): LuaArray<Agent>;
210
+ enemies(): LuaArray<Agent>;
211
+ select(values?: LuaArray<Agent> | readonly Agent[]): AgentSelection;
212
+ };
213
+ declare const scheduler: {
214
+ frame(callback: () => void): EventSubscription;
215
+ after(seconds: number, callback: () => void): void;
216
+ afterTicks(ticks: number, callback: () => void): EventSubscription;
217
+ every(seconds: number, callback: () => void): EventSubscription;
218
+ everyTicks(ticks: number, callback: () => void): EventSubscription;
219
+ until(predicate: () => boolean, callback: () => void): EventSubscription;
220
+ debounce(key: string, seconds: number, callback: () => void): void;
221
+ throttle(key: string, seconds: number, callback: () => void): boolean;
222
+ };
223
+ declare const camera: {
224
+ main(): Camera;
225
+ create(): Camera | undefined;
226
+ remove(value: Camera): void;
227
+ };
228
+ declare const time: {
229
+ seconds(): number;
230
+ tick(): number;
231
+ toTicks(seconds: number): number;
232
+ toSeconds(ticks: number): number;
233
+ /** Converts seconds without the native SecondsToTick floating-point undercount. */
234
+ ceilTicks(seconds: number): number;
235
+ };
236
+
237
+ export { AgentSelection, type Binding, type ClientScope, type ControlDefinition, type ControlHandle, type ControlType, type ControlsHandle, Gamepad, type InputReference, Keyboard, type LineOptions, Mouse, type OverlayOptions, Scope, type ToggleState, agents, camera, control, defineControls, input, scheduler, scope, time, visuals };
package/dist/client.js ADDED
@@ -0,0 +1,305 @@
1
+ import {
2
+ arrays,
3
+ compilerMacro,
4
+ defineNetwork,
5
+ defineSettings,
6
+ logger,
7
+ macroOnly,
8
+ quaternion,
9
+ setting,
10
+ vector2,
11
+ vector3
12
+ } from "./chunk-6XHZVS7S.js";
13
+
14
+ // src/controls.ts
15
+ function control(binding, options = {}) {
16
+ return {
17
+ [compilerMacro]: "control",
18
+ type: options.type ?? "Button",
19
+ binding: typeof binding === "string" ? { path: binding } : binding
20
+ };
21
+ }
22
+ ((control2) => {
23
+ function raw(definition) {
24
+ return {
25
+ [compilerMacro]: "control",
26
+ ...definition
27
+ };
28
+ }
29
+ control2.raw = raw;
30
+ function hold(binding, duration = 0.4) {
31
+ const resolved = typeof binding === "string" ? { path: binding } : binding;
32
+ return control2({ ...resolved, interactions: `hold(duration=${duration})` });
33
+ }
34
+ control2.hold = hold;
35
+ function tap(binding, duration = 0.2) {
36
+ const resolved = typeof binding === "string" ? { path: binding } : binding;
37
+ return control2({ ...resolved, interactions: `tap(duration=${duration})` });
38
+ }
39
+ control2.tap = tap;
40
+ function multiTap(binding, tapCount = 2, maxDelay = 0.3) {
41
+ const resolved = typeof binding === "string" ? { path: binding } : binding;
42
+ return control2({
43
+ ...resolved,
44
+ interactions: `multiTap(tapCount=${tapCount},tapDelay=${maxDelay})`
45
+ });
46
+ }
47
+ control2.multiTap = multiTap;
48
+ function onRelease(binding) {
49
+ const resolved = typeof binding === "string" ? { path: binding } : binding;
50
+ return control2({ ...resolved, interactions: "press(behavior=1)" });
51
+ }
52
+ control2.onRelease = onRelease;
53
+ })(control || (control = {}));
54
+ function defineControls(..._args) {
55
+ return macroOnly("defineControls");
56
+ }
57
+ var input = {
58
+ anyPressed(actions) {
59
+ return macroOnly("input.anyPressed");
60
+ },
61
+ allPressed(actions) {
62
+ return macroOnly("input.allPressed");
63
+ },
64
+ onAnyPressed(actions, callback) {
65
+ return macroOnly("input.onAnyPressed");
66
+ },
67
+ onChord(actions, callback) {
68
+ return macroOnly("input.onChord");
69
+ },
70
+ toggle(action, initialValue, callback) {
71
+ return macroOnly("input.toggle");
72
+ }
73
+ };
74
+ function keyboard(path) {
75
+ return `<Keyboard>/${path}`;
76
+ }
77
+ var Keyboard = {
78
+ A: keyboard("a"),
79
+ B: keyboard("b"),
80
+ C: keyboard("c"),
81
+ D: keyboard("d"),
82
+ E: keyboard("e"),
83
+ F: keyboard("f"),
84
+ G: keyboard("g"),
85
+ H: keyboard("h"),
86
+ I: keyboard("i"),
87
+ J: keyboard("j"),
88
+ K: keyboard("k"),
89
+ L: keyboard("l"),
90
+ M: keyboard("m"),
91
+ N: keyboard("n"),
92
+ O: keyboard("o"),
93
+ P: keyboard("p"),
94
+ Q: keyboard("q"),
95
+ R: keyboard("r"),
96
+ S: keyboard("s"),
97
+ T: keyboard("t"),
98
+ U: keyboard("u"),
99
+ V: keyboard("v"),
100
+ W: keyboard("w"),
101
+ X: keyboard("x"),
102
+ Y: keyboard("y"),
103
+ Z: keyboard("z"),
104
+ F1: keyboard("f1"),
105
+ F2: keyboard("f2"),
106
+ F3: keyboard("f3"),
107
+ F4: keyboard("f4"),
108
+ F5: keyboard("f5"),
109
+ F6: keyboard("f6"),
110
+ F7: keyboard("f7"),
111
+ F8: keyboard("f8"),
112
+ F9: keyboard("f9"),
113
+ F10: keyboard("f10"),
114
+ F11: keyboard("f11"),
115
+ F12: keyboard("f12"),
116
+ Space: keyboard("space"),
117
+ Enter: keyboard("enter"),
118
+ Escape: keyboard("escape"),
119
+ Tab: keyboard("tab"),
120
+ Backspace: keyboard("backspace"),
121
+ LeftShift: keyboard("leftShift"),
122
+ RightShift: keyboard("rightShift"),
123
+ LeftCtrl: keyboard("leftCtrl"),
124
+ RightCtrl: keyboard("rightCtrl"),
125
+ LeftAlt: keyboard("leftAlt"),
126
+ RightAlt: keyboard("rightAlt"),
127
+ Up: keyboard("upArrow"),
128
+ Down: keyboard("downArrow"),
129
+ Left: keyboard("leftArrow"),
130
+ Right: keyboard("rightArrow"),
131
+ Digit0: keyboard("0"),
132
+ Digit1: keyboard("1"),
133
+ Digit2: keyboard("2"),
134
+ Digit3: keyboard("3"),
135
+ Digit4: keyboard("4"),
136
+ Digit5: keyboard("5"),
137
+ Digit6: keyboard("6"),
138
+ Digit7: keyboard("7"),
139
+ Digit8: keyboard("8"),
140
+ Digit9: keyboard("9"),
141
+ Home: keyboard("home"),
142
+ End: keyboard("end"),
143
+ PageUp: keyboard("pageUp"),
144
+ PageDown: keyboard("pageDown"),
145
+ Insert: keyboard("insert"),
146
+ Delete: keyboard("delete"),
147
+ CapsLock: keyboard("capsLock"),
148
+ Comma: keyboard("comma"),
149
+ Period: keyboard("period"),
150
+ Slash: keyboard("slash"),
151
+ Semicolon: keyboard("semicolon"),
152
+ Quote: keyboard("quote"),
153
+ Backquote: keyboard("backquote"),
154
+ Minus: keyboard("minus"),
155
+ Equals: keyboard("equals"),
156
+ LeftBracket: keyboard("leftBracket"),
157
+ RightBracket: keyboard("rightBracket"),
158
+ Backslash: keyboard("backslash")
159
+ };
160
+ var Mouse = {
161
+ Left: "<Mouse>/leftButton",
162
+ Right: "<Mouse>/rightButton",
163
+ Middle: "<Mouse>/middleButton",
164
+ Back: "<Mouse>/backButton",
165
+ Forward: "<Mouse>/forwardButton",
166
+ Scroll: "<Mouse>/scroll",
167
+ Delta: "<Mouse>/delta",
168
+ Position: "<Mouse>/position"
169
+ };
170
+ var Gamepad = {
171
+ South: "<Gamepad>/buttonSouth",
172
+ East: "<Gamepad>/buttonEast",
173
+ West: "<Gamepad>/buttonWest",
174
+ North: "<Gamepad>/buttonNorth",
175
+ LeftShoulder: "<Gamepad>/leftShoulder",
176
+ RightShoulder: "<Gamepad>/rightShoulder",
177
+ LeftTrigger: "<Gamepad>/leftTrigger",
178
+ RightTrigger: "<Gamepad>/rightTrigger",
179
+ LeftStick: "<Gamepad>/leftStick",
180
+ RightStick: "<Gamepad>/rightStick",
181
+ LeftStickPress: "<Gamepad>/leftStickPress",
182
+ RightStickPress: "<Gamepad>/rightStickPress",
183
+ Dpad: "<Gamepad>/dpad",
184
+ DpadUp: "<Gamepad>/dpad/up",
185
+ DpadDown: "<Gamepad>/dpad/down",
186
+ DpadLeft: "<Gamepad>/dpad/left",
187
+ DpadRight: "<Gamepad>/dpad/right",
188
+ Start: "<Gamepad>/start",
189
+ Select: "<Gamepad>/select"
190
+ };
191
+
192
+ // src/visuals.ts
193
+ var visuals = {
194
+ line(options) {
195
+ return macroOnly("visuals.line");
196
+ },
197
+ overlay(options) {
198
+ return macroOnly("visuals.overlay");
199
+ },
200
+ remove(object) {
201
+ macroOnly("visuals.remove");
202
+ }
203
+ };
204
+
205
+ // src/client.ts
206
+ function scope() {
207
+ return macroOnly("scope");
208
+ }
209
+ var agents = {
210
+ local() {
211
+ return macroOnly("agents.local");
212
+ },
213
+ localOrSpectated() {
214
+ return macroOnly("agents.localOrSpectated");
215
+ },
216
+ all() {
217
+ return macroOnly("agents.all");
218
+ },
219
+ allies() {
220
+ return macroOnly("agents.allies");
221
+ },
222
+ enemies() {
223
+ return macroOnly("agents.enemies");
224
+ },
225
+ select(values) {
226
+ return macroOnly("agents.select");
227
+ }
228
+ };
229
+ var scheduler = {
230
+ frame(callback) {
231
+ return macroOnly("scheduler.frame");
232
+ },
233
+ after(seconds, callback) {
234
+ macroOnly("scheduler.after");
235
+ },
236
+ afterTicks(ticks, callback) {
237
+ return macroOnly("scheduler.afterTicks");
238
+ },
239
+ every(seconds, callback) {
240
+ return macroOnly("scheduler.every");
241
+ },
242
+ everyTicks(ticks, callback) {
243
+ return macroOnly("scheduler.everyTicks");
244
+ },
245
+ until(predicate, callback) {
246
+ return macroOnly("scheduler.until");
247
+ },
248
+ debounce(key, seconds, callback) {
249
+ macroOnly("scheduler.debounce");
250
+ },
251
+ throttle(key, seconds, callback) {
252
+ return macroOnly("scheduler.throttle");
253
+ }
254
+ };
255
+ var camera = {
256
+ main() {
257
+ return macroOnly("camera.main");
258
+ },
259
+ create() {
260
+ return macroOnly("camera.create");
261
+ },
262
+ remove(value) {
263
+ macroOnly("camera.remove");
264
+ }
265
+ };
266
+ var time = {
267
+ seconds() {
268
+ return macroOnly("time.seconds");
269
+ },
270
+ tick() {
271
+ return macroOnly("time.tick");
272
+ },
273
+ toTicks(seconds) {
274
+ return macroOnly("time.toTicks");
275
+ },
276
+ toSeconds(ticks) {
277
+ return macroOnly("time.toSeconds");
278
+ },
279
+ /** Converts seconds without the native SecondsToTick floating-point undercount. */
280
+ ceilTicks(seconds) {
281
+ return macroOnly("time.ceilTicks");
282
+ }
283
+ };
284
+ export {
285
+ Gamepad,
286
+ Keyboard,
287
+ Mouse,
288
+ agents,
289
+ arrays,
290
+ camera,
291
+ control,
292
+ defineControls,
293
+ defineNetwork,
294
+ defineSettings,
295
+ input,
296
+ logger,
297
+ quaternion,
298
+ scheduler,
299
+ scope,
300
+ setting,
301
+ time,
302
+ vector2,
303
+ vector3,
304
+ visuals
305
+ };
@@ -0,0 +1,130 @@
1
+ declare const compilerMacro: unique symbol;
2
+
3
+ type PrimitiveSetting = boolean | number;
4
+ interface SettingOptions {
5
+ readonly label?: string;
6
+ readonly min?: number;
7
+ readonly max?: number;
8
+ }
9
+ interface SettingDefinition<T> {
10
+ readonly [compilerMacro]: "setting";
11
+ readonly defaultValue: T;
12
+ readonly options?: SettingOptions;
13
+ }
14
+ interface ChoiceDefinition<TOptions extends readonly string[]> extends SettingDefinition<TOptions[number]> {
15
+ readonly kind: "choice";
16
+ readonly choices: TOptions;
17
+ }
18
+ interface FlagsDefinition<TOptions extends readonly string[]> extends SettingDefinition<number> {
19
+ readonly kind: "flags";
20
+ readonly choices: TOptions;
21
+ readonly defaultFlags: readonly TOptions[number][];
22
+ }
23
+ interface ColorDefinition extends SettingDefinition<Color> {
24
+ readonly kind: "color";
25
+ readonly rgba: readonly [number, number, number, number];
26
+ }
27
+ type SettingInput = PrimitiveSetting | SettingDefinition<unknown>;
28
+ type Widen<T> = T extends boolean ? boolean : T extends number ? number : T;
29
+ type SettingValue<T> = T extends ChoiceDefinition<infer TOptions> ? TOptions[number] : T extends SettingDefinition<infer TValue> ? Widen<TValue> : Widen<T>;
30
+ type SettingsHandle<TSchema extends Record<string, SettingInput>> = {
31
+ -readonly [TKey in keyof TSchema]: SettingValue<TSchema[TKey]>;
32
+ };
33
+ declare function setting<const TValue extends PrimitiveSetting>(defaultValue: TValue, options?: SettingOptions): SettingDefinition<TValue>;
34
+ declare namespace setting {
35
+ function choice<const TOptions extends readonly [string, ...string[]]>(choices: TOptions, defaultValue: TOptions[number], options?: Pick<SettingOptions, "label">): ChoiceDefinition<TOptions>;
36
+ function flags<const TOptions extends readonly [string, ...string[]]>(choices: TOptions, defaultFlags?: readonly TOptions[number][], options?: Pick<SettingOptions, "label">): FlagsDefinition<TOptions>;
37
+ function color(value: string | readonly [number, number, number, number?], options?: Pick<SettingOptions, "label">): ColorDefinition;
38
+ }
39
+ declare function defineSettings<const TSchema extends Record<string, SettingInput>>(schema: TSchema): SettingsHandle<TSchema>;
40
+ declare function defineSettings<const TNamespace extends string, const TSchema extends Record<string, SettingInput>>(namespace: TNamespace, schema: TSchema): SettingsHandle<TSchema>;
41
+
42
+ /** Helpers for the game's read-only, one-based Array userdata. */
43
+ declare const arrays: {
44
+ forEach<T>(values: LuaArray<T>, callback: (value: T, index: number) => void): void;
45
+ some<T>(values: LuaArray<T>, predicate: (value: T, index: number) => boolean): boolean;
46
+ every<T>(values: LuaArray<T>, predicate: (value: T, index: number) => boolean): boolean;
47
+ find<T>(values: LuaArray<T>, predicate: (value: T, index: number) => boolean): T | undefined;
48
+ map<T, TResult extends {}>(values: LuaArray<T>, transform: (value: T, index: number) => TResult): TResult[];
49
+ filter<T>(values: LuaArray<T>, predicate: (value: T, index: number) => boolean): T[];
50
+ toArray<T>(values: LuaArray<T>): T[];
51
+ first<T>(values: LuaArray<T>): T | undefined;
52
+ last<T>(values: LuaArray<T>): T | undefined;
53
+ };
54
+
55
+ interface Logger {
56
+ info(message: string): void;
57
+ debug(message: string): void;
58
+ warn(message: string): void;
59
+ /** Prints several lines as one console entry. */
60
+ batch(lines: readonly string[]): void;
61
+ /** Prints a message only once for this logger and key. */
62
+ once(key: string, message: string): void;
63
+ /** Prints at most once per interval for this logger and key. */
64
+ throttled(key: string, seconds: number, message: string): void;
65
+ }
66
+ /** Creates a lightweight, prefixed logger in the generated Lua. */
67
+ declare function logger(name: string): Logger;
68
+
69
+ interface AgentSelection {
70
+ where(predicate: (agent: Agent) => boolean): this;
71
+ alive(): this;
72
+ dead(): this;
73
+ visible(): this;
74
+ within(origin: Vector3, distance: number): this;
75
+ exclude(agent: Agent | undefined): this;
76
+ team(team: Team): this;
77
+ first(): Agent | undefined;
78
+ nearestTo(origin: Vector3): Agent | undefined;
79
+ count(): number;
80
+ toArray(): Agent[];
81
+ }
82
+
83
+ interface Scope {
84
+ /** Tracks a cancellable native or SDK subscription. */
85
+ using<T extends EventSubscription | undefined>(subscription: T): T;
86
+ /** Runs a cleanup callback when dispose() is called. */
87
+ defer(callback: () => void): void;
88
+ /** Cancels tracked resources and runs deferred callbacks once. */
89
+ dispose(): void;
90
+ isDisposed(): boolean;
91
+ }
92
+
93
+ /** Operator helpers that remain type-safe in TypeScript and lower to native Lua operators. */
94
+ declare const vector2: {
95
+ add(left: Vector2, right: Vector2): Vector2;
96
+ subtract(left: Vector2, right: Vector2): Vector2;
97
+ };
98
+ declare const vector3: {
99
+ add(left: Vector3, right: Vector3): Vector3;
100
+ subtract(left: Vector3, right: Vector3): Vector3;
101
+ };
102
+ declare const quaternion: {
103
+ multiply(left: Quaternion, right: Quaternion): Quaternion;
104
+ rotate(rotation: Quaternion, value: Vector3): Vector3;
105
+ };
106
+
107
+ type MessageMap = object;
108
+ type LuaPayload<T> = T extends LuaPrimitive ? T : T extends (...args: never[]) => unknown ? never : T extends readonly (infer TItem)[] ? readonly Exclude<LuaPayload<TItem>, undefined>[] : T extends object ? {
109
+ readonly [TKey in keyof T]: LuaPayload<Exclude<T[TKey], undefined>> | Extract<T[TKey], undefined>;
110
+ } : never;
111
+ type UnsafeMessageKinds<TMessages extends MessageMap> = {
112
+ [TKey in keyof TMessages]: [TMessages[TKey]] extends [LuaPayload<TMessages[TKey]>] ? never : TKey;
113
+ }[keyof TMessages];
114
+ type NetworkDefinitionArguments<TOutbound extends MessageMap, TInbound extends MessageMap> = [UnsafeMessageKinds<TOutbound> | UnsafeMessageKinds<TInbound>] extends [never] ? [namespace?: string] : [
115
+ namespace: string | undefined,
116
+ invalidPayload: "Network payloads must contain only transport-safe values"
117
+ ];
118
+ interface NetworkChannel<TOutbound extends MessageMap, TInbound extends MessageMap> {
119
+ /** Queues a message for the next ordered batch sent once per simulation tick. */
120
+ send<TKey extends Extract<keyof TOutbound, string>>(kind: TKey, payload: TOutbound[TKey] & LuaPayload<TOutbound[TKey]>): void;
121
+ /** Registers a local callback for one incoming message kind. */
122
+ on<TKey extends Extract<keyof TInbound, string>>(kind: TKey, callback: (payload: TInbound[TKey]) => void): void;
123
+ }
124
+ /**
125
+ * Defines one typed view of the Reflex transport. This is a top-level compiler
126
+ * declaration and does not add an SDK dependency to the emitted Lua.
127
+ */
128
+ declare function defineNetwork<TOutbound extends MessageMap, TInbound extends MessageMap>(..._args: NetworkDefinitionArguments<TOutbound, TInbound>): NetworkChannel<TOutbound, TInbound>;
129
+
130
+ export { type AgentSelection as A, type ChoiceDefinition as C, type FlagsDefinition as F, type Logger as L, type MessageMap as M, type NetworkChannel as N, type Scope as S, type ColorDefinition as a, type SettingDefinition as b, type SettingOptions as c, type SettingsHandle as d, arrays as e, defineNetwork as f, defineSettings as g, vector3 as h, compilerMacro as i, logger as l, quaternion as q, setting as s, vector2 as v };
@@ -0,0 +1 @@
1
+ export { A as AgentSelection, C as ChoiceDefinition, a as ColorDefinition, F as FlagsDefinition, L as Logger, M as MessageMap, N as NetworkChannel, S as Scope, b as SettingDefinition, c as SettingOptions, d as SettingsHandle, e as arrays, f as defineNetwork, g as defineSettings, l as logger, q as quaternion, s as setting, v as vector2, h as vector3 } from './index-C8VwPmhn.js';
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import {
2
+ arrays,
3
+ defineNetwork,
4
+ defineSettings,
5
+ logger,
6
+ quaternion,
7
+ setting,
8
+ vector2,
9
+ vector3
10
+ } from "./chunk-6XHZVS7S.js";
11
+ export {
12
+ arrays,
13
+ defineNetwork,
14
+ defineSettings,
15
+ logger,
16
+ quaternion,
17
+ setting,
18
+ vector2,
19
+ vector3
20
+ };
@@ -0,0 +1,32 @@
1
+ import { A as AgentSelection, S as Scope } from './index-C8VwPmhn.js';
2
+ export { C as ChoiceDefinition, a as ColorDefinition, F as FlagsDefinition, L as Logger, M as MessageMap, N as NetworkChannel, b as SettingDefinition, c as SettingOptions, d as SettingsHandle, e as arrays, f as defineNetwork, g as defineSettings, l as logger, q as quaternion, s as setting, v as vector2, h as vector3 } from './index-C8VwPmhn.js';
3
+
4
+ declare function scope(): Scope;
5
+ declare const agents: {
6
+ local(): Agent | undefined;
7
+ localOrSpectated(): Agent | undefined;
8
+ all(): LuaArray<Agent>;
9
+ allies(): LuaArray<Agent>;
10
+ enemies(): LuaArray<Agent>;
11
+ select(values?: LuaArray<Agent> | readonly Agent[]): AgentSelection;
12
+ };
13
+ declare const scheduler: {
14
+ tick(callback: () => void): EventSubscription;
15
+ after(seconds: number, callback: () => void): void;
16
+ afterTicks(ticks: number, callback: () => void): EventSubscription;
17
+ every(seconds: number, callback: () => void): EventSubscription;
18
+ everyTicks(ticks: number, callback: () => void): EventSubscription;
19
+ until(predicate: () => boolean, callback: () => void): EventSubscription;
20
+ debounce(key: string, seconds: number, callback: () => void): void;
21
+ throttle(key: string, seconds: number, callback: () => void): boolean;
22
+ };
23
+ declare const time: {
24
+ seconds(): number;
25
+ tick(): number;
26
+ toTicks(seconds: number): number;
27
+ toSeconds(ticks: number): number;
28
+ /** Converts seconds without the native SecondsToTick floating-point undercount. */
29
+ ceilTicks(seconds: number): number;
30
+ };
31
+
32
+ export { AgentSelection, Scope, agents, scheduler, scope, time };
package/dist/server.js ADDED
@@ -0,0 +1,94 @@
1
+ import {
2
+ arrays,
3
+ defineNetwork,
4
+ defineSettings,
5
+ logger,
6
+ macroOnly,
7
+ quaternion,
8
+ setting,
9
+ vector2,
10
+ vector3
11
+ } from "./chunk-6XHZVS7S.js";
12
+
13
+ // src/server.ts
14
+ function scope() {
15
+ return macroOnly("scope");
16
+ }
17
+ var agents = {
18
+ local() {
19
+ return macroOnly("agents.local");
20
+ },
21
+ localOrSpectated() {
22
+ return macroOnly("agents.localOrSpectated");
23
+ },
24
+ all() {
25
+ return macroOnly("agents.all");
26
+ },
27
+ allies() {
28
+ return macroOnly("agents.allies");
29
+ },
30
+ enemies() {
31
+ return macroOnly("agents.enemies");
32
+ },
33
+ select(values) {
34
+ return macroOnly("agents.select");
35
+ }
36
+ };
37
+ var scheduler = {
38
+ tick(callback) {
39
+ return macroOnly("scheduler.tick");
40
+ },
41
+ after(seconds, callback) {
42
+ macroOnly("scheduler.after");
43
+ },
44
+ afterTicks(ticks, callback) {
45
+ return macroOnly("scheduler.afterTicks");
46
+ },
47
+ every(seconds, callback) {
48
+ return macroOnly("scheduler.every");
49
+ },
50
+ everyTicks(ticks, callback) {
51
+ return macroOnly("scheduler.everyTicks");
52
+ },
53
+ until(predicate, callback) {
54
+ return macroOnly("scheduler.until");
55
+ },
56
+ debounce(key, seconds, callback) {
57
+ macroOnly("scheduler.debounce");
58
+ },
59
+ throttle(key, seconds, callback) {
60
+ return macroOnly("scheduler.throttle");
61
+ }
62
+ };
63
+ var time = {
64
+ seconds() {
65
+ return macroOnly("time.seconds");
66
+ },
67
+ tick() {
68
+ return macroOnly("time.tick");
69
+ },
70
+ toTicks(seconds) {
71
+ return macroOnly("time.toTicks");
72
+ },
73
+ toSeconds(ticks) {
74
+ return macroOnly("time.toSeconds");
75
+ },
76
+ /** Converts seconds without the native SecondsToTick floating-point undercount. */
77
+ ceilTicks(seconds) {
78
+ return macroOnly("time.ceilTicks");
79
+ }
80
+ };
81
+ export {
82
+ agents,
83
+ arrays,
84
+ defineNetwork,
85
+ defineSettings,
86
+ logger,
87
+ quaternion,
88
+ scheduler,
89
+ scope,
90
+ setting,
91
+ time,
92
+ vector2,
93
+ vector3
94
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@killscript/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Compile-time SDK and convenience wrappers for KILLSCRIPT modules",
5
+ "license": "MIT",
6
+ "keywords": ["killscript", "typescript", "lua", "modding", "sdk"],
7
+ "homepage": "https://silentbless.github.io/killscript/",
8
+ "sideEffects": false,
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/SilentBless/killscript.git",
12
+ "directory": "packages/sdk"
13
+ },
14
+ "type": "module",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./client": {
24
+ "types": "./dist/client.d.ts",
25
+ "import": "./dist/client.js"
26
+ },
27
+ "./server": {
28
+ "types": "./dist/server.d.ts",
29
+ "import": "./dist/server.js"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "build": "tsup src/index.ts src/client.ts src/server.ts --format esm --dts --clean",
34
+ "check": "tsc -p tsconfig.json --noEmit",
35
+ "prepack": "npm run build"
36
+ },
37
+ "dependencies": {
38
+ "@killscript/types": "0.1.0"
39
+ },
40
+ "devDependencies": {
41
+ "tsup": "8.5.1",
42
+ "typescript": "6.0.2"
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }