@dloizides/game-skins 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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - First release: the engine-free skin contract extracted from Surge `src/skin/` (GAME-SKINS-1 "Shared game skins"), the active-skin, asset-cache, preview-pick, role-colour and CSS-token helpers, and the four shared palettes Night circuit, Dusk highway, Ember line and Deep current.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 dloizides
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,17 @@
1
- # Temporary Holding Version
1
+ # @dloizides/game-skins
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
+ The look of a game as data, shared across EisaiPollis games. Zero dependencies, no engine types.
4
+
5
+ - **Contract** (`SkinBinding<Role, Cue>`): each game declares its own role and cue lists; a skin binds every one (a missing role is a type error). Materials, environment, parallax, post-FX, UI tokens, gameplay colours, audio and quality tiers.
6
+ - **Helpers**: `setActiveSkin` / `activeSkin`, `roleColour` / `roleVariantColour`, `applySkinUi(root, ui)`, `pickSkin(built, loader)` for `?skin=` previews, `createAssetCache(load)`.
7
+ - **Shared palettes** (`GAME_SKINS`, `gameSkin(id)`, `paletteUi(palette)`): Night circuit, Dusk highway, Ember line, Deep current. A palette has no game roles (sky, ground, accent, figure, danger, reward); each game maps its roles onto the swatches.
8
+
9
+ ```ts
10
+ import { GameSkinId, gameSkin, paletteUi, applySkinUi, type SkinBinding } from '@dloizides/game-skins';
11
+
12
+ type Role = 'tile' | 'cursor';
13
+ const deep = gameSkin(GameSkinId.DeepCurrent)!;
14
+ applySkinUi(document.documentElement, paletteUi(deep));
15
+ ```
16
+
17
+ Engine adapters (Three.js materials, loaders) stay in each game.
@@ -0,0 +1,222 @@
1
+ /** Roles the environment paints outside the game's role list. */
2
+ declare enum EnvironmentRole {
3
+ Sky = "sky"
4
+ }
5
+
6
+ /** How a role's colour mixes with what is behind it. */
7
+ declare enum MaterialBlending {
8
+ Normal = "normal",
9
+ Additive = "additive"
10
+ }
11
+
12
+ /** How a role is drawn; the engine adapter maps each kind to a material. */
13
+ declare enum MaterialKind {
14
+ Lambert = "lambert",
15
+ Unlit = "unlit",
16
+ Standard = "standard",
17
+ Line = "line",
18
+ Shader = "shader"
19
+ }
20
+
21
+ /** Which faces of a role's mesh are drawn. */
22
+ declare enum MaterialSide {
23
+ Front = "front",
24
+ Back = "back",
25
+ Double = "double"
26
+ }
27
+
28
+ /** The tone curve a skin renders through. */
29
+ declare enum ToneMapping {
30
+ None = "none",
31
+ Aces = "aces",
32
+ Agx = "agx"
33
+ }
34
+
35
+ /** A file shipped by a skin, relative to the skin's asset folder; every one needs a licence row. */
36
+ interface AssetRef {
37
+ readonly path: string;
38
+ }
39
+ /** How one role is painted, with no engine types: the engine adapter turns it into a material. */
40
+ interface MaterialRecipe {
41
+ readonly kind: MaterialKind;
42
+ readonly color?: number;
43
+ readonly map?: AssetRef;
44
+ readonly mapScale?: number;
45
+ readonly normalMap?: AssetRef;
46
+ readonly roughness?: number;
47
+ readonly metalness?: number;
48
+ readonly emissive?: number;
49
+ readonly emissiveIntensity?: number;
50
+ readonly transparent?: boolean;
51
+ readonly opacity?: number;
52
+ readonly depthWrite?: boolean;
53
+ readonly depthTest?: boolean;
54
+ readonly side?: MaterialSide;
55
+ readonly blending?: MaterialBlending;
56
+ readonly fog?: boolean;
57
+ }
58
+ /** The look of one game role; `variants` paints a family the game indexes by number. */
59
+ interface RoleLook {
60
+ readonly material: MaterialRecipe;
61
+ readonly variants?: readonly MaterialRecipe[];
62
+ readonly model?: AssetRef;
63
+ readonly castShadow?: boolean;
64
+ }
65
+ interface SkyGradient {
66
+ readonly top: number;
67
+ readonly horizon: number;
68
+ readonly glow: number;
69
+ }
70
+ interface FogSpec {
71
+ readonly color: number;
72
+ readonly near: number;
73
+ readonly far: number;
74
+ }
75
+ interface HemiLightSpec {
76
+ readonly sky: number;
77
+ readonly ground: number;
78
+ readonly intensity: number;
79
+ }
80
+ interface KeyLightSpec {
81
+ readonly color: number;
82
+ readonly intensity: number;
83
+ readonly position: readonly [number, number, number];
84
+ }
85
+ /** Scenery models repeated along both sides of the play space, recycled ahead of the camera. */
86
+ interface PropSpec {
87
+ readonly models: readonly AssetRef[];
88
+ readonly tint: number;
89
+ readonly windowGlow: number;
90
+ readonly glow: number;
91
+ readonly rows: number;
92
+ readonly spacing: number;
93
+ readonly lateral: readonly [number, number];
94
+ readonly footprint: readonly [number, number];
95
+ readonly baseY: number;
96
+ }
97
+ interface EnvironmentSpec {
98
+ readonly background: number;
99
+ readonly sky: SkyGradient;
100
+ readonly hdri?: AssetRef;
101
+ readonly hdriGain?: number;
102
+ readonly props?: PropSpec;
103
+ readonly fog: FogSpec;
104
+ readonly hemi: HemiLightSpec;
105
+ readonly key: KeyLightSpec;
106
+ readonly exposure: number;
107
+ }
108
+ interface ParallaxLayer {
109
+ readonly image: AssetRef;
110
+ readonly depth: number;
111
+ readonly scrollFactor: number;
112
+ readonly tint?: number;
113
+ }
114
+ interface PostFxSpec {
115
+ readonly bloom: number;
116
+ readonly vignette: number;
117
+ readonly grain: number;
118
+ readonly toneMapping: ToneMapping;
119
+ }
120
+ /** CSS custom properties the skin sets on the document root. */
121
+ type UiTokens = Readonly<Record<string, string>>;
122
+ /** Colours that carry gameplay meaning; a skin may restyle them but must keep them apart without colour. */
123
+ interface SemanticColours {
124
+ readonly padTiers: readonly number[];
125
+ readonly shield: number;
126
+ readonly hazard: number;
127
+ readonly jackpot: number;
128
+ readonly boost: number;
129
+ readonly spark: number;
130
+ }
131
+ interface AudioSpec<Cue extends string = string> {
132
+ readonly music: Readonly<Record<string, AssetRef>>;
133
+ readonly sfx: Readonly<Record<Cue, AssetRef>>;
134
+ }
135
+ interface TierSpec {
136
+ readonly maxTexture: 512 | 1024 | 2048;
137
+ readonly shadows: boolean;
138
+ readonly bloomScale: number;
139
+ readonly hdri: boolean;
140
+ }
141
+ /** Everything one skin owns for a game's `Role` and `Cue` lists; a forgotten role or cue is a type error. */
142
+ interface SkinBinding<Role extends string, Cue extends string = string> {
143
+ readonly id: string;
144
+ readonly contractVersion: 1;
145
+ readonly roles: Readonly<Record<Role, RoleLook>>;
146
+ readonly environment: EnvironmentSpec;
147
+ readonly layers: readonly ParallaxLayer[];
148
+ readonly post: PostFxSpec;
149
+ readonly ui: UiTokens;
150
+ readonly semantics: SemanticColours;
151
+ readonly audio: AudioSpec<Cue>;
152
+ readonly tiers: {
153
+ readonly mobile: TierSpec;
154
+ readonly desktop: TierSpec;
155
+ };
156
+ }
157
+
158
+ /** Makes `skin` the one every role lookup reads from; a build selects exactly one. */
159
+ declare const setActiveSkin: <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>) => void;
160
+ /** The selected skin; throws when nothing selected one, so a missing composition root fails loudly. */
161
+ declare const activeSkin: <Role extends string, Cue extends string>() => SkinBinding<Role, Cue>;
162
+
163
+ /** One shared load per asset path; `dispose` hands every loaded value to `free` and forgets them all. */
164
+ interface AssetCache<T> {
165
+ get(path: string): Promise<T>;
166
+ dispose(free: (value: T) => void): Promise<void>;
167
+ }
168
+ /** Creates an asset cache over `load`; a failed load is forgotten so the next `get` retries. */
169
+ declare const createAssetCache: <T>(load: (path: string) => Promise<T>) => AssetCache<T>;
170
+
171
+ /** The skin `load` brings (a preview), or `built` when there is no loader or the load fails. */
172
+ declare const pickSkin: <S>(built: S, load: (() => Promise<{
173
+ readonly skin: S;
174
+ }>) | undefined) => Promise<S>;
175
+
176
+ /** The colour `skin` gives `role` (a shader uniform, a tint, a burst). */
177
+ declare const roleColour: <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role) => number;
178
+ /** The colour of variant `index` of `role`, in the skin's order. */
179
+ declare const roleVariantColour: <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role, index: number) => number;
180
+
181
+ /** Anything with an inline style, such as `document.documentElement`. */
182
+ interface StyleTarget {
183
+ readonly style: {
184
+ setProperty(name: string, value: string): void;
185
+ };
186
+ }
187
+ /** Sets each of `ui`'s CSS custom properties on `root`, so the DOM chrome reads its colours from the skin. */
188
+ declare const applySkinUi: (root: StyleTarget, ui: UiTokens) => void;
189
+
190
+ /** The ids of the shared skins, in the order they unlock. */
191
+ declare enum GameSkinId {
192
+ NightCircuit = "night-circuit",
193
+ DuskHighway = "dusk-highway",
194
+ EmberLine = "ember-line",
195
+ DeepCurrent = "deep-current"
196
+ }
197
+
198
+ /** A shared skin as colours with no game roles; each game maps its own roles onto these swatches. */
199
+ interface SkinPalette {
200
+ readonly id: GameSkinId;
201
+ readonly name: string;
202
+ readonly skyTop: number;
203
+ readonly skyBand: number;
204
+ readonly ground: number;
205
+ readonly accent: number;
206
+ readonly figure: number;
207
+ readonly danger: number;
208
+ readonly reward: number;
209
+ readonly rewardLight: number;
210
+ }
211
+
212
+ /** The shared skins, in unlock order. */
213
+ declare const GAME_SKINS: readonly SkinPalette[];
214
+ /** The shared skin with `id` (a `?skin=` value), or undefined when no shared skin has it. */
215
+ declare const gameSkin: (id: string) => SkinPalette | undefined;
216
+
217
+ /** `colour` as a six-digit CSS hex string. */
218
+ declare const hexCss: (colour: number) => string;
219
+ /** The palette as `--skin-*` CSS custom properties, ready for `applySkinUi`. */
220
+ declare const paletteUi: (palette: SkinPalette) => UiTokens;
221
+
222
+ export { type AssetCache, type AssetRef, type AudioSpec, EnvironmentRole, type EnvironmentSpec, type FogSpec, GAME_SKINS, GameSkinId, type HemiLightSpec, type KeyLightSpec, MaterialBlending, MaterialKind, type MaterialRecipe, MaterialSide, type ParallaxLayer, type PostFxSpec, type PropSpec, type RoleLook, type SemanticColours, type SkinBinding, type SkinPalette, type SkyGradient, type StyleTarget, type TierSpec, ToneMapping, type UiTokens, activeSkin, applySkinUi, createAssetCache, gameSkin, hexCss, paletteUi, pickSkin, roleColour, roleVariantColour, setActiveSkin };
@@ -0,0 +1,222 @@
1
+ /** Roles the environment paints outside the game's role list. */
2
+ declare enum EnvironmentRole {
3
+ Sky = "sky"
4
+ }
5
+
6
+ /** How a role's colour mixes with what is behind it. */
7
+ declare enum MaterialBlending {
8
+ Normal = "normal",
9
+ Additive = "additive"
10
+ }
11
+
12
+ /** How a role is drawn; the engine adapter maps each kind to a material. */
13
+ declare enum MaterialKind {
14
+ Lambert = "lambert",
15
+ Unlit = "unlit",
16
+ Standard = "standard",
17
+ Line = "line",
18
+ Shader = "shader"
19
+ }
20
+
21
+ /** Which faces of a role's mesh are drawn. */
22
+ declare enum MaterialSide {
23
+ Front = "front",
24
+ Back = "back",
25
+ Double = "double"
26
+ }
27
+
28
+ /** The tone curve a skin renders through. */
29
+ declare enum ToneMapping {
30
+ None = "none",
31
+ Aces = "aces",
32
+ Agx = "agx"
33
+ }
34
+
35
+ /** A file shipped by a skin, relative to the skin's asset folder; every one needs a licence row. */
36
+ interface AssetRef {
37
+ readonly path: string;
38
+ }
39
+ /** How one role is painted, with no engine types: the engine adapter turns it into a material. */
40
+ interface MaterialRecipe {
41
+ readonly kind: MaterialKind;
42
+ readonly color?: number;
43
+ readonly map?: AssetRef;
44
+ readonly mapScale?: number;
45
+ readonly normalMap?: AssetRef;
46
+ readonly roughness?: number;
47
+ readonly metalness?: number;
48
+ readonly emissive?: number;
49
+ readonly emissiveIntensity?: number;
50
+ readonly transparent?: boolean;
51
+ readonly opacity?: number;
52
+ readonly depthWrite?: boolean;
53
+ readonly depthTest?: boolean;
54
+ readonly side?: MaterialSide;
55
+ readonly blending?: MaterialBlending;
56
+ readonly fog?: boolean;
57
+ }
58
+ /** The look of one game role; `variants` paints a family the game indexes by number. */
59
+ interface RoleLook {
60
+ readonly material: MaterialRecipe;
61
+ readonly variants?: readonly MaterialRecipe[];
62
+ readonly model?: AssetRef;
63
+ readonly castShadow?: boolean;
64
+ }
65
+ interface SkyGradient {
66
+ readonly top: number;
67
+ readonly horizon: number;
68
+ readonly glow: number;
69
+ }
70
+ interface FogSpec {
71
+ readonly color: number;
72
+ readonly near: number;
73
+ readonly far: number;
74
+ }
75
+ interface HemiLightSpec {
76
+ readonly sky: number;
77
+ readonly ground: number;
78
+ readonly intensity: number;
79
+ }
80
+ interface KeyLightSpec {
81
+ readonly color: number;
82
+ readonly intensity: number;
83
+ readonly position: readonly [number, number, number];
84
+ }
85
+ /** Scenery models repeated along both sides of the play space, recycled ahead of the camera. */
86
+ interface PropSpec {
87
+ readonly models: readonly AssetRef[];
88
+ readonly tint: number;
89
+ readonly windowGlow: number;
90
+ readonly glow: number;
91
+ readonly rows: number;
92
+ readonly spacing: number;
93
+ readonly lateral: readonly [number, number];
94
+ readonly footprint: readonly [number, number];
95
+ readonly baseY: number;
96
+ }
97
+ interface EnvironmentSpec {
98
+ readonly background: number;
99
+ readonly sky: SkyGradient;
100
+ readonly hdri?: AssetRef;
101
+ readonly hdriGain?: number;
102
+ readonly props?: PropSpec;
103
+ readonly fog: FogSpec;
104
+ readonly hemi: HemiLightSpec;
105
+ readonly key: KeyLightSpec;
106
+ readonly exposure: number;
107
+ }
108
+ interface ParallaxLayer {
109
+ readonly image: AssetRef;
110
+ readonly depth: number;
111
+ readonly scrollFactor: number;
112
+ readonly tint?: number;
113
+ }
114
+ interface PostFxSpec {
115
+ readonly bloom: number;
116
+ readonly vignette: number;
117
+ readonly grain: number;
118
+ readonly toneMapping: ToneMapping;
119
+ }
120
+ /** CSS custom properties the skin sets on the document root. */
121
+ type UiTokens = Readonly<Record<string, string>>;
122
+ /** Colours that carry gameplay meaning; a skin may restyle them but must keep them apart without colour. */
123
+ interface SemanticColours {
124
+ readonly padTiers: readonly number[];
125
+ readonly shield: number;
126
+ readonly hazard: number;
127
+ readonly jackpot: number;
128
+ readonly boost: number;
129
+ readonly spark: number;
130
+ }
131
+ interface AudioSpec<Cue extends string = string> {
132
+ readonly music: Readonly<Record<string, AssetRef>>;
133
+ readonly sfx: Readonly<Record<Cue, AssetRef>>;
134
+ }
135
+ interface TierSpec {
136
+ readonly maxTexture: 512 | 1024 | 2048;
137
+ readonly shadows: boolean;
138
+ readonly bloomScale: number;
139
+ readonly hdri: boolean;
140
+ }
141
+ /** Everything one skin owns for a game's `Role` and `Cue` lists; a forgotten role or cue is a type error. */
142
+ interface SkinBinding<Role extends string, Cue extends string = string> {
143
+ readonly id: string;
144
+ readonly contractVersion: 1;
145
+ readonly roles: Readonly<Record<Role, RoleLook>>;
146
+ readonly environment: EnvironmentSpec;
147
+ readonly layers: readonly ParallaxLayer[];
148
+ readonly post: PostFxSpec;
149
+ readonly ui: UiTokens;
150
+ readonly semantics: SemanticColours;
151
+ readonly audio: AudioSpec<Cue>;
152
+ readonly tiers: {
153
+ readonly mobile: TierSpec;
154
+ readonly desktop: TierSpec;
155
+ };
156
+ }
157
+
158
+ /** Makes `skin` the one every role lookup reads from; a build selects exactly one. */
159
+ declare const setActiveSkin: <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>) => void;
160
+ /** The selected skin; throws when nothing selected one, so a missing composition root fails loudly. */
161
+ declare const activeSkin: <Role extends string, Cue extends string>() => SkinBinding<Role, Cue>;
162
+
163
+ /** One shared load per asset path; `dispose` hands every loaded value to `free` and forgets them all. */
164
+ interface AssetCache<T> {
165
+ get(path: string): Promise<T>;
166
+ dispose(free: (value: T) => void): Promise<void>;
167
+ }
168
+ /** Creates an asset cache over `load`; a failed load is forgotten so the next `get` retries. */
169
+ declare const createAssetCache: <T>(load: (path: string) => Promise<T>) => AssetCache<T>;
170
+
171
+ /** The skin `load` brings (a preview), or `built` when there is no loader or the load fails. */
172
+ declare const pickSkin: <S>(built: S, load: (() => Promise<{
173
+ readonly skin: S;
174
+ }>) | undefined) => Promise<S>;
175
+
176
+ /** The colour `skin` gives `role` (a shader uniform, a tint, a burst). */
177
+ declare const roleColour: <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role) => number;
178
+ /** The colour of variant `index` of `role`, in the skin's order. */
179
+ declare const roleVariantColour: <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role, index: number) => number;
180
+
181
+ /** Anything with an inline style, such as `document.documentElement`. */
182
+ interface StyleTarget {
183
+ readonly style: {
184
+ setProperty(name: string, value: string): void;
185
+ };
186
+ }
187
+ /** Sets each of `ui`'s CSS custom properties on `root`, so the DOM chrome reads its colours from the skin. */
188
+ declare const applySkinUi: (root: StyleTarget, ui: UiTokens) => void;
189
+
190
+ /** The ids of the shared skins, in the order they unlock. */
191
+ declare enum GameSkinId {
192
+ NightCircuit = "night-circuit",
193
+ DuskHighway = "dusk-highway",
194
+ EmberLine = "ember-line",
195
+ DeepCurrent = "deep-current"
196
+ }
197
+
198
+ /** A shared skin as colours with no game roles; each game maps its own roles onto these swatches. */
199
+ interface SkinPalette {
200
+ readonly id: GameSkinId;
201
+ readonly name: string;
202
+ readonly skyTop: number;
203
+ readonly skyBand: number;
204
+ readonly ground: number;
205
+ readonly accent: number;
206
+ readonly figure: number;
207
+ readonly danger: number;
208
+ readonly reward: number;
209
+ readonly rewardLight: number;
210
+ }
211
+
212
+ /** The shared skins, in unlock order. */
213
+ declare const GAME_SKINS: readonly SkinPalette[];
214
+ /** The shared skin with `id` (a `?skin=` value), or undefined when no shared skin has it. */
215
+ declare const gameSkin: (id: string) => SkinPalette | undefined;
216
+
217
+ /** `colour` as a six-digit CSS hex string. */
218
+ declare const hexCss: (colour: number) => string;
219
+ /** The palette as `--skin-*` CSS custom properties, ready for `applySkinUi`. */
220
+ declare const paletteUi: (palette: SkinPalette) => UiTokens;
221
+
222
+ export { type AssetCache, type AssetRef, type AudioSpec, EnvironmentRole, type EnvironmentSpec, type FogSpec, GAME_SKINS, GameSkinId, type HemiLightSpec, type KeyLightSpec, MaterialBlending, MaterialKind, type MaterialRecipe, MaterialSide, type ParallaxLayer, type PostFxSpec, type PropSpec, type RoleLook, type SemanticColours, type SkinBinding, type SkinPalette, type SkyGradient, type StyleTarget, type TierSpec, ToneMapping, type UiTokens, activeSkin, applySkinUi, createAssetCache, gameSkin, hexCss, paletteUi, pickSkin, roleColour, roleVariantColour, setActiveSkin };
package/dist/index.js ADDED
@@ -0,0 +1,209 @@
1
+ 'use strict';
2
+
3
+ // src/contract/environmentRole.ts
4
+ var EnvironmentRole = /* @__PURE__ */ ((EnvironmentRole2) => {
5
+ EnvironmentRole2["Sky"] = "sky";
6
+ return EnvironmentRole2;
7
+ })(EnvironmentRole || {});
8
+
9
+ // src/contract/materialBlending.ts
10
+ var MaterialBlending = /* @__PURE__ */ ((MaterialBlending2) => {
11
+ MaterialBlending2["Normal"] = "normal";
12
+ MaterialBlending2["Additive"] = "additive";
13
+ return MaterialBlending2;
14
+ })(MaterialBlending || {});
15
+
16
+ // src/contract/materialKind.ts
17
+ var MaterialKind = /* @__PURE__ */ ((MaterialKind2) => {
18
+ MaterialKind2["Lambert"] = "lambert";
19
+ MaterialKind2["Unlit"] = "unlit";
20
+ MaterialKind2["Standard"] = "standard";
21
+ MaterialKind2["Line"] = "line";
22
+ MaterialKind2["Shader"] = "shader";
23
+ return MaterialKind2;
24
+ })(MaterialKind || {});
25
+
26
+ // src/contract/materialSide.ts
27
+ var MaterialSide = /* @__PURE__ */ ((MaterialSide2) => {
28
+ MaterialSide2["Front"] = "front";
29
+ MaterialSide2["Back"] = "back";
30
+ MaterialSide2["Double"] = "double";
31
+ return MaterialSide2;
32
+ })(MaterialSide || {});
33
+
34
+ // src/contract/toneMapping.ts
35
+ var ToneMapping = /* @__PURE__ */ ((ToneMapping2) => {
36
+ ToneMapping2["None"] = "none";
37
+ ToneMapping2["Aces"] = "aces";
38
+ ToneMapping2["Agx"] = "agx";
39
+ return ToneMapping2;
40
+ })(ToneMapping || {});
41
+
42
+ // src/core/active.ts
43
+ var current;
44
+ var setActiveSkin = (skin) => {
45
+ current = skin;
46
+ };
47
+ var activeSkin = () => {
48
+ if (current === void 0) {
49
+ throw new Error("No skin is active: call setActiveSkin before reading roles");
50
+ }
51
+ return current;
52
+ };
53
+
54
+ // src/core/assetCache.ts
55
+ var createAssetCache = (load) => {
56
+ const byPath = /* @__PURE__ */ new Map();
57
+ return {
58
+ get(path) {
59
+ const known = byPath.get(path);
60
+ if (known !== void 0) {
61
+ return known;
62
+ }
63
+ const next = load(path);
64
+ byPath.set(path, next);
65
+ next.catch(() => byPath.delete(path));
66
+ return next;
67
+ },
68
+ async dispose(free) {
69
+ const all = [...byPath.values()];
70
+ byPath.clear();
71
+ for (const value of await Promise.allSettled(all)) {
72
+ if (value.status === "fulfilled") {
73
+ free(value.value);
74
+ }
75
+ }
76
+ }
77
+ };
78
+ };
79
+
80
+ // src/core/pickSkin.ts
81
+ var pickSkin = async (built, load) => {
82
+ if (load === void 0) {
83
+ return built;
84
+ }
85
+ try {
86
+ return (await load()).skin;
87
+ } catch {
88
+ return built;
89
+ }
90
+ };
91
+
92
+ // src/core/roleColour.ts
93
+ var colourOf = (role, recipe) => {
94
+ if (recipe.color === void 0) {
95
+ throw new Error(`Skin role ${role} has no colour`);
96
+ }
97
+ return recipe.color;
98
+ };
99
+ var roleColour = (skin, role) => colourOf(role, skin.roles[role].material);
100
+ var roleVariantColour = (skin, role, index) => {
101
+ const recipe = skin.roles[role].variants?.[index];
102
+ if (recipe === void 0) {
103
+ throw new Error(`Skin role ${role} has no variant ${index}`);
104
+ }
105
+ return colourOf(role, recipe);
106
+ };
107
+
108
+ // src/core/applySkinUi.ts
109
+ var applySkinUi = (root, ui) => {
110
+ for (const [name, value] of Object.entries(ui)) {
111
+ root.style.setProperty(name, value);
112
+ }
113
+ };
114
+
115
+ // src/palettes/gameSkinId.ts
116
+ var GameSkinId = /* @__PURE__ */ ((GameSkinId2) => {
117
+ GameSkinId2["NightCircuit"] = "night-circuit";
118
+ GameSkinId2["DuskHighway"] = "dusk-highway";
119
+ GameSkinId2["EmberLine"] = "ember-line";
120
+ GameSkinId2["DeepCurrent"] = "deep-current";
121
+ return GameSkinId2;
122
+ })(GameSkinId || {});
123
+
124
+ // src/palettes/palettes.ts
125
+ var NIGHT_CIRCUIT = {
126
+ id: "night-circuit" /* NightCircuit */,
127
+ name: "Night circuit",
128
+ skyTop: 197382,
129
+ skyBand: 9050668,
130
+ ground: 2041400,
131
+ accent: 7336959,
132
+ figure: 12174300,
133
+ danger: 11032108,
134
+ reward: 16765503,
135
+ rewardLight: 16773544
136
+ };
137
+ var DUSK_HIGHWAY = {
138
+ id: "dusk-highway" /* DuskHighway */,
139
+ name: "Dusk highway",
140
+ skyTop: 1182748,
141
+ skyBand: 12084282,
142
+ ground: 3025466,
143
+ accent: 16761963,
144
+ figure: 13156276,
145
+ danger: 12083258,
146
+ reward: 16761963,
147
+ rewardLight: 16770752
148
+ };
149
+ var EMBER_LINE = {
150
+ id: "ember-line" /* EmberLine */,
151
+ name: "Ember line",
152
+ skyTop: 919045,
153
+ skyBand: 12604988,
154
+ ground: 2825498,
155
+ accent: 16747084,
156
+ figure: 14207160,
157
+ danger: 8007196,
158
+ reward: 16764810,
159
+ rewardLight: 16773334
160
+ };
161
+ var DEEP_CURRENT = {
162
+ id: "deep-current" /* DeepCurrent */,
163
+ name: "Deep current",
164
+ skyTop: 133389,
165
+ skyBand: 2060154,
166
+ ground: 1191994,
167
+ accent: 8257472,
168
+ figure: 10473686,
169
+ danger: 12868168,
170
+ reward: 13234943,
171
+ rewardLight: 15858943
172
+ };
173
+ var GAME_SKINS = [NIGHT_CIRCUIT, DUSK_HIGHWAY, EMBER_LINE, DEEP_CURRENT];
174
+ var gameSkin = (id) => GAME_SKINS.find((skin) => skin.id === id);
175
+
176
+ // src/palettes/paletteUi.ts
177
+ var HEX_RADIX = 16;
178
+ var HEX_DIGITS = 6;
179
+ var hexCss = (colour) => `#${colour.toString(HEX_RADIX).padStart(HEX_DIGITS, "0")}`;
180
+ var paletteUi = (palette) => ({
181
+ "--skin-sky-top": hexCss(palette.skyTop),
182
+ "--skin-sky-band": hexCss(palette.skyBand),
183
+ "--skin-ground": hexCss(palette.ground),
184
+ "--skin-accent": hexCss(palette.accent),
185
+ "--skin-figure": hexCss(palette.figure),
186
+ "--skin-danger": hexCss(palette.danger),
187
+ "--skin-reward": hexCss(palette.reward),
188
+ "--skin-reward-light": hexCss(palette.rewardLight)
189
+ });
190
+
191
+ exports.EnvironmentRole = EnvironmentRole;
192
+ exports.GAME_SKINS = GAME_SKINS;
193
+ exports.GameSkinId = GameSkinId;
194
+ exports.MaterialBlending = MaterialBlending;
195
+ exports.MaterialKind = MaterialKind;
196
+ exports.MaterialSide = MaterialSide;
197
+ exports.ToneMapping = ToneMapping;
198
+ exports.activeSkin = activeSkin;
199
+ exports.applySkinUi = applySkinUi;
200
+ exports.createAssetCache = createAssetCache;
201
+ exports.gameSkin = gameSkin;
202
+ exports.hexCss = hexCss;
203
+ exports.paletteUi = paletteUi;
204
+ exports.pickSkin = pickSkin;
205
+ exports.roleColour = roleColour;
206
+ exports.roleVariantColour = roleVariantColour;
207
+ exports.setActiveSkin = setActiveSkin;
208
+ //# sourceMappingURL=index.js.map
209
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/contract/environmentRole.ts","../src/contract/materialBlending.ts","../src/contract/materialKind.ts","../src/contract/materialSide.ts","../src/contract/toneMapping.ts","../src/core/active.ts","../src/core/assetCache.ts","../src/core/pickSkin.ts","../src/core/roleColour.ts","../src/core/applySkinUi.ts","../src/palettes/gameSkinId.ts","../src/palettes/palettes.ts","../src/palettes/paletteUi.ts"],"names":["EnvironmentRole","MaterialBlending","MaterialKind","MaterialSide","ToneMapping","GameSkinId"],"mappings":";;;AACO,IAAK,eAAA,qBAAAA,gBAAAA,KAAL;AAAuB,EAAAA,iBAAA,KAAA,CAAA,GAAM,KAAA;AAAxB,EAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;;ACAL,IAAK,gBAAA,qBAAAC,iBAAAA,KAAL;AAAwB,EAAAA,kBAAA,QAAA,CAAA,GAAS,QAAA;AAAU,EAAAA,kBAAA,UAAA,CAAA,GAAW,UAAA;AAAjD,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA;;;ACAL,IAAK,YAAA,qBAAAC,aAAAA,KAAL;AAAoB,EAAAA,cAAA,SAAA,CAAA,GAAU,SAAA;AAAW,EAAAA,cAAA,OAAA,CAAA,GAAQ,OAAA;AAAS,EAAAA,cAAA,UAAA,CAAA,GAAW,UAAA;AAAY,EAAAA,cAAA,MAAA,CAAA,GAAO,MAAA;AAAQ,EAAAA,cAAA,QAAA,CAAA,GAAS,QAAA;AAApG,EAAA,OAAAA,aAAAA;AAAA,CAAA,EAAA,YAAA,IAAA,EAAA;;;ACAL,IAAK,YAAA,qBAAAC,aAAAA,KAAL;AAAoB,EAAAA,cAAA,OAAA,CAAA,GAAQ,OAAA;AAAS,EAAAA,cAAA,MAAA,CAAA,GAAO,MAAA;AAAQ,EAAAA,c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AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,qBAAA,EAAuB,MAAA,CAAO,OAAA,CAAQ,WAAW;AACnD,CAAA","file":"index.js","sourcesContent":["/** Roles the environment paints outside the game's role list. */\nexport enum EnvironmentRole { Sky = 'sky' }\n","/** How a role's colour mixes with what is behind it. */\nexport enum MaterialBlending { Normal = 'normal', Additive = 'additive' }\n","/** How a role is drawn; the engine adapter maps each kind to a material. */\nexport enum MaterialKind { Lambert = 'lambert', Unlit = 'unlit', Standard = 'standard', Line = 'line', Shader = 'shader' }\n","/** Which faces of a role's mesh are drawn. */\nexport enum MaterialSide { Front = 'front', Back = 'back', Double = 'double' }\n","/** The tone curve a skin renders through. */\nexport enum ToneMapping { None = 'none', Aces = 'aces', Agx = 'agx' }\n","import type { SkinBinding } from '../contract/types';\n\ntype AnySkin = SkinBinding<string, string>;\n\nlet current: AnySkin | undefined;\n\n/** Makes `skin` the one every role lookup reads from; a build selects exactly one. */\nexport const setActiveSkin = <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>): void => {\n current = skin as unknown as AnySkin;\n};\n\n/** The selected skin; throws when nothing selected one, so a missing composition root fails loudly. */\nexport const activeSkin = <Role extends string, Cue extends string>(): SkinBinding<Role, Cue> => {\n if (current === undefined) {\n throw new Error('No skin is active: call setActiveSkin before reading roles');\n }\n return current as unknown as SkinBinding<Role, Cue>;\n};\n","/** One shared load per asset path; `dispose` hands every loaded value to `free` and forgets them all. */\nexport interface AssetCache<T> {\n get(path: string): Promise<T>;\n dispose(free: (value: T) => void): Promise<void>;\n}\n\n/** Creates an asset cache over `load`; a failed load is forgotten so the next `get` retries. */\nexport const createAssetCache = <T>(load: (path: string) => Promise<T>): AssetCache<T> => {\n const byPath = new Map<string, Promise<T>>();\n return {\n get(path: string): Promise<T> {\n const known = byPath.get(path);\n if (known !== undefined) {\n return known;\n }\n const next = load(path);\n byPath.set(path, next);\n next.catch(() => byPath.delete(path));\n return next;\n },\n async dispose(free: (value: T) => void): Promise<void> {\n const all = [...byPath.values()];\n byPath.clear();\n for (const value of await Promise.allSettled(all)) {\n if (value.status === 'fulfilled') {\n free(value.value);\n }\n }\n },\n };\n};\n","/** The skin `load` brings (a preview), or `built` when there is no loader or the load fails. */\nexport const pickSkin = async <S>(built: S, load: (() => Promise<{ readonly skin: S }>) | undefined): Promise<S> => {\n if (load === undefined) {\n return built;\n }\n try {\n return (await load()).skin;\n } catch {\n return built;\n }\n};\n","import type { MaterialRecipe, SkinBinding } from '../contract/types';\n\nconst colourOf = (role: string, recipe: MaterialRecipe): number => {\n if (recipe.color === undefined) {\n throw new Error(`Skin role ${role} has no colour`);\n }\n return recipe.color;\n};\n\n/** The colour `skin` gives `role` (a shader uniform, a tint, a burst). */\nexport const roleColour = <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role): number =>\n colourOf(role, skin.roles[role].material);\n\n/** The colour of variant `index` of `role`, in the skin's order. */\nexport const roleVariantColour = <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role, index: number): number => {\n const recipe = skin.roles[role].variants?.[index];\n if (recipe === undefined) {\n throw new Error(`Skin role ${role} has no variant ${index}`);\n }\n return colourOf(role, recipe);\n};\n","import type { UiTokens } from '../contract/types';\n\n/** Anything with an inline style, such as `document.documentElement`. */\nexport interface StyleTarget { readonly style: { setProperty(name: string, value: string): void } }\n\n/** Sets each of `ui`'s CSS custom properties on `root`, so the DOM chrome reads its colours from the skin. */\nexport const applySkinUi = (root: StyleTarget, ui: UiTokens): void => {\n for (const [name, value] of Object.entries(ui)) {\n root.style.setProperty(name, value);\n }\n};\n","/** The ids of the shared skins, in the order they unlock. */\nexport enum GameSkinId {\n NightCircuit = 'night-circuit',\n DuskHighway = 'dusk-highway',\n EmberLine = 'ember-line',\n DeepCurrent = 'deep-current',\n}\n","import { GameSkinId } from './gameSkinId';\nimport type { SkinPalette } from './skinPalette';\n\nconst NIGHT_CIRCUIT: SkinPalette = {\n id: GameSkinId.NightCircuit,\n name: 'Night circuit',\n skyTop: 0x030306,\n skyBand: 0x8a1a2c,\n ground: 0x1f2638,\n accent: 0x6ff3ff,\n figure: 0xb9c3dc,\n danger: 0xa8562c,\n reward: 0xffd23f,\n rewardLight: 0xfff1a8,\n};\n\nconst DUSK_HIGHWAY: SkinPalette = {\n id: GameSkinId.DuskHighway,\n name: 'Dusk highway',\n skyTop: 0x120c1c,\n skyBand: 0xb8643a,\n ground: 0x2e2a3a,\n accent: 0xffc46b,\n figure: 0xc8bfb4,\n danger: 0xb8603a,\n reward: 0xffc46b,\n rewardLight: 0xffe6c0,\n};\n\nconst EMBER_LINE: SkinPalette = {\n id: GameSkinId.EmberLine,\n name: 'Ember line',\n skyTop: 0x0e0605,\n skyBand: 0xc0563c,\n ground: 0x2b1d1a,\n accent: 0xff8a4c,\n figure: 0xd8c8b8,\n danger: 0x7a2e1c,\n reward: 0xffcf8a,\n rewardLight: 0xfff0d6,\n};\n\nconst DEEP_CURRENT: SkinPalette = {\n id: GameSkinId.DeepCurrent,\n name: 'Deep current',\n skyTop: 0x02090d,\n skyBand: 0x1f6f7a,\n ground: 0x12303a,\n accent: 0x7dffc0,\n figure: 0x9fd0d6,\n danger: 0xc45a48,\n reward: 0xc9f2ff,\n rewardLight: 0xf1fcff,\n};\n\n/** The shared skins, in unlock order. */\nexport const GAME_SKINS: readonly SkinPalette[] = [NIGHT_CIRCUIT, DUSK_HIGHWAY, EMBER_LINE, DEEP_CURRENT];\n\n/** The shared skin with `id` (a `?skin=` value), or undefined when no shared skin has it. */\nexport const gameSkin = (id: string): SkinPalette | undefined => GAME_SKINS.find((skin) => skin.id === id);\n","import type { UiTokens } from '../contract/types';\nimport type { SkinPalette } from './skinPalette';\n\nconst HEX_RADIX = 16;\nconst HEX_DIGITS = 6;\n\n/** `colour` as a six-digit CSS hex string. */\nexport const hexCss = (colour: number): string => `#${colour.toString(HEX_RADIX).padStart(HEX_DIGITS, '0')}`;\n\n/** The palette as `--skin-*` CSS custom properties, ready for `applySkinUi`. */\nexport const paletteUi = (palette: SkinPalette): UiTokens => ({\n '--skin-sky-top': hexCss(palette.skyTop),\n '--skin-sky-band': hexCss(palette.skyBand),\n '--skin-ground': hexCss(palette.ground),\n '--skin-accent': hexCss(palette.accent),\n '--skin-figure': hexCss(palette.figure),\n '--skin-danger': hexCss(palette.danger),\n '--skin-reward': hexCss(palette.reward),\n '--skin-reward-light': hexCss(palette.rewardLight),\n});\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,191 @@
1
+ // src/contract/environmentRole.ts
2
+ var EnvironmentRole = /* @__PURE__ */ ((EnvironmentRole2) => {
3
+ EnvironmentRole2["Sky"] = "sky";
4
+ return EnvironmentRole2;
5
+ })(EnvironmentRole || {});
6
+
7
+ // src/contract/materialBlending.ts
8
+ var MaterialBlending = /* @__PURE__ */ ((MaterialBlending2) => {
9
+ MaterialBlending2["Normal"] = "normal";
10
+ MaterialBlending2["Additive"] = "additive";
11
+ return MaterialBlending2;
12
+ })(MaterialBlending || {});
13
+
14
+ // src/contract/materialKind.ts
15
+ var MaterialKind = /* @__PURE__ */ ((MaterialKind2) => {
16
+ MaterialKind2["Lambert"] = "lambert";
17
+ MaterialKind2["Unlit"] = "unlit";
18
+ MaterialKind2["Standard"] = "standard";
19
+ MaterialKind2["Line"] = "line";
20
+ MaterialKind2["Shader"] = "shader";
21
+ return MaterialKind2;
22
+ })(MaterialKind || {});
23
+
24
+ // src/contract/materialSide.ts
25
+ var MaterialSide = /* @__PURE__ */ ((MaterialSide2) => {
26
+ MaterialSide2["Front"] = "front";
27
+ MaterialSide2["Back"] = "back";
28
+ MaterialSide2["Double"] = "double";
29
+ return MaterialSide2;
30
+ })(MaterialSide || {});
31
+
32
+ // src/contract/toneMapping.ts
33
+ var ToneMapping = /* @__PURE__ */ ((ToneMapping2) => {
34
+ ToneMapping2["None"] = "none";
35
+ ToneMapping2["Aces"] = "aces";
36
+ ToneMapping2["Agx"] = "agx";
37
+ return ToneMapping2;
38
+ })(ToneMapping || {});
39
+
40
+ // src/core/active.ts
41
+ var current;
42
+ var setActiveSkin = (skin) => {
43
+ current = skin;
44
+ };
45
+ var activeSkin = () => {
46
+ if (current === void 0) {
47
+ throw new Error("No skin is active: call setActiveSkin before reading roles");
48
+ }
49
+ return current;
50
+ };
51
+
52
+ // src/core/assetCache.ts
53
+ var createAssetCache = (load) => {
54
+ const byPath = /* @__PURE__ */ new Map();
55
+ return {
56
+ get(path) {
57
+ const known = byPath.get(path);
58
+ if (known !== void 0) {
59
+ return known;
60
+ }
61
+ const next = load(path);
62
+ byPath.set(path, next);
63
+ next.catch(() => byPath.delete(path));
64
+ return next;
65
+ },
66
+ async dispose(free) {
67
+ const all = [...byPath.values()];
68
+ byPath.clear();
69
+ for (const value of await Promise.allSettled(all)) {
70
+ if (value.status === "fulfilled") {
71
+ free(value.value);
72
+ }
73
+ }
74
+ }
75
+ };
76
+ };
77
+
78
+ // src/core/pickSkin.ts
79
+ var pickSkin = async (built, load) => {
80
+ if (load === void 0) {
81
+ return built;
82
+ }
83
+ try {
84
+ return (await load()).skin;
85
+ } catch {
86
+ return built;
87
+ }
88
+ };
89
+
90
+ // src/core/roleColour.ts
91
+ var colourOf = (role, recipe) => {
92
+ if (recipe.color === void 0) {
93
+ throw new Error(`Skin role ${role} has no colour`);
94
+ }
95
+ return recipe.color;
96
+ };
97
+ var roleColour = (skin, role) => colourOf(role, skin.roles[role].material);
98
+ var roleVariantColour = (skin, role, index) => {
99
+ const recipe = skin.roles[role].variants?.[index];
100
+ if (recipe === void 0) {
101
+ throw new Error(`Skin role ${role} has no variant ${index}`);
102
+ }
103
+ return colourOf(role, recipe);
104
+ };
105
+
106
+ // src/core/applySkinUi.ts
107
+ var applySkinUi = (root, ui) => {
108
+ for (const [name, value] of Object.entries(ui)) {
109
+ root.style.setProperty(name, value);
110
+ }
111
+ };
112
+
113
+ // src/palettes/gameSkinId.ts
114
+ var GameSkinId = /* @__PURE__ */ ((GameSkinId2) => {
115
+ GameSkinId2["NightCircuit"] = "night-circuit";
116
+ GameSkinId2["DuskHighway"] = "dusk-highway";
117
+ GameSkinId2["EmberLine"] = "ember-line";
118
+ GameSkinId2["DeepCurrent"] = "deep-current";
119
+ return GameSkinId2;
120
+ })(GameSkinId || {});
121
+
122
+ // src/palettes/palettes.ts
123
+ var NIGHT_CIRCUIT = {
124
+ id: "night-circuit" /* NightCircuit */,
125
+ name: "Night circuit",
126
+ skyTop: 197382,
127
+ skyBand: 9050668,
128
+ ground: 2041400,
129
+ accent: 7336959,
130
+ figure: 12174300,
131
+ danger: 11032108,
132
+ reward: 16765503,
133
+ rewardLight: 16773544
134
+ };
135
+ var DUSK_HIGHWAY = {
136
+ id: "dusk-highway" /* DuskHighway */,
137
+ name: "Dusk highway",
138
+ skyTop: 1182748,
139
+ skyBand: 12084282,
140
+ ground: 3025466,
141
+ accent: 16761963,
142
+ figure: 13156276,
143
+ danger: 12083258,
144
+ reward: 16761963,
145
+ rewardLight: 16770752
146
+ };
147
+ var EMBER_LINE = {
148
+ id: "ember-line" /* EmberLine */,
149
+ name: "Ember line",
150
+ skyTop: 919045,
151
+ skyBand: 12604988,
152
+ ground: 2825498,
153
+ accent: 16747084,
154
+ figure: 14207160,
155
+ danger: 8007196,
156
+ reward: 16764810,
157
+ rewardLight: 16773334
158
+ };
159
+ var DEEP_CURRENT = {
160
+ id: "deep-current" /* DeepCurrent */,
161
+ name: "Deep current",
162
+ skyTop: 133389,
163
+ skyBand: 2060154,
164
+ ground: 1191994,
165
+ accent: 8257472,
166
+ figure: 10473686,
167
+ danger: 12868168,
168
+ reward: 13234943,
169
+ rewardLight: 15858943
170
+ };
171
+ var GAME_SKINS = [NIGHT_CIRCUIT, DUSK_HIGHWAY, EMBER_LINE, DEEP_CURRENT];
172
+ var gameSkin = (id) => GAME_SKINS.find((skin) => skin.id === id);
173
+
174
+ // src/palettes/paletteUi.ts
175
+ var HEX_RADIX = 16;
176
+ var HEX_DIGITS = 6;
177
+ var hexCss = (colour) => `#${colour.toString(HEX_RADIX).padStart(HEX_DIGITS, "0")}`;
178
+ var paletteUi = (palette) => ({
179
+ "--skin-sky-top": hexCss(palette.skyTop),
180
+ "--skin-sky-band": hexCss(palette.skyBand),
181
+ "--skin-ground": hexCss(palette.ground),
182
+ "--skin-accent": hexCss(palette.accent),
183
+ "--skin-figure": hexCss(palette.figure),
184
+ "--skin-danger": hexCss(palette.danger),
185
+ "--skin-reward": hexCss(palette.reward),
186
+ "--skin-reward-light": hexCss(palette.rewardLight)
187
+ });
188
+
189
+ export { EnvironmentRole, GAME_SKINS, GameSkinId, MaterialBlending, MaterialKind, MaterialSide, ToneMapping, activeSkin, applySkinUi, createAssetCache, gameSkin, hexCss, paletteUi, pickSkin, roleColour, roleVariantColour, setActiveSkin };
190
+ //# sourceMappingURL=index.mjs.map
191
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/contract/environmentRole.ts","../src/contract/materialBlending.ts","../src/contract/materialKind.ts","../src/contract/materialSide.ts","../src/contract/toneMapping.ts","../src/core/active.ts","../src/core/assetCache.ts","../src/core/pickSkin.ts","../src/core/roleColour.ts","../src/core/applySkinUi.ts","../src/palettes/gameSkinId.ts","../src/palettes/palettes.ts","../src/palettes/paletteUi.ts"],"names":["EnvironmentRole","MaterialBlending","MaterialKind","MaterialSide","ToneMapping","GameSkinId"],"mappings":";AACO,IAAK,eAAA,qBAAAA,gBAAAA,KAAL;AAAuB,EAAAA,iBAAA,KAAA,CAAA,GAAM,KAAA;AAAxB,EAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;;ACAL,IAAK,g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AA,EACR,WAAA,EAAa;AACf,CAAA;AAGO,IAAM,UAAA,GAAqC,CAAC,aAAA,EAAe,YAAA,EAAc,YAAY,YAAY;AAGjG,IAAM,QAAA,GAAW,CAAC,EAAA,KAAwC,UAAA,CAAW,KAAK,CAAC,IAAA,KAAS,IAAA,CAAK,EAAA,KAAO,EAAE;;;ACxDzG,IAAM,SAAA,GAAY,EAAA;AAClB,IAAM,UAAA,GAAa,CAAA;AAGZ,IAAM,MAAA,GAAS,CAAC,MAAA,KAA2B,CAAA,CAAA,EAAI,MAAA,CAAO,QAAA,CAAS,SAAS,CAAA,CAAE,QAAA,CAAS,UAAA,EAAY,GAAG,CAAC,CAAA;AAGnG,IAAM,SAAA,GAAY,CAAC,OAAA,MAAoC;AAAA,EAC5D,gBAAA,EAAkB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACvC,iBAAA,EAAmB,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA;AAAA,EACzC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,eAAA,EAAiB,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA;AAAA,EACtC,qBAAA,EAAuB,MAAA,CAAO,OAAA,CAAQ,WAAW;AACnD,CAAA","file":"index.mjs","sourcesContent":["/** Roles the environment paints outside the game's role list. */\nexport enum EnvironmentRole { Sky = 'sky' }\n","/** How a role's colour mixes with what is behind it. */\nexport enum MaterialBlending { Normal = 'normal', Additive = 'additive' }\n","/** How a role is drawn; the engine adapter maps each kind to a material. */\nexport enum MaterialKind { Lambert = 'lambert', Unlit = 'unlit', Standard = 'standard', Line = 'line', Shader = 'shader' }\n","/** Which faces of a role's mesh are drawn. */\nexport enum MaterialSide { Front = 'front', Back = 'back', Double = 'double' }\n","/** The tone curve a skin renders through. */\nexport enum ToneMapping { None = 'none', Aces = 'aces', Agx = 'agx' }\n","import type { SkinBinding } from '../contract/types';\n\ntype AnySkin = SkinBinding<string, string>;\n\nlet current: AnySkin | undefined;\n\n/** Makes `skin` the one every role lookup reads from; a build selects exactly one. */\nexport const setActiveSkin = <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>): void => {\n current = skin as unknown as AnySkin;\n};\n\n/** The selected skin; throws when nothing selected one, so a missing composition root fails loudly. */\nexport const activeSkin = <Role extends string, Cue extends string>(): SkinBinding<Role, Cue> => {\n if (current === undefined) {\n throw new Error('No skin is active: call setActiveSkin before reading roles');\n }\n return current as unknown as SkinBinding<Role, Cue>;\n};\n","/** One shared load per asset path; `dispose` hands every loaded value to `free` and forgets them all. */\nexport interface AssetCache<T> {\n get(path: string): Promise<T>;\n dispose(free: (value: T) => void): Promise<void>;\n}\n\n/** Creates an asset cache over `load`; a failed load is forgotten so the next `get` retries. */\nexport const createAssetCache = <T>(load: (path: string) => Promise<T>): AssetCache<T> => {\n const byPath = new Map<string, Promise<T>>();\n return {\n get(path: string): Promise<T> {\n const known = byPath.get(path);\n if (known !== undefined) {\n return known;\n }\n const next = load(path);\n byPath.set(path, next);\n next.catch(() => byPath.delete(path));\n return next;\n },\n async dispose(free: (value: T) => void): Promise<void> {\n const all = [...byPath.values()];\n byPath.clear();\n for (const value of await Promise.allSettled(all)) {\n if (value.status === 'fulfilled') {\n free(value.value);\n }\n }\n },\n };\n};\n","/** The skin `load` brings (a preview), or `built` when there is no loader or the load fails. */\nexport const pickSkin = async <S>(built: S, load: (() => Promise<{ readonly skin: S }>) | undefined): Promise<S> => {\n if (load === undefined) {\n return built;\n }\n try {\n return (await load()).skin;\n } catch {\n return built;\n }\n};\n","import type { MaterialRecipe, SkinBinding } from '../contract/types';\n\nconst colourOf = (role: string, recipe: MaterialRecipe): number => {\n if (recipe.color === undefined) {\n throw new Error(`Skin role ${role} has no colour`);\n }\n return recipe.color;\n};\n\n/** The colour `skin` gives `role` (a shader uniform, a tint, a burst). */\nexport const roleColour = <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role): number =>\n colourOf(role, skin.roles[role].material);\n\n/** The colour of variant `index` of `role`, in the skin's order. */\nexport const roleVariantColour = <Role extends string, Cue extends string>(skin: SkinBinding<Role, Cue>, role: Role, index: number): number => {\n const recipe = skin.roles[role].variants?.[index];\n if (recipe === undefined) {\n throw new Error(`Skin role ${role} has no variant ${index}`);\n }\n return colourOf(role, recipe);\n};\n","import type { UiTokens } from '../contract/types';\n\n/** Anything with an inline style, such as `document.documentElement`. */\nexport interface StyleTarget { readonly style: { setProperty(name: string, value: string): void } }\n\n/** Sets each of `ui`'s CSS custom properties on `root`, so the DOM chrome reads its colours from the skin. */\nexport const applySkinUi = (root: StyleTarget, ui: UiTokens): void => {\n for (const [name, value] of Object.entries(ui)) {\n root.style.setProperty(name, value);\n }\n};\n","/** The ids of the shared skins, in the order they unlock. */\nexport enum GameSkinId {\n NightCircuit = 'night-circuit',\n DuskHighway = 'dusk-highway',\n EmberLine = 'ember-line',\n DeepCurrent = 'deep-current',\n}\n","import { GameSkinId } from './gameSkinId';\nimport type { SkinPalette } from './skinPalette';\n\nconst NIGHT_CIRCUIT: SkinPalette = {\n id: GameSkinId.NightCircuit,\n name: 'Night circuit',\n skyTop: 0x030306,\n skyBand: 0x8a1a2c,\n ground: 0x1f2638,\n accent: 0x6ff3ff,\n figure: 0xb9c3dc,\n danger: 0xa8562c,\n reward: 0xffd23f,\n rewardLight: 0xfff1a8,\n};\n\nconst DUSK_HIGHWAY: SkinPalette = {\n id: GameSkinId.DuskHighway,\n name: 'Dusk highway',\n skyTop: 0x120c1c,\n skyBand: 0xb8643a,\n ground: 0x2e2a3a,\n accent: 0xffc46b,\n figure: 0xc8bfb4,\n danger: 0xb8603a,\n reward: 0xffc46b,\n rewardLight: 0xffe6c0,\n};\n\nconst EMBER_LINE: SkinPalette = {\n id: GameSkinId.EmberLine,\n name: 'Ember line',\n skyTop: 0x0e0605,\n skyBand: 0xc0563c,\n ground: 0x2b1d1a,\n accent: 0xff8a4c,\n figure: 0xd8c8b8,\n danger: 0x7a2e1c,\n reward: 0xffcf8a,\n rewardLight: 0xfff0d6,\n};\n\nconst DEEP_CURRENT: SkinPalette = {\n id: GameSkinId.DeepCurrent,\n name: 'Deep current',\n skyTop: 0x02090d,\n skyBand: 0x1f6f7a,\n ground: 0x12303a,\n accent: 0x7dffc0,\n figure: 0x9fd0d6,\n danger: 0xc45a48,\n reward: 0xc9f2ff,\n rewardLight: 0xf1fcff,\n};\n\n/** The shared skins, in unlock order. */\nexport const GAME_SKINS: readonly SkinPalette[] = [NIGHT_CIRCUIT, DUSK_HIGHWAY, EMBER_LINE, DEEP_CURRENT];\n\n/** The shared skin with `id` (a `?skin=` value), or undefined when no shared skin has it. */\nexport const gameSkin = (id: string): SkinPalette | undefined => GAME_SKINS.find((skin) => skin.id === id);\n","import type { UiTokens } from '../contract/types';\nimport type { SkinPalette } from './skinPalette';\n\nconst HEX_RADIX = 16;\nconst HEX_DIGITS = 6;\n\n/** `colour` as a six-digit CSS hex string. */\nexport const hexCss = (colour: number): string => `#${colour.toString(HEX_RADIX).padStart(HEX_DIGITS, '0')}`;\n\n/** The palette as `--skin-*` CSS custom properties, ready for `applySkinUi`. */\nexport const paletteUi = (palette: SkinPalette): UiTokens => ({\n '--skin-sky-top': hexCss(palette.skyTop),\n '--skin-sky-band': hexCss(palette.skyBand),\n '--skin-ground': hexCss(palette.ground),\n '--skin-accent': hexCss(palette.accent),\n '--skin-figure': hexCss(palette.figure),\n '--skin-danger': hexCss(palette.danger),\n '--skin-reward': hexCss(palette.reward),\n '--skin-reward-light': hexCss(palette.rewardLight),\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "@dloizides/game-skins",
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": "Engine-free game skin contract (roles, materials, environment, UI tokens, audio cues) plus the shared skin palettes Night circuit, Dusk highway, Ember line and Deep current. Zero deps. Extracted from Surge.",
5
+ "keywords": [
6
+ "game",
7
+ "skin",
8
+ "theme",
9
+ "palette",
10
+ "three",
11
+ "eisaipollis"
12
+ ],
13
+ "author": "dloizides",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/openmindednewby/game-skins.git"
18
+ },
19
+ "homepage": "https://github.com/openmindednewby/game-skins#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/openmindednewby/game-skins/issues"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.mjs",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "browser": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./dist/index.d.mts",
38
+ "default": "./dist/index.mjs"
39
+ },
40
+ "default": {
41
+ "types": "./dist/index.d.ts",
42
+ "default": "./dist/index.js"
43
+ }
44
+ }
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "README.md",
49
+ "CHANGELOG.md"
50
+ ],
51
+ "sideEffects": false,
52
+ "engines": {
53
+ "node": ">=18.0.0"
54
+ },
55
+ "scripts": {
56
+ "build": "rimraf dist && tsup",
57
+ "build:watch": "tsup --watch",
58
+ "test": "jest",
59
+ "test:watch": "jest --watch",
60
+ "test:coverage": "jest --coverage",
61
+ "lint": "eslint src --ext .ts",
62
+ "lint:fix": "eslint src --ext .ts --fix",
63
+ "typecheck": "tsc --noEmit",
64
+ "clean": "rimraf dist",
65
+ "security:audit": "npm audit --audit-level=high",
66
+ "prepublishOnly": "npm run clean && npm run build && npm run test"
67
+ },
68
+ "devDependencies": {
69
+ "@types/jest": "^29.5.0",
70
+ "@types/node": "^20.19.32",
71
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
72
+ "@typescript-eslint/parser": "^7.0.0",
73
+ "eslint": "^8.57.0",
74
+ "jest": "^29.7.0",
75
+ "rimraf": "^5.0.0",
76
+ "ts-jest": "^29.1.0",
77
+ "tsup": "^8.0.0",
78
+ "typescript": "^5.4.0"
79
+ }
80
+ }