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 c52acc0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 66 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
68 changes: 8 additions & 60 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 @@ -87,33 +52,16 @@ export namespace MapPicker {
}
}

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

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 })
})
static register<T extends MapPicker.ConfigTypes>(type: T, builder: MapPicker.NodeBuilderRecord[T]) {
assert(!this.nodeConfigs[type])
this.nodeConfigs[type] = builder
}
}

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 Expand Up @@ -189,7 +137,7 @@ export function mapPickerConfigurable(_config: MapPicker.Config): MapPicker {
const finishedWhole = branchDone && nodeId == lastNodeId
if (finishedWhole) debugger

const generator = nodeConfigs[config.type]
const generator = MapPickerNodeConfigs.nodeConfigs[config.type]
return generator(config as any, {
exitTpr: lastTpr,
mapPicker,
Expand All @@ -207,7 +155,7 @@ export function mapPickerConfigurable(_config: MapPicker.Config): MapPicker {
const nextConfig = config.branches[nextBranch] as MapPicker.ConfigNodeBuildtime
return mapPicker(id, accesor, newId, undefined, nextConfig)
}
const generator = nodeConfigs[config.type]
const generator = MapPickerNodeConfigs.nodeConfigs[config.type]
return generator(config as any, { exitTpr: lastTpr, mapPicker, nodeId: nodeId })
}

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, MapPickerNodeConfigs } 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
}
}
}

MapPickerNodeConfigs.register('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
}
}
}
MapPickerNodeConfigs.register('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
}
}
}
MapPickerNodeConfigs.register('SimpleBranch', (data, buildtimeData) => {
return simpleMapBranchTunnelArrange({ ...data, ...buildtimeData, branchCount: data.branches.length })
})
export function simpleMapBranchTunnelArrange({
mapPicker,
exitTpr,
Expand Down

0 comments on commit c52acc0

Please sign in to comment.