@blkc-code/mapgen 0.0.0-stage → 0.3.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,106 @@
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 WorldPlan } from "./plan.js";
11
+ export * from "./plan.js";
12
+ export interface MapRoom {
13
+ id: string;
14
+ name: string;
15
+ x: number;
16
+ y: number;
17
+ w: number;
18
+ h: number;
19
+ floor: string;
20
+ paths: string[];
21
+ /** lobby, lounge and quests are always there. hall is a corridor. vacant is an empty room, free for the next folder. */
22
+ role?: RoomRole;
23
+ /** Edited by hand: the generator leaves it alone. */
24
+ locked?: boolean;
25
+ files?: number;
26
+ }
27
+ export interface MapItem {
28
+ type: string;
29
+ x: number;
30
+ y: number;
31
+ room?: string;
32
+ }
33
+ export interface MapDoor {
34
+ x: number;
35
+ y: number;
36
+ }
37
+ export interface OfficeMap {
38
+ version: 1;
39
+ /** Which world this map is for. The office if left out. */
40
+ world?: string;
41
+ /** halls: rooms in even rows along corridors. Left out on older maps, whose rooms were placed one against another. */
42
+ layout?: "halls";
43
+ /** How tall the rooms are in the first pair of rows. */
44
+ roomHeight?: number;
45
+ seed: string;
46
+ /** Follow the project as it changes. */
47
+ evolve: boolean;
48
+ cols: number;
49
+ rows: number;
50
+ rooms: MapRoom[];
51
+ doors: MapDoor[];
52
+ furniture: MapItem[];
53
+ log: {
54
+ at: string;
55
+ text: string;
56
+ }[];
57
+ /** Which rooms depend on which, and whether a door joins them. */
58
+ links?: MapLink[];
59
+ }
60
+ export interface MapLink {
61
+ from: string;
62
+ to: string;
63
+ door: boolean;
64
+ }
65
+ /** A map, for any world. */
66
+ export type WorldMap = OfficeMap;
67
+ export interface ProjectArea {
68
+ id: string;
69
+ name: string;
70
+ path: string;
71
+ files: number;
72
+ /** How many other areas depend on this one. */
73
+ dependents?: number;
74
+ }
75
+ export interface ProjectScan {
76
+ areas: ProjectArea[];
77
+ rootFiles: number;
78
+ /** `from` depends on `to`. */
79
+ links?: {
80
+ from: string;
81
+ to: string;
82
+ }[];
83
+ /** Folders that didn't make the map. */
84
+ omitted?: number;
85
+ }
86
+ export declare function hashText(text: string): number;
87
+ /** The plain folder names in a .gitignore. Patterns with wildcards aren't followed. */
88
+ export declare function gitignoredNames(root: string): Set<string>;
89
+ /** A folder with its own .git is another project, even if it sits inside this one. */
90
+ export declare const isOwnRepo: (dir: string) => boolean;
91
+ /** Folder names, file counts and how the folders depend on each other. */
92
+ export declare function scanProject(root: string): ProjectScan;
93
+ /**
94
+ * The map after the project's latest changes, or a new one. Returns what changed in words.
95
+ * Pure: the same map, scan and seed always give the same result.
96
+ */
97
+ export declare function evolveMap(previous: OfficeMap | undefined, scan: ProjectScan, seed: string, now?: string, newWorld?: WorldPlan): {
98
+ map: OfficeMap;
99
+ changes: string[];
100
+ };
101
+ /** The room a project file belongs to: the longest matching folder. */
102
+ export declare function roomForPath(rooms: {
103
+ id: string;
104
+ paths?: string[];
105
+ }[], relative: string): string |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