Skip to content

Commit

Permalink
Move MapPickerConfigNode's to their implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 16, 2024
1 parent e37c856 commit c6f7795
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
6 changes: 1 addition & 5 deletions src/dungeon/builder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Id, BuildQueue } from '../build-queue/build-queue'
import { BuildQueue } from '../build-queue/build-queue'
import { drawMapArrangeQueue } from '../map-arrange/drawer'
import { MapArrangeData } from '../map-arrange/map-arrange'
import { MapPicker, mapPickerConfigurable } from '../map-arrange/map-picker/configurable'
import { setRandomSeed } from '../util/util'

export type RoomBlueprint = {}

export type BlueprintRoot = Record<Id, RoomBlueprint>

export class DungeonBuilder {
build(seed: string) {
const queue = new BuildQueue<MapArrangeData>(true)
Expand Down
54 changes: 1 addition & 53 deletions src/map-arrange/map-picker/configurable.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
import { Id, BuildQueueAccesor, NextQueueEntryGenerator } from '../../build-queue/build-queue'
import { MapArrangeData, TprArrange, MapArrange } from '../../map-arrange/map-arrange'
import { Dir } from '../../util/geometry'
import { simpleMapArrange, simpleMapTunnelArrange, simpleMapBranchTunnelArrange } from '../maps/simple'
import { assert } from '../../util/util'

declare global {
export namespace MapPickerNodeConfigs {
export interface All {}

export interface All {
Simple: Simple
}
export interface Simple {
count: number
size: Vec2
randomizeDirTryOrder?: boolean
followedBy?: MapPicker.ConfigNode
}

export interface All {
SimpleTunnel: SimpleTunnel
}
export interface SimpleTunnel {
count: number
roomSize: Vec2
tunnelSize: Vec2
randomizeDirTryOrder?: boolean
followedBy?: MapPicker.ConfigNode
}

export interface All {
SimpleBranch: SimpleBranch
}
export interface SimpleBranch {
roomSize: Vec2
tunnelSize: Vec2
branches:
| [MapPicker.ConfigNode]
| [MapPicker.ConfigNode, MapPicker.ConfigNode]
| [MapPicker.ConfigNode, MapPicker.ConfigNode, MapPicker.ConfigNode]
randomizeDirTryOrder?: boolean
}
}
}

Expand Down Expand Up @@ -88,32 +53,15 @@ export namespace MapPicker {
}

const nodeConfigs: MapPicker.NodeBuilderRecord = {} as any
export function registerRoomChooserNodeConfig<T extends MapPicker.ConfigTypes>(
export function registerMapPickerNodeConfig<T extends MapPicker.ConfigTypes>(
type: T,
builder: MapPicker.NodeBuilderRecord[T]
) {
assert(!nodeConfigs[type])
nodeConfigs[type] = builder
}

let registered = false
function registerStuff() {
if (registered) return
registered = true
registerRoomChooserNodeConfig('Simple', (data, buildtimeData) => {
return simpleMapArrange({ ...data, ...buildtimeData })
})
registerRoomChooserNodeConfig('SimpleTunnel', (data, buildtimeData) => {
return simpleMapTunnelArrange({ ...data, ...buildtimeData })
})
registerRoomChooserNodeConfig('SimpleBranch', (data, buildtimeData) => {
return simpleMapBranchTunnelArrange({ ...data, ...buildtimeData, branchCount: data.branches.length })
})
}

export function mapPickerConfigurable(_config: MapPicker.Config): MapPicker {
registerStuff()

const config = _config as MapPicker.ConfigBuildtime
const idToNodeMap: Record<number, MapPicker.ConfigNodeBuildtime> = {}
let lastNodeId: number
Expand Down
55 changes: 54 additions & 1 deletion src/map-arrange/maps/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ import { NextQueueEntryGenerator, QueueEntry } from '../../build-queue/build-que
import { Dir, DirU, Rect } from '../../util/geometry'
import { shuffleArray } from '../../util/util'
import { TprArrange, MapArrangeData, MapArrange, RoomArrange, TprArrange3d, doesMapArrangeFit } from '../map-arrange'
import { MapPicker } from '../map-picker/configurable'
import { MapPicker, registerMapPickerNodeConfig } from '../map-picker/configurable'
import { Vec2 } from '../../util/vec2'

declare global {
export namespace MapPickerNodeConfigs {
export interface All {
Simple: Simple
}
export interface Simple {
count: number
size: Vec2
randomizeDirTryOrder?: boolean
followedBy?: MapPicker.ConfigNode
}
}
}

registerMapPickerNodeConfig('Simple', (data, buildtimeData) => {
return simpleMapArrange({ ...data, ...buildtimeData })
})
export function simpleMapArrange({
mapPicker,
exitTpr,
Expand Down Expand Up @@ -96,6 +113,23 @@ export function simpleMapArrange({
}
}

declare global {
export namespace MapPickerNodeConfigs {
export interface All {
SimpleTunnel: SimpleTunnel
}
export interface SimpleTunnel {
count: number
roomSize: Vec2
tunnelSize: Vec2
randomizeDirTryOrder?: boolean
followedBy?: MapPicker.ConfigNode
}
}
}
registerMapPickerNodeConfig('SimpleTunnel', (data, buildtimeData) => {
return simpleMapTunnelArrange({ ...data, ...buildtimeData })
})
export function simpleMapTunnelArrange({
mapPicker,
exitTpr,
Expand Down Expand Up @@ -215,6 +249,25 @@ export function simpleMapTunnelArrange({
}
}

declare global {
export namespace MapPickerNodeConfigs {
export interface All {
SimpleBranch: SimpleBranch
}
export interface SimpleBranch {
roomSize: Vec2
tunnelSize: Vec2
branches:
| [MapPicker.ConfigNode]
| [MapPicker.ConfigNode, MapPicker.ConfigNode]
| [MapPicker.ConfigNode, MapPicker.ConfigNode, MapPicker.ConfigNode]
randomizeDirTryOrder?: boolean
}
}
}
registerMapPickerNodeConfig('SimpleBranch', (data, buildtimeData) => {
return simpleMapBranchTunnelArrange({ ...data, ...buildtimeData, branchCount: data.branches.length })
})
export function simpleMapBranchTunnelArrange({
mapPicker,
exitTpr,
Expand Down
2 changes: 2 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import './util/modify-prototypes'
import './map-arrange/map-picker/configurable'
import './map-arrange/map-picker/simple'

0 comments on commit c6f7795

Please sign in to comment.