@khr3/launchers 0.0.0-stage → 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 khr3 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 CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @khr3/launchers
2
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.
3
+ Zero-dependency KHR launcher moving-part schema (`bolt`, `pump`, `trigger`, `magazine`, `screen_rect`), rail attachment sockets (`rail_top`, `rail_under`, `muzzle`, `sight_align`), character mount sockets (`Socket_Hand_R/L`, `Socket_Head`, `Socket_Back`), data-driven ammo catalog, and deterministic cycle state machine for `khr3`.
4
+
5
+ ## Quick Start
6
+
7
+ ```ts
8
+ import { DEFAULT_AMMO_CATALOG, createLauncherState, stepLauncher } from "@khr3/launchers";
9
+
10
+ const state = createLauncherState({
11
+ id: "kolmogorov_pistol",
12
+ ammoId: DEFAULT_AMMO_CATALOG.pistol.id,
13
+ fireRateHz: 5,
14
+ magazineCapacity: 12,
15
+ reloadSec: 1.4,
16
+ recoilImpulseNs: 2.4,
17
+ sockets: { grip_primary: [0, 0, 0], muzzle: [0, 0.08, 0.22] },
18
+ });
19
+
20
+ const event = stepLauncher(state, { trigger: true }, 1 / 60);
21
+ ```
@@ -0,0 +1,2 @@
1
+ export * from "./schema.js";
2
+ export * from "./runtime.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./schema.js";
2
+ export * from "./runtime.js";
@@ -0,0 +1,25 @@
1
+ import { type AttachmentSpec, type LauncherSpec, type RailSocketName, type Vec3Tuple } from "./schema.js";
2
+ export interface LauncherInput {
3
+ trigger: boolean;
4
+ reload?: boolean;
5
+ }
6
+ export interface LaunchEvent {
7
+ readonly launcherId: string;
8
+ readonly ammoId: string;
9
+ readonly muzzleLocal: Vec3Tuple;
10
+ readonly ejectLocal: Vec3Tuple | null;
11
+ readonly recoilImpulseNs: number;
12
+ }
13
+ export interface LauncherState {
14
+ readonly spec: LauncherSpec;
15
+ ammoInMag: number;
16
+ cooldownSec: number;
17
+ reloadRemainingSec: number;
18
+ /** 0 = closed/resting, 1 = full rearward bolt/pump stroke */
19
+ cyclePhase: number;
20
+ totalFired: number;
21
+ }
22
+ export declare function createLauncherState(spec: LauncherSpec): LauncherState;
23
+ export declare function stepLauncher(state: LauncherState, input: LauncherInput, dt: number): LaunchEvent | null;
24
+ export declare function attachModule(spec: LauncherSpec, attachment: AttachmentSpec): LauncherSpec;
25
+ export declare function detachModule(spec: LauncherSpec, rail: RailSocketName): LauncherSpec;
@@ -0,0 +1,60 @@
1
+ import { validateLauncherSpec, } from "./schema.js";
2
+ export function createLauncherState(spec) {
3
+ validateLauncherSpec(spec);
4
+ return {
5
+ spec,
6
+ ammoInMag: spec.magazineCapacity,
7
+ cooldownSec: 0,
8
+ reloadRemainingSec: 0,
9
+ cyclePhase: 0,
10
+ totalFired: 0,
11
+ };
12
+ }
13
+ export function stepLauncher(state, input, dt) {
14
+ const stepDt = Math.max(0, dt);
15
+ if (state.cooldownSec > 0)
16
+ state.cooldownSec = Math.max(0, state.cooldownSec - stepDt);
17
+ if (state.reloadRemainingSec > 0) {
18
+ state.reloadRemainingSec = Math.max(0, state.reloadRemainingSec - stepDt);
19
+ if (state.reloadRemainingSec === 0)
20
+ state.ammoInMag = state.spec.magazineCapacity;
21
+ }
22
+ else if (input.reload && state.ammoInMag < state.spec.magazineCapacity) {
23
+ state.reloadRemainingSec = state.spec.reloadSec;
24
+ if (state.reloadRemainingSec === 0)
25
+ state.ammoInMag = state.spec.magazineCapacity;
26
+ }
27
+ const cyclePeriod = 1 / state.spec.fireRateHz;
28
+ state.cyclePhase = state.cooldownSec > 0 ? Math.sin((state.cooldownSec / cyclePeriod) * Math.PI) : 0;
29
+ if (input.trigger && state.reloadRemainingSec === 0 && state.cooldownSec === 0) {
30
+ if (state.ammoInMag > 0) {
31
+ state.ammoInMag -= 1;
32
+ state.totalFired += 1;
33
+ state.cooldownSec = cyclePeriod;
34
+ state.cyclePhase = 1;
35
+ return {
36
+ launcherId: state.spec.id,
37
+ ammoId: state.spec.ammoId,
38
+ muzzleLocal: state.spec.sockets.muzzle,
39
+ ejectLocal: state.spec.sockets.eject_port ?? null,
40
+ recoilImpulseNs: state.spec.recoilImpulseNs,
41
+ };
42
+ }
43
+ state.reloadRemainingSec = state.spec.reloadSec;
44
+ }
45
+ return null;
46
+ }
47
+ export function attachModule(spec, attachment) {
48
+ return {
49
+ ...spec,
50
+ attachments: {
51
+ ...spec.attachments,
52
+ [attachment.rail]: attachment,
53
+ },
54
+ };
55
+ }
56
+ export function detachModule(spec, rail) {
57
+ const next = { ...spec.attachments };
58
+ delete next[rail];
59
+ return { ...spec, attachments: next };
60
+ }
@@ -0,0 +1,36 @@
1
+ export declare const LAUNCHER_PART_ROLES: readonly ["receiver", "bolt", "pump", "trigger", "magazine", "barrel", "stock", "screen_rect"];
2
+ export type LauncherPartRole = (typeof LAUNCHER_PART_ROLES)[number];
3
+ export declare const LAUNCHER_SOCKETS: readonly ["grip_primary", "grip_secondary", "rail_top", "rail_under", "muzzle", "eject_port", "sight_align"];
4
+ export type LauncherSocketName = (typeof LAUNCHER_SOCKETS)[number];
5
+ export declare const RAIL_SOCKETS: readonly ["rail_top", "rail_under", "muzzle"];
6
+ export type RailSocketName = (typeof RAIL_SOCKETS)[number];
7
+ export declare const CHARACTER_SOCKETS: readonly ["Socket_Hand_R", "Socket_Hand_L", "Socket_Head", "Socket_Back"];
8
+ export type CharacterSocketName = (typeof CHARACTER_SOCKETS)[number];
9
+ export type Vec3Tuple = readonly [number, number, number];
10
+ export interface AmmoSpec {
11
+ readonly id: string;
12
+ readonly muzzleSpeedMs: number;
13
+ readonly massKg: number;
14
+ readonly casingRadiusM: number;
15
+ readonly casingLengthM: number;
16
+ readonly tipRatio: number;
17
+ readonly color: string;
18
+ }
19
+ export interface AttachmentSpec {
20
+ readonly id: string;
21
+ readonly rail: RailSocketName;
22
+ readonly massKg: number;
23
+ readonly glbKey?: string;
24
+ }
25
+ export interface LauncherSpec {
26
+ readonly id: string;
27
+ readonly ammoId: string;
28
+ readonly fireRateHz: number;
29
+ readonly magazineCapacity: number;
30
+ readonly reloadSec: number;
31
+ readonly recoilImpulseNs: number;
32
+ readonly sockets: Partial<Record<LauncherSocketName, Vec3Tuple>>;
33
+ readonly attachments?: Partial<Record<RailSocketName, AttachmentSpec>>;
34
+ }
35
+ export declare const DEFAULT_AMMO_CATALOG: Readonly<Record<string, AmmoSpec>>;
36
+ export declare function validateLauncherSpec(spec: LauncherSpec): void;
package/dist/schema.js ADDED
@@ -0,0 +1,50 @@
1
+ export const LAUNCHER_PART_ROLES = [
2
+ "receiver",
3
+ "bolt",
4
+ "pump",
5
+ "trigger",
6
+ "magazine",
7
+ "barrel",
8
+ "stock",
9
+ "screen_rect",
10
+ ];
11
+ export const LAUNCHER_SOCKETS = [
12
+ "grip_primary",
13
+ "grip_secondary",
14
+ "rail_top",
15
+ "rail_under",
16
+ "muzzle",
17
+ "eject_port",
18
+ "sight_align",
19
+ ];
20
+ export const RAIL_SOCKETS = ["rail_top", "rail_under", "muzzle"];
21
+ export const CHARACTER_SOCKETS = [
22
+ "Socket_Hand_R",
23
+ "Socket_Hand_L",
24
+ "Socket_Head",
25
+ "Socket_Back",
26
+ ];
27
+ export const DEFAULT_AMMO_CATALOG = {
28
+ pistol: { id: "pistol", muzzleSpeedMs: 360, massKg: 0.008, casingRadiusM: 0.0049, casingLengthM: 0.019, tipRatio: 0.35, color: "#E3A83B" },
29
+ rifle: { id: "rifle", muzzleSpeedMs: 880, massKg: 0.004, casingRadiusM: 0.0048, casingLengthM: 0.045, tipRatio: 0.45, color: "#D68A28" },
30
+ laser: { id: "laser", muzzleSpeedMs: 1200, massKg: 0.0001, casingRadiusM: 0, casingLengthM: 0, tipRatio: 0, color: "#26E3E8" },
31
+ orb: { id: "orb", muzzleSpeedMs: 42, massKg: 0.12, casingRadiusM: 0, casingLengthM: 0, tipRatio: 0, color: "#E3782A" },
32
+ rocket: { id: "rocket", muzzleSpeedMs: 95, massKg: 1.4, casingRadiusM: 0.035, casingLengthM: 0.32, tipRatio: 0.3, color: "#D93832" },
33
+ };
34
+ export function validateLauncherSpec(spec) {
35
+ if (!spec.id)
36
+ throw new Error("LauncherSpec: missing id");
37
+ if (!spec.ammoId)
38
+ throw new Error(`LauncherSpec(${spec.id}): missing ammoId`);
39
+ if (!(spec.fireRateHz > 0))
40
+ throw new Error(`LauncherSpec(${spec.id}): fireRateHz must be > 0`);
41
+ if (!(spec.magazineCapacity >= 1 && Number.isInteger(spec.magazineCapacity))) {
42
+ throw new Error(`LauncherSpec(${spec.id}): magazineCapacity must be a positive integer`);
43
+ }
44
+ if (!(spec.reloadSec >= 0))
45
+ throw new Error(`LauncherSpec(${spec.id}): reloadSec must be >= 0`);
46
+ if (!spec.sockets.grip_primary)
47
+ throw new Error(`LauncherSpec(${spec.id}): missing grip_primary socket`);
48
+ if (!spec.sockets.muzzle)
49
+ throw new Error(`LauncherSpec(${spec.id}): missing muzzle socket`);
50
+ }
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@khr3/launchers",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Zero-dependency KHR launcher moving-part schema, rail attachment sockets, data-driven ammo catalog, and deterministic cycle state machine for khr3.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
22
+ "keywords": [
23
+ "khr3",
24
+ "launchers",
25
+ "sockets",
26
+ "gltf",
27
+ "glb",
28
+ "threejs",
29
+ "r3f",
30
+ "gamedev"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/pinkAphant/khr3-launchers.git"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "typecheck": "tsc --noEmit",
41
+ "build": "rm -rf dist && tsc && rm -f dist/*.test.*",
42
+ "test": "rm -rf dist && tsc && node --test dist/launchers.test.js && rm -f dist/*.test.*",
43
+ "prepack": "npm run build",
44
+ "pack:dry": "npm pack --dry-run"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^22.0.0",
48
+ "typescript": "^5.8.0"
49
+ }
50
+ }