@blkc-code/mapgen 0.0.0-stage → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # @blkc-code/mapgen
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
+ Grow a unique map from a project, and keep it in step as the project changes. Rooms that exist stay where they are, and new folders add new ones. The output is plain JSON, so any renderer can draw it.
4
+
5
+ ```ts
6
+ import { evolveMap, scanProject } from "@blkc-code/mapgen";
7
+
8
+ const { map, changes } = evolveMap(previous, scanProject("."), "my-project");
9
+ ```
10
+
11
+ Part of [BLKC](https://blkc.blackcode.space). Apache-2.0.
@@ -0,0 +1,132 @@
1
+ /**
2
+ * BLKC Mapgen. Grows a building from a project. Every project gets its own map: the seed comes from its
3
+ * name, and the rooms from its folders. The map evolves rather than regenerates: rooms that
4
+ * exist stay where they are, new folders add rooms, bigger folders get bigger rooms, and a
5
+ * room someone has edited by hand is never touched again.
6
+ *
7
+ * Folder names, file counts and project manifests (package.json, pnpm-workspace.yaml) are read
8
+ * here, never source code.
9
+ */
10
+ import { type RoomRole, type Theme, type WorldPlan } from "./plan.js";
11
+ export * from "./plan.js";
12
+ export * from "./project-files.js";
13
+ export * from "./tree.js";
14
+ export * from "./roads.js";
15
+ export interface MapRoom {
16
+ id: string;
17
+ name: string;
18
+ x: number;
19
+ y: number;
20
+ w: number;
21
+ h: number;
22
+ floor: string;
23
+ paths: string[];
24
+ /** lobby, lounge and quests are always there. hall is a corridor. vacant is an empty room, free for the next folder. */
25
+ role?: RoomRole;
26
+ /** Edited by hand: the generator leaves it alone. */
27
+ locked?: boolean;
28
+ files?: number;
29
+ /** The road this sits on, as a path. */
30
+ road?: string;
31
+ }
32
+ export interface MapItem {
33
+ type: string;
34
+ x: number;
35
+ y: number;
36
+ room?: string;
37
+ /** The real folder or file group this stands for. */
38
+ part?: string;
39
+ /** Shown beside it on the map, for things like a group of loose files. */
40
+ label?: string;
41
+ }
42
+ export interface MapDoor {
43
+ x: number;
44
+ y: number;
45
+ }
46
+ export interface OfficeMap {
47
+ version: 1;
48
+ /** Which world this map is for. The office if left out. */
49
+ world?: string;
50
+ /** roads: grows from the project's folders, with no size limit. halls: even rows along corridors. Left out on the oldest maps. */
51
+ layout?: "halls" | "roads";
52
+ /** How tall the rooms are in the first pair of rows. */
53
+ roomHeight?: number;
54
+ seed: string;
55
+ /** Follow the project as it changes. */
56
+ evolve: boolean;
57
+ cols: number;
58
+ rows: number;
59
+ rooms: MapRoom[];
60
+ doors: MapDoor[];
61
+ furniture: MapItem[];
62
+ log: {
63
+ at: string;
64
+ text: string;
65
+ }[];
66
+ /** Which rooms depend on which, and whether a door joins them. */
67
+ links?: MapLink[];
68
+ }
69
+ export interface MapLink {
70
+ from: string;
71
+ to: string;
72
+ door: boolean;
73
+ }
74
+ /** A map, for any world. */
75
+ export type WorldMap = OfficeMap;
76
+ export interface ProjectArea {
77
+ id: string;
78
+ name: string;
79
+ path: string;
80
+ files: number;
81
+ /** How many other areas depend on this one. */
82
+ dependents?: number;
83
+ /** The folder path it sits on, such as "apps/". */
84
+ street?: string;
85
+ }
86
+ /** How to read a project. This is the part of a Kit's world.json the scan needs. */
87
+ export interface ScanOptions {
88
+ /** File names that mark a folder as an application, such as "go.mod" or "*.xydsf". */
89
+ markers?: string[];
90
+ /** Use only `markers`, not the built-in ones as well. */
91
+ replaceDefaults?: boolean;
92
+ /** Folders that get a building even with no marker. */
93
+ include?: string[];
94
+ /** Folders that never get a building: a name, or a path from the top. */
95
+ ignore?: string[];
96
+ }
97
+ export interface ProjectScan {
98
+ areas: ProjectArea[];
99
+ rootFiles: number;
100
+ /** `from` depends on `to`. */
101
+ links?: {
102
+ from: string;
103
+ to: string;
104
+ }[];
105
+ /** Folders that didn't make the map. */
106
+ omitted?: number;
107
+ }
108
+ export declare const slug: (value: string) => string;
109
+ export declare const titled: (value: string) => string;
110
+ export declare function hashText(text: string): number;
111
+ /** A small seeded generator, so the same project always grows the same way. */
112
+ export declare function rng(seed: string): () => number;
113
+ /** Folder names, file counts and how the folders depend on each other. */
114
+ export declare function scanProject(root: string, options?: ScanOptions): ProjectScan;
115
+ /** The look comes from a folder's own name, so everything in apps/ doesn't look like a front end. */
116
+ export declare function themeFor(folder: string, plan: WorldPlan, random: () => number): Theme;
117
+ export declare const deskCount: (files: number) => number;
118
+ export declare function furnish(room: MapRoom, doors: MapDoor[], seed: string, plan: WorldPlan): MapItem[];
119
+ /**
120
+ * The map after the project's latest changes, or a new one. Returns what changed in words.
121
+ * Pure: the same map, scan and seed always give the same result.
122
+ */
123
+ export declare function evolveMap(previous: OfficeMap | undefined, scan: ProjectScan, seed: string, now?: string, newWorld?: WorldPlan): {
124
+ map: OfficeMap;
125
+ changes: string[];
126
+ };
127
+ /** The room a project file belongs to: the longest matching folder. */
128
+ export declare function roomForPath(rooms: {
129
+ id: string;
130
+ paths?: string[];
131
+ }[], relative: string): string | undefined;
132
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAE9F,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,E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