@benosjs/pixel 0.0.0-stage → 0.8.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 +22 -0
- package/README.md +62 -2
- package/dist/js/index.development.js +2419 -0
- package/dist/js/index.development.js.map +1 -0
- package/dist/js/index.production.js +2119 -0
- package/dist/js/png.development.js +60 -0
- package/dist/js/png.development.js.map +1 -0
- package/dist/js/png.production.js +46 -0
- package/dist/types/ai.d.ts +37 -0
- package/dist/types/ai.d.ts.map +1 -0
- package/dist/types/character.d.ts +61 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/color.d.ts +14 -0
- package/dist/types/color.d.ts.map +1 -0
- package/dist/types/draw.d.ts +27 -0
- package/dist/types/draw.d.ts.map +1 -0
- package/dist/types/font.d.ts +5 -0
- package/dist/types/font.d.ts.map +1 -0
- package/dist/types/format.d.ts +22 -0
- package/dist/types/format.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/library/decor.d.ts +2 -0
- package/dist/types/library/decor.d.ts.map +1 -0
- package/dist/types/library/furniture.d.ts +2 -0
- package/dist/types/library/furniture.d.ts.map +1 -0
- package/dist/types/library/index.d.ts +9 -0
- package/dist/types/library/index.d.ts.map +1 -0
- package/dist/types/library/make.d.ts +6 -0
- package/dist/types/library/make.d.ts.map +1 -0
- package/dist/types/library/more.d.ts +2 -0
- package/dist/types/library/more.d.ts.map +1 -0
- package/dist/types/library/people.d.ts +2 -0
- package/dist/types/library/people.d.ts.map +1 -0
- package/dist/types/library/structure.d.ts +2 -0
- package/dist/types/library/structure.d.ts.map +1 -0
- package/dist/types/library/tech.d.ts +2 -0
- package/dist/types/library/tech.d.ts.map +1 -0
- package/dist/types/must.d.ts +6 -0
- package/dist/types/must.d.ts.map +1 -0
- package/dist/types/palette.d.ts +8 -0
- package/dist/types/palette.d.ts.map +1 -0
- package/dist/types/pixelate.d.ts +36 -0
- package/dist/types/pixelate.d.ts.map +1 -0
- package/dist/types/png.d.ts +4 -0
- package/dist/types/png.d.ts.map +1 -0
- package/dist/types/procedural.d.ts +91 -0
- package/dist/types/procedural.d.ts.map +1 -0
- package/dist/types/recolor.d.ts +14 -0
- package/dist/types/recolor.d.ts.map +1 -0
- package/dist/types/render.d.ts +13 -0
- package/dist/types/render.d.ts.map +1 -0
- package/dist/types/sheet.d.ts +19 -0
- package/dist/types/sheet.d.ts.map +1 -0
- package/package.json +39 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { deflateSync } from "node:zlib";
|
|
2
|
+
// packages/pixel/src/must.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns a value the surrounding code guarantees is present, such as an array item
|
|
5
|
+
* at an index already known to be in range. Throws if that guarantee is ever broken.
|
|
6
|
+
*/
|
|
7
|
+
function must(value) {
|
|
8
|
+
if (value === void 0) throw new Error("Internal error: a value that must exist is missing");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
// packages/pixel/src/png.ts
|
|
12
|
+
var CRC_TABLE = Array.from({ length: 256 }, (_, n) => {
|
|
13
|
+
let c = n;
|
|
14
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
15
|
+
return c >>> 0;
|
|
16
|
+
});
|
|
17
|
+
function chunk(type, data) {
|
|
18
|
+
const body = Buffer.concat([Buffer.from(type, "ascii"), data]);
|
|
19
|
+
let crc = 4294967295;
|
|
20
|
+
for (const byte of body) crc = must(CRC_TABLE[(crc ^ byte) & 255]) ^ crc >>> 8;
|
|
21
|
+
const out = Buffer.alloc(body.length + 8);
|
|
22
|
+
out.writeUInt32BE(data.length, 0);
|
|
23
|
+
body.copy(out, 4);
|
|
24
|
+
out.writeUInt32BE((crc ^ 4294967295) >>> 0, body.length + 4);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** Encodes a bitmap as a PNG file with transparency. */
|
|
28
|
+
function encodePng(bitmap) {
|
|
29
|
+
const stride = bitmap.width * 4;
|
|
30
|
+
const raw = Buffer.alloc((stride + 1) * bitmap.height);
|
|
31
|
+
for (let y = 0; y < bitmap.height; y++) raw.set(bitmap.data.subarray(y * stride, (y + 1) * stride), y * (stride + 1) + 1);
|
|
32
|
+
const header = Buffer.alloc(13);
|
|
33
|
+
header.writeUInt32BE(bitmap.width, 0);
|
|
34
|
+
header.writeUInt32BE(bitmap.height, 4);
|
|
35
|
+
header.set([
|
|
36
|
+
8,
|
|
37
|
+
6,
|
|
38
|
+
0,
|
|
39
|
+
0,
|
|
40
|
+
0
|
|
41
|
+
], 8);
|
|
42
|
+
return Buffer.concat([
|
|
43
|
+
Buffer.from([
|
|
44
|
+
137,
|
|
45
|
+
80,
|
|
46
|
+
78,
|
|
47
|
+
71,
|
|
48
|
+
13,
|
|
49
|
+
10,
|
|
50
|
+
26,
|
|
51
|
+
10
|
|
52
|
+
]),
|
|
53
|
+
chunk("IHDR", header),
|
|
54
|
+
chunk("IDAT", deflateSync(raw, { level: 9 })),
|
|
55
|
+
chunk("IEND", /* @__PURE__ */ new Uint8Array(0))
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
export { encodePng };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=png.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png.development.js","names":[],"sources":["../../src/must.ts","../../src/png.ts"],"sourcesContent":["/**\n * Returns a value the surrounding code guarantees is present, such as an array item\n * at an index already known to be in range. Throws if that guarantee is ever broken.\n */\nexport function must<T>(value: T | undefined): T {\n if (value === undefined) {\n throw new Error('Internal error: a value that must exist is missing')\n }\n return value\n}\n","import { deflateSync } from 'node:zlib'\nimport type { Bitmap } from './render.js'\nimport { must } from './must.js'\n\n// PNG writing for Node, used at build time. In the browser, draw the bitmap to a\n// canvas instead and let the browser encode it.\n\nconst CRC_TABLE = Array.from({ length: 256 }, (_, n) => {\n let c = n\n for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1\n return c >>> 0\n})\n\nfunction chunk(type: string, data: Uint8Array): Buffer {\n const body = Buffer.concat([Buffer.from(type, 'ascii'), data])\n let crc = 0xffffffff\n for (const byte of body)\n crc = must(CRC_TABLE[(crc ^ byte) & 0xff]) ^ (crc >>> 8)\n const out = Buffer.alloc(body.length + 8)\n out.writeUInt32BE(data.length, 0)\n body.copy(out, 4)\n out.writeUInt32BE((crc ^ 0xffffffff) >>> 0, body.length + 4)\n return out\n}\n\n/** Encodes a bitmap as a PNG file with transparency. */\nexport function encodePng(bitmap: Bitmap): Buffer {\n const stride = bitmap.width * 4\n const raw = Buffer.alloc((stride + 1) * bitmap.height)\n for (let y = 0; y < bitmap.height; y++) {\n // Each row starts with a filter byte; 0 means the row is stored as it is.\n raw.set(\n bitmap.data.subarray(y * stride, (y + 1) * stride),\n y * (stride + 1) + 1,\n )\n }\n const header = Buffer.alloc(13)\n header.writeUInt32BE(bitmap.width, 0)\n header.writeUInt32BE(bitmap.height, 4)\n header.set([8, 6, 0, 0, 0], 8) // 8 bits per channel, RGBA\n return Buffer.concat([\n Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),\n chunk('IHDR', header),\n chunk('IDAT', deflateSync(raw, { level: 9 })),\n chunk('IEND', new Uint8Array(0)),\n ])\n}\n"],"mappings":";;;;;;AAIA,SAAgB,KAAQ,OAAyB;CAC/C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MAAM,oDAAoD;CAEtE,OAAO;AACT;;ACFA,IAAM,YAAY,MAAM,KAAK,EAAE,QAAQ,IAAI,IAAI,GAAG,MAAM;CACtD,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,IAAI,IAAI,IAAI,aAAc,MAAM,IAAK,MAAM;CACvE,OAAO,MAAM;AACf,CAAC;AAED,SAAS,MAAM,MAAc,MAA0B;CACrD,MAAM,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,MAAM,OAAO,GAAG,IAAI,CAAC;CAC7D,IAAI,MAAM;CACV,KAAK,MAAM,QAAQ,MACjB,MAAM,KAAK,WAAW,MAAM,QAAQ,IAAK,IAAK,QAAQ;CACxD,MAAM,MAAM,OAAO,MAAM,KAAK,SAAS,CAAC;CACxC,IAAI,cAAc,KAAK,QAAQ,CAAC;CAChC,KAAK,KAAK,KAAK,CAAC;CAChB,IAAI,eAAe,MAAM,gBAAgB,GAAG,KAAK,SAAS,CAAC;CAC3D,OAAO;AACT;;AAGA,SAAgB,UAAU,QAAwB;CAChD,MAAM,SAAS,OAAO,QAAQ;CAC9B,MAAM,MAAM,OAAO,OAAO,SAAS,KAAK,OAAO,MAAM;CACrD,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAEjC,IAAI,IACF,OAAO,KAAK,SAAS,IAAI,SAAS,IAAI,KAAK,MAAM,GACjD,KAAK,SAAS,KAAK,CACrB;CAEF,MAAM,SAAS,OAAO,MAAM,EAAE;CAC9B,OAAO,cAAc,OAAO,OAAO,CAAC;CACpC,OAAO,cAAc,OAAO,QAAQ,CAAC;CACrC,OAAO,IAAI;EAAC;EAAG;EAAG;EAAG;EAAG;CAAC,GAAG,CAAC;CAC7B,OAAO,OAAO,OAAO;EACnB,OAAO,KAAK;GAAC;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;EAAI,CAAC;EAC5D,MAAM,QAAQ,MAAM;EACpB,MAAM,QAAQ,YAAY,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;EAC5C,MAAM,wBAAQ,IAAI,WAAW,CAAC,CAAC;CACjC,CAAC;AACH"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { deflateSync as u } from "node:zlib";
|
|
2
|
+
function i(t) {
|
|
3
|
+
if (t === void 0) throw new Error("Internal error: a value that must exist is missing");
|
|
4
|
+
return t;
|
|
5
|
+
}
|
|
6
|
+
var l = Array.from({ length: 256 }, (t, o) => {
|
|
7
|
+
let r = o;
|
|
8
|
+
for (let e = 0; e < 8; e++) r = r & 1 ? 3988292384 ^ r >>> 1 : r >>> 1;
|
|
9
|
+
return r >>> 0;
|
|
10
|
+
});
|
|
11
|
+
function f(t, o) {
|
|
12
|
+
const r = Buffer.concat([Buffer.from(t, "ascii"), o]);
|
|
13
|
+
let e = 4294967295;
|
|
14
|
+
for (const c of r) e = i(l[(e ^ c) & 255]) ^ e >>> 8;
|
|
15
|
+
const n = Buffer.alloc(r.length + 8);
|
|
16
|
+
return n.writeUInt32BE(o.length, 0), r.copy(n, 4), n.writeUInt32BE((e ^ 4294967295) >>> 0, r.length + 4), n;
|
|
17
|
+
}
|
|
18
|
+
function h(t) {
|
|
19
|
+
const o = t.width * 4, r = Buffer.alloc((o + 1) * t.height);
|
|
20
|
+
for (let n = 0; n < t.height; n++) r.set(t.data.subarray(n * o, (n + 1) * o), n * (o + 1) + 1);
|
|
21
|
+
const e = Buffer.alloc(13);
|
|
22
|
+
return e.writeUInt32BE(t.width, 0), e.writeUInt32BE(t.height, 4), e.set([
|
|
23
|
+
8,
|
|
24
|
+
6,
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
0
|
|
28
|
+
], 8), Buffer.concat([
|
|
29
|
+
Buffer.from([
|
|
30
|
+
137,
|
|
31
|
+
80,
|
|
32
|
+
78,
|
|
33
|
+
71,
|
|
34
|
+
13,
|
|
35
|
+
10,
|
|
36
|
+
26,
|
|
37
|
+
10
|
|
38
|
+
]),
|
|
39
|
+
f("IHDR", e),
|
|
40
|
+
f("IDAT", u(r, { level: 9 })),
|
|
41
|
+
f("IEND", /* @__PURE__ */ new Uint8Array(0))
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
h as encodePng
|
|
46
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Sprite } from './format.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turning a model's answer into a sprite. The model is asked for a palette and rows
|
|
4
|
+
* in the shared format; this checks the answer and tidies small slips, so one stray
|
|
5
|
+
* character does not waste a paid generation.
|
|
6
|
+
*/
|
|
7
|
+
/** The shape the model is asked to return. */
|
|
8
|
+
export interface AiSpriteReply {
|
|
9
|
+
name: string;
|
|
10
|
+
palette: Array<{
|
|
11
|
+
char: string;
|
|
12
|
+
colour: string;
|
|
13
|
+
}>;
|
|
14
|
+
rows: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const AI_SIZES: readonly [16, 32];
|
|
17
|
+
export type AiSize = (typeof AI_SIZES)[number];
|
|
18
|
+
export declare const AI_MAX_COLOURS = 16;
|
|
19
|
+
export declare const AI_PROMPT_MAX_LENGTH = 200;
|
|
20
|
+
export type AiSpriteResult = {
|
|
21
|
+
ok: true;
|
|
22
|
+
sprite: Sprite;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
reason: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Builds a sprite from a reply, or says why it cannot be used.
|
|
29
|
+
*
|
|
30
|
+
* Tidied quietly: rows a little too long or short, a few characters with no palette
|
|
31
|
+
* entry, palette entries nothing uses, uppercase colours. Rejected: the wrong number
|
|
32
|
+
* of rows by more than a couple, mostly unknown characters, or a nearly empty picture.
|
|
33
|
+
*/
|
|
34
|
+
export declare function spriteFromReply(reply: AiSpriteReply, size: AiSize): AiSpriteResult;
|
|
35
|
+
/** Removes control characters and squeezes whitespace in what the visitor typed. */
|
|
36
|
+
export declare function cleanPrompt(text: string): string;
|
|
37
|
+
//# sourceMappingURL=ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/ai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC;;;;GAIG;AAEH,8CAA8C;AAC9C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAChD,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,eAAO,MAAM,QAAQ,mBAAoB,CAAA;AACzC,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAA;AAE9C,eAAO,MAAM,cAAc,KAAK,CAAA;AAChC,eAAO,MAAM,oBAAoB,MAAM,CAAA;AAEvC,MAAM,MAAM,cAAc,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,GACX,cAAc,CA0EhB;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQhD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Sprite } from './format.js';
|
|
2
|
+
export interface Part {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
rows: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const HAIR_STYLES: Part[];
|
|
8
|
+
export declare const TOPS: Part[];
|
|
9
|
+
export declare const BOTTOMS: Part[];
|
|
10
|
+
export declare const ACCESSORIES: Part[];
|
|
11
|
+
export interface Swatch {
|
|
12
|
+
name: string;
|
|
13
|
+
colour: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SKIN_TONES: Swatch[];
|
|
16
|
+
export declare const HAIR_COLOURS: Swatch[];
|
|
17
|
+
export declare const TOP_COLOURS: Swatch[];
|
|
18
|
+
export declare const BOTTOM_COLOURS: Swatch[];
|
|
19
|
+
export declare const SHOE_COLOURS: Swatch[];
|
|
20
|
+
export declare const ACCENT_COLOURS: Swatch[];
|
|
21
|
+
export interface CharacterChoices {
|
|
22
|
+
skin: string;
|
|
23
|
+
hairStyle: string;
|
|
24
|
+
hairColour: string;
|
|
25
|
+
top: string;
|
|
26
|
+
topColour: string;
|
|
27
|
+
bottom: string;
|
|
28
|
+
bottomColour: string;
|
|
29
|
+
shoeColour: string;
|
|
30
|
+
accessory: string;
|
|
31
|
+
/** Used for small details: drawstrings, ties, logos, caps and headphone cups. */
|
|
32
|
+
accent: string;
|
|
33
|
+
}
|
|
34
|
+
export declare const DEFAULT_CHARACTER: CharacterChoices;
|
|
35
|
+
/** Lays maps on top of each other. Later layers cover earlier ones; dots let them show through. */
|
|
36
|
+
export declare function stack(layers: string[][]): string[];
|
|
37
|
+
/** Builds a character sprite from a set of choices. */
|
|
38
|
+
export declare function buildCharacter(choices: CharacterChoices): Sprite;
|
|
39
|
+
/** A random set of choices. Pass a random source to make it repeatable. */
|
|
40
|
+
export declare function randomCharacter(random?: () => number): CharacterChoices;
|
|
41
|
+
/** Frames that share one palette, played in order and looped. */
|
|
42
|
+
export interface SpriteAnimation {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
tags: string[];
|
|
46
|
+
palette: Record<string, string>;
|
|
47
|
+
frames: string[][];
|
|
48
|
+
/** How long each frame shows, in milliseconds. */
|
|
49
|
+
frameMs: number;
|
|
50
|
+
}
|
|
51
|
+
/** A four-frame walk on the spot: left step, stand, right step, stand. */
|
|
52
|
+
export declare function walkFrames(rows: string[]): string[][];
|
|
53
|
+
/** A two-frame idle: standing, then a slight dip as if breathing. */
|
|
54
|
+
export declare function idleFrames(rows: string[]): string[][];
|
|
55
|
+
/** Walk and idle animations for a character sprite. */
|
|
56
|
+
export declare function animateCharacter(character: Sprite): SpriteAnimation[];
|
|
57
|
+
/** All frames of an animation side by side as one sprite, ready to save as a strip. */
|
|
58
|
+
export declare function animationStrip(animation: SpriteAnimation): Sprite;
|
|
59
|
+
/** One frame of an animation as a sprite. */
|
|
60
|
+
export declare function animationFrame(animation: SpriteAnimation, index: number): Sprite;
|
|
61
|
+
//# sourceMappingURL=character.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"character.d.ts","sourceRoot":"","sources":["../../src/character.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAyCzC,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,eAAO,MAAM,WAAW,EAAE,IAAI,EAqD7B,CAAA;AAED,eAAO,MAAM,IAAI,EAAE,IAAI,EAiDtB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,IAAI,EAyBzB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,IAAI,EA4B7B,CAAA;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,UAAU,EAAE,MAAM,EAM9B,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,EAQhC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,MAAM,EAS/B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,EAMlC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,EAKhC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,EAMlC,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,U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+
export type Rgb = [number, number, number];
|
|
3
|
+
export declare function toRgb(hex: string): Rgb;
|
|
4
|
+
export declare function toHex([r, g, b]: Rgb): string;
|
|
5
|
+
/** Hue in degrees from 0 to 360; saturation and lightness from 0 to 1. */
|
|
6
|
+
export declare function toHsl(hex: string): [number, number, number];
|
|
7
|
+
export declare function fromHsl(hue: number, saturation: number, lightness: number): string;
|
|
8
|
+
/** How bright a colour looks, from 0 (black) to 1 (white). */
|
|
9
|
+
export declare function brightness(hex: string): number;
|
|
10
|
+
/** Scales a colour towards black. 1 leaves it alone, 0 gives black. */
|
|
11
|
+
export declare function darken(hex: string, amount: number): string;
|
|
12
|
+
/** Blends two colours. 0 gives the first, 1 the second. */
|
|
13
|
+
export declare function mix(from: string, to: string, amount: number): string;
|
|
14
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/color.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAE1C,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAMtC;AAED,wBAAgB,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAM5C;AAED,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAkB3D;AAED,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,MAAM,CAkBR;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED,uEAAuE;AACvE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,2DAA2D;AAC3D,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small drawing board for building a sprite's text map from shapes instead of
|
|
3
|
+
* typing every row. `rows()` returns the finished map.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Draw {
|
|
6
|
+
readonly width: number;
|
|
7
|
+
readonly height: number;
|
|
8
|
+
private readonly grid;
|
|
9
|
+
constructor(width: number, height: number);
|
|
10
|
+
get(x: number, y: number): string;
|
|
11
|
+
px(x: number, y: number, char: string): this;
|
|
12
|
+
/** Several single pixels in one colour: [[x, y], ...]. */
|
|
13
|
+
dots(char: string, points: Array<[number, number]>): this;
|
|
14
|
+
rect(x: number, y: number, width: number, height: number, char: string): this;
|
|
15
|
+
/** A one-pixel border just inside the given rectangle. */
|
|
16
|
+
frame(x: number, y: number, width: number, height: number, char: string): this;
|
|
17
|
+
hline(x: number, y: number, length: number, char: string): this;
|
|
18
|
+
vline(x: number, y: number, length: number, char: string): this;
|
|
19
|
+
/** A filled circle. Use a centre ending in .5 for an even diameter. */
|
|
20
|
+
disc(cx: number, cy: number, radius: number, char: string): this;
|
|
21
|
+
/** Stamps a text map at a position. '.' leaves what is underneath. */
|
|
22
|
+
stamp(x: number, y: number, rows: string[]): this;
|
|
23
|
+
/** Outlines the drawing: every empty pixel that touches a filled one is filled. */
|
|
24
|
+
outline(char?: string): this;
|
|
25
|
+
rows(): string[];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=draw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../src/draw.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,IAAI;IACf,QAAQ,CAAC,KA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E,GAAG,IAAI;IASjD,mFAAmF;IACnF,OAAO,CAAC,IAAI,SAAM,GAAG,IAAI;IAkBzB,IAAI,IAAI,MAAM,EAAE;CAGjB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Sprite } from './format.js';
|
|
2
|
+
export declare const FONT_HEIGHT = 7;
|
|
3
|
+
/** A line of text as a one-colour sprite. Letters are capitalised; anything else becomes a space. */
|
|
4
|
+
export declare function textSprite(text: string, colour: string): Sprite;
|
|
5
|
+
//# sourceMappingURL=font.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../src/font.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAqCzC,eAAO,MAAM,WAAW,IAAI,CAAA;AAE5B,qGAAqG;AACrG,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAc/D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared sprite format: a text map plus a palette.
|
|
3
|
+
*
|
|
4
|
+
* Each string in `rows` is one row of pixels and each character is one pixel. A
|
|
5
|
+
* character is looked up in `palette` to get its colour; '.' is always transparent.
|
|
6
|
+
* Recolouring a sprite is swapping palette values, and nothing else changes.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TRANSPARENT = ".";
|
|
9
|
+
export interface Sprite {
|
|
10
|
+
/** Lowercase words joined by hyphens. Used in URLs and file names. */
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
tags: string[];
|
|
14
|
+
/** One character per pixel, mapped to a "#rrggbb" colour. */
|
|
15
|
+
palette: Record<string, string>;
|
|
16
|
+
rows: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare const spriteWidth: (sprite: Sprite) => number;
|
|
19
|
+
export declare const spriteHeight: (sprite: Sprite) => number;
|
|
20
|
+
/** Lists everything wrong with a sprite. An empty list means it is valid. */
|
|
21
|
+
export declare function validateSprite(sprite: Sprite): string[];
|
|
22
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,WAAW,MAAM,CAAA;AAE9B,MAAM,WAAW,MAAM;IACrB,sEAAsE;IACtE,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,WAAgC,CAAA;AAC1E,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,WAAuB,CAAA;AAElE,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAiCvD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Draw } from './draw.js';
|
|
2
|
+
export { TRANSPARENT, spriteHeight, spriteWidth, validateSprite, type Sprite, } from './format.js';
|
|
3
|
+
export { SPRITES, SPRITE_ANIMATIONS, findAnimation, findSprite, } from './library/index.js';
|
|
4
|
+
export { HOUSE_PALETTE, paletteFor } from './palette.js';
|
|
5
|
+
export { createBitmap, drawSprite, renderSprite, type Bitmap, } from './render.js';
|
|
6
|
+
export { packSheet, type SheetFrame, type SpriteSheet } from './sheet.js';
|
|
7
|
+
export { ACCENT_COLOURS, ACCESSORIES, BOTTOMS, BOTTOM_COLOURS, DEFAULT_CHARACTER, HAIR_COLOURS, HAIR_STYLES, SHOE_COLOURS, SKIN_TONES, TOPS, TOP_COLOURS, animateCharacter, animationFrame, animationStrip, buildCharacter, idleFrames, randomCharacter, walkFrames, type SpriteAnimation, stack, type CharacterChoices, type Part, type Swatch, } from './character.js';
|
|
8
|
+
export { brightness, darken, fromHsl, mix, toHex, toHsl, toRgb, } from './color.js';
|
|
9
|
+
export { RECOLOUR_PRESETS, mapPalette, recolour, shiftHue, type RecolourPreset, } from './recolor.js';
|
|
10
|
+
export { FIXED_PALETTES, MAX_COLOURS, findPalette, fitSize, nearest, pixelate, shrink, type Dither, type NamedPalette, type PixelateOptions, } from './pixelate.js';
|
|
11
|
+
export { ITEM_KINDS, TILE_STYLES, createRandom, generateCreature, generateItem, generateTile, repeatSprite, type ItemKind, type TileStyle, } from './procedural.js';
|
|
12
|
+
export { FONT_HEIGHT, textSprite } from './font.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EACd,KAAK,MAAM,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,UAAU,GACX,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,KAAK,MAAM,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EACL,cAAc,EACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,eAAe,EACf,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,EACL,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,MAAM,GACZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,UAAU,EACV,MAAM,EACN,OAAO,EACP,GAAG,EACH,KAAK,EACL,KAAK,EACL,KAAK,GACN,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,KAAK,cAAc,GACpB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,OAAO,EACP,OAAO,EACP,QAAQ,EACR,MAAM,EACN,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decor.d.ts","sourceRoot":"","sources":["../../../src/library/decor.ts"],"names":[],"mappings":"AA0JA,eAAO,MAAM,KAAK,iCAQjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"furniture.d.ts","sourceRoot":"","sources":["../../../src/library/furniture.ts"],"names":[],"mappings":"AAqKA,eAAO,MAAM,SAAS,iCAMrB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SpriteAnimation } from '../character.js';
|
|
2
|
+
import type { Sprite } from '../format.js';
|
|
3
|
+
/** The tech office sprite set: furniture, tech, decor, tiles and characters in one shared palette. */
|
|
4
|
+
export declare const SPRITES: Sprite[];
|
|
5
|
+
/** Walk and idle animations for the designer and the manager. */
|
|
6
|
+
export declare const SPRITE_ANIMATIONS: SpriteAnimation[];
|
|
7
|
+
export declare function findSprite(id: string): Sprite | undefined;
|
|
8
|
+
export declare function findAnimation(id: string): SpriteAnimation | undefined;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/library/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AA4C1C,sGAAsG;AACtG,eAAO,MAAM,OAAO,EAAE,MAAM,EAS3B,CAAA;AAED,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,EAAE,eAAe,EAG9C,CAAA;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEzD;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAErE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Sprite } from '../format.js';
|
|
2
|
+
/** Builds a library sprite. Without a palette, colours come from the house palette. */
|
|
3
|
+
export declare function make(id: string, name: string, tags: string[], rows: string[], palette?: Record<string, string>): Sprite;
|
|
4
|
+
/** Checks that hand-typed rows are all `width` wide, so a typo fails loudly. */
|
|
5
|
+
export declare function art(width: number, rows: string[]): string[];
|
|
6
|
+
//# sourceMappingURL=make.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make.d.ts","sourceRoot":"","sources":["../../../src/library/make.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAG1C,uFAAuF;AACvF,wBAAgB,IAAI,CAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,MAAM,CAQR;AAED,gFAAgF;AAChF,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQ3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"more.d.ts","sourceRoot":"","sources":["../../../src/library/more.ts"],"names":[],"mappings":"AAujBA,eAAO,MAAM,YAAY,iCA8CxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"people.d.ts","sourceRoot":"","sources":["../../../src/library/people.ts"],"names":[],"mappings":"AA6BA,eAAO,MAAM,MAAM,iCAclB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../../../src/library/structure.ts"],"names":[],"mappings":"AAmGA,eAAO,MAAM,SAAS,iCAUrB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tech.d.ts","sourceRoot":"","sources":["../../../src/library/tech.ts"],"names":[],"mappings":"AAqHA,eAAO,MAAM,IAAI,iCAQhB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a value the surrounding code guarantees is present, such as an array item
|
|
3
|
+
* at an index already known to be in range. Throws if that guarantee is ever broken.
|
|
4
|
+
*/
|
|
5
|
+
export declare function must<T>(value: T | undefined): T;
|
|
6
|
+
//# sourceMappingURL=must.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"must.d.ts","sourceRoot":"","sources":["../../src/must.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,CAK/C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The house palette. Library sprites draw from these colours so that they sit well
|
|
3
|
+
* together. A sprite's own palette holds only the entries it uses.
|
|
4
|
+
*/
|
|
5
|
+
export declare const HOUSE_PALETTE: Record<string, string>;
|
|
6
|
+
/** The subset of a palette that a set of rows actually uses. */
|
|
7
|
+
export declare function paletteFor(rows: string[], source?: Record<string, string>): Record<string, string>;
|
|
8
|
+
//# sourceMappingURL=palette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/palette.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA2ChD,CAAA;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAiB,GAC7C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASxB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Rgb } from './color.js';
|
|
2
|
+
import type { Sprite } from './format.js';
|
|
3
|
+
import type { Bitmap } from './render.js';
|
|
4
|
+
/**
|
|
5
|
+
* Turns a photo or drawing into a sprite in the shared format: shrink it to a few
|
|
6
|
+
* pixels, reduce it to a small palette, and optionally dither to fake extra shades.
|
|
7
|
+
*/
|
|
8
|
+
export type Dither = 'none' | 'ordered' | 'diffusion';
|
|
9
|
+
export interface PixelateOptions {
|
|
10
|
+
/** Length of the longer side of the result, in pixels. The shape of the image is kept. */
|
|
11
|
+
size: number;
|
|
12
|
+
/** Either a fixed list of "#rrggbb" colours, or a number of colours to find in the image. */
|
|
13
|
+
palette: string[] | number;
|
|
14
|
+
dither?: Dither;
|
|
15
|
+
}
|
|
16
|
+
export declare const MAX_COLOURS: number;
|
|
17
|
+
export interface NamedPalette {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
colours: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare const FIXED_PALETTES: NamedPalette[];
|
|
23
|
+
/** The size of the result for a source image, keeping its shape and never rounding a side to zero. */
|
|
24
|
+
export declare function fitSize(sourceWidth: number, sourceHeight: number, size: number): [number, number];
|
|
25
|
+
/** A cell of the shrunken image: its average colour, or null where the source is mostly see-through. */
|
|
26
|
+
type Cell = Rgb | null;
|
|
27
|
+
/** Shrinks a bitmap by averaging each block of source pixels, weighted by how opaque they are. */
|
|
28
|
+
export declare function shrink(source: Bitmap, width: number, height: number): Cell[];
|
|
29
|
+
/** Finds up to `count` colours that represent the pixels well, by repeatedly splitting the widest group. */
|
|
30
|
+
export declare function findPalette(pixels: Rgb[], count: number): string[];
|
|
31
|
+
/** Index of the palette colour closest to a colour, weighting channels roughly as the eye does. */
|
|
32
|
+
export declare function nearest(colour: Rgb, palette: Rgb[]): number;
|
|
33
|
+
/** Converts a bitmap into a sprite. */
|
|
34
|
+
export declare function pixelate(source: Bitmap, options: PixelateOptions): Sprite;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=pixelate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixelate.d.ts","sourceRoot":"","sources":["../../src/pixelate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,GAAG,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGzC;;;GAGG;AAEH,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAA;AAErD,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAA;IACZ,6FAA6F;IAC7F,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAC1B,M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|
3
|
+
* Rule-based generators. Each takes a seed and always returns the same sprite for
|
|
4
|
+
* the same seed, so a result can be found again from its number.
|
|
5
|
+
*/
|
|
6
|
+
/** A repeatable source of random numbers from 0 up to, but not including, 1. */
|
|
7
|
+
export declare function createRandom(seed: number): () => number;
|
|
8
|
+
/** A symmetric little monster. */
|
|
9
|
+
export declare function generateCreature(seed: number): Sprite;
|
|
10
|
+
declare function potion(random: () => number): {
|
|
11
|
+
rows: string[];
|
|
12
|
+
colours: {
|
|
13
|
+
o: string;
|
|
14
|
+
g: string;
|
|
15
|
+
c: string;
|
|
16
|
+
'1': string;
|
|
17
|
+
l: string;
|
|
18
|
+
d: string;
|
|
19
|
+
t: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
declare function gem(random: () => number): {
|
|
23
|
+
rows: string[];
|
|
24
|
+
colours: {
|
|
25
|
+
o: string;
|
|
26
|
+
'1': string;
|
|
27
|
+
h: string;
|
|
28
|
+
b: string;
|
|
29
|
+
s: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
declare function sword(random: () => number): {
|
|
33
|
+
rows: string[];
|
|
34
|
+
colours: {
|
|
35
|
+
o: string;
|
|
36
|
+
h: string;
|
|
37
|
+
b: string;
|
|
38
|
+
g: string;
|
|
39
|
+
k: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
declare function shield(random: () => number): {
|
|
43
|
+
rows: string[];
|
|
44
|
+
colours: {
|
|
45
|
+
o: string;
|
|
46
|
+
m: string;
|
|
47
|
+
a: string;
|
|
48
|
+
e: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
declare function key(random: () => number): {
|
|
52
|
+
rows: string[];
|
|
53
|
+
colours: {
|
|
54
|
+
o: string;
|
|
55
|
+
g: string;
|
|
56
|
+
s: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
declare const ITEM_MAKERS: {
|
|
60
|
+
potion: typeof potion;
|
|
61
|
+
gem: typeof gem;
|
|
62
|
+
sword: typeof sword;
|
|
63
|
+
shield: typeof shield;
|
|
64
|
+
key: typeof key;
|
|
65
|
+
};
|
|
66
|
+
export type ItemKind = keyof typeof ITEM_MAKERS;
|
|
67
|
+
export declare const ITEM_KINDS: Array<{
|
|
68
|
+
id: ItemKind;
|
|
69
|
+
name: string;
|
|
70
|
+
}>;
|
|
71
|
+
/** A 16 by 16 inventory icon. */
|
|
72
|
+
export declare function generateItem(seed: number, kind: ItemKind): Sprite;
|
|
73
|
+
type Painter = (random: () => number) => (x: number, y: number) => string;
|
|
74
|
+
declare const TILE_PAINTERS: {
|
|
75
|
+
bricks: Painter;
|
|
76
|
+
planks: Painter;
|
|
77
|
+
checker: Painter;
|
|
78
|
+
cobbles: Painter;
|
|
79
|
+
speckle: Painter;
|
|
80
|
+
};
|
|
81
|
+
export type TileStyle = keyof typeof TILE_PAINTERS;
|
|
82
|
+
export declare const TILE_STYLES: Array<{
|
|
83
|
+
id: TileStyle;
|
|
84
|
+
name: string;
|
|
85
|
+
}>;
|
|
86
|
+
/** A 16 by 16 floor tile that repeats without visible seams. */
|
|
87
|
+
export declare function generateTile(seed: number, style: TileStyle): Sprite;
|
|
88
|
+
/** A sprite repeated across and down, for checking that a tile joins up with itself. */
|
|
89
|
+
export declare function repeatSprite(sprite: Sprite, across: number, down: number): Sprite;
|
|
90
|
+
export {};
|
|
91
|
+
//# sourceMappingURL=procedural.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedural.d.ts","sourceRoot":"","sources":["../../src/procedural.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIzC;;;GAGG;AAEH,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,MAAM,CASvD;AA8HD,kCAAkC;AAClC,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA2BrD;AAaD,iBAA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1,14 @@
|
|
|
1
|
+
import type { Sprite } from './format.js';
|
|
2
|
+
/** A copy of the sprite with some palette entries replaced. Unknown characters are ignored. */
|
|
3
|
+
export declare function recolour(sprite: Sprite, changes: Record<string, string>): Sprite;
|
|
4
|
+
/** A copy of the sprite with every colour passed through `change`. */
|
|
5
|
+
export declare function mapPalette(sprite: Sprite, change: (colour: string) => string): Sprite;
|
|
6
|
+
/** Rotates every colour around the colour wheel. Greys stay grey. */
|
|
7
|
+
export declare function shiftHue(sprite: Sprite, degrees: number): Sprite;
|
|
8
|
+
export interface RecolourPreset {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
apply: (colour: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export declare const RECOLOUR_PRESETS: RecolourPreset[];
|
|
14
|
+
//# sourceMappingURL=recolor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recolor.d.ts","sourceRoot":"","sources":["../../src/recolor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGzC,+FAA+F;AAC/F,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,MAAM,CAMR;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GACjC,MAAM,CAUR;AAED,qEAAqE;AACrE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAMhE;AAUD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;CAClC;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAoC5C,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Sprite } from './format.js';
|
|
2
|
+
/** Raw pixels, four bytes each in red, green, blue, alpha order. Works with canvas ImageData. */
|
|
3
|
+
export interface Bitmap {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
data: Uint8ClampedArray;
|
|
7
|
+
}
|
|
8
|
+
export declare function createBitmap(width: number, height: number): Bitmap;
|
|
9
|
+
/** Draws a sprite onto a bitmap. Each sprite pixel becomes a `scale` by `scale` block. */
|
|
10
|
+
export declare function drawSprite(target: Bitmap, sprite: Sprite, left?: number, top?: number, scale?: number): void;
|
|
11
|
+
/** A sprite as pixels, enlarged by a whole-number scale. */
|
|
12
|
+
export declare function renderSprite(sprite: Sprite, scale?: number): Bitmap;
|
|
13
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EACZ,MAAM,aAAa,CAAA;AAEpB,iGAAiG;AACjG,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,iBAAiB,CAAA;CACxB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAElE;AAUD,0FAA0F;AAC1F,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,SAAI,EACR,GAAG,SAAI,EACP,KAAK,SAAI,GACR,IAAI,CAwBN;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAS9D"}
|