Skip to content

Commit

Permalink
Add map construction for SimpleBranch
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 19, 2024
1 parent 6c6fdc8 commit 1703ba6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 114 deletions.
93 changes: 46 additions & 47 deletions src/dungeon/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,58 @@ export class DungeonBuilder {
const randomizeDirTryOrder = true
const roomSizeReg = { x: 13 * 16, y: 13 * 16 }
const tunnelSizeReg = { x: 5 * 16, y: 3 * 16 }
// const roomSizeBranch = { x: 5, y: 5 }
// const tunnelSizeBranch = { x: 1, y: 1 }
//
// function tunnel(count: number, followedBy?: MapPicker.ConfigNode): MapPicker.ConfigNode {
// return {
// type: 'SimpleTunnel',
// roomSize: roomSizeReg,
// tunnelSize: tunnelSizeReg,
// count,
// randomizeDirTryOrder,
// followedBy,
// }
// }
// function branch(
// deep: number,
// branchTunnelCount: () => number,
// finalTunnelCount: () => number,
// branchCount: () => 1 | 2 | 3
// ): MapPicker.ConfigNode {
// if (deep == 0) {
// return tunnel(finalTunnelCount())
// }
// return {
// type: 'SimpleBranch',
// roomSize: roomSizeBranch,
// tunnelSize: tunnelSizeBranch,
// branches: [
// ...new Array(branchCount())
// .fill(null)
// .map(_ =>
// tunnel(
// branchTunnelCount(),
// branch(deep - 1, branchTunnelCount, finalTunnelCount, branchCount)
// )
// ),
// ] as any,
// }
// }
const roomSizeBranch = { x: 17 * 16, y: 17 * 16 }
const tunnelSizeBranch = { x: 5 * 16, y: 5 * 16 }

const mapPicker: MapPicker = mapPickerConfigurable({
root: {
function tunnel(count: number, followedBy?: MapPicker.ConfigNode): MapPicker.ConfigNode {
return {
type: 'SimpleTunnel',
roomSize: roomSizeReg,
tunnelSize: tunnelSizeReg,
count: 5,
count,
randomizeDirTryOrder,
followedBy,
}
}
function branch(
deep: number,
branchTunnelCount: () => number,
finalTunnelCount: () => number,
branchCount: () => 1 | 2 | 3
): MapPicker.ConfigNode {
if (deep == 0) {
return tunnel(finalTunnelCount())
}
return {
type: 'SimpleBranch',
roomSize: roomSizeBranch,
tunnelSize: tunnelSizeBranch,
branches: [
...new Array(branchCount())
.fill(null)
.map(_ =>
tunnel(
branchTunnelCount(),
branch(deep - 1, branchTunnelCount, finalTunnelCount, branchCount)
)
),
] as any,
}
}

const mapPicker: MapPicker = mapPickerConfigurable({
root: {
type: 'Simple',
size: roomSizeReg,
count: 1,
randomizeDirTryOrder,

// followedBy: branch(
// 2,
// () => 2,
// () => 2,
// () => 2
// ),
followedBy: branch(
3,
() => 1,
() => 1,
() => 2
),
},
})

Expand Down
6 changes: 5 additions & 1 deletion src/maps/simple-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
TprArrange3d,
} from '../map-arrange/map-arrange'
import { MapPicker, registerMapPickerNodeConfig } from '../map-arrange/map-picker/configurable'
import { registerMapConstructor } from '../map-construct/map-construct'
import { DirU, Rect, Dir } from '../util/geometry'
import { shuffleArray } from '../util/util'
import { simpleMapConstructor } from './simple'

declare global {
export namespace MapPickerNodeConfigs {
Expand Down Expand Up @@ -118,7 +120,7 @@ export function simpleMapBranchTunnelArrange({
dir: DirU.flip(dir),
})
const walls: Record<Dir, boolean> = [true, true, true, true]
walls[dir] = false
walls[DirU.flip(dir)] = false
tunnelExit = { ...rect, walls }
map.rects.push(tunnelExit)
}
Expand Down Expand Up @@ -165,3 +167,5 @@ export function simpleMapBranchTunnelArrange({
}
}
}

registerMapConstructor('SimpleBranch', simpleMapConstructor)
66 changes: 3 additions & 63 deletions src/maps/simple-tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ import {
TprArrange3d,
} from '../map-arrange/map-arrange'
import { MapPicker, registerMapPickerNodeConfig } from '../map-arrange/map-picker/configurable'
import {
baseMapConstruct,
convertRoomsArrangeToRoomsConstruct,
getTprName,
registerMapConstructor,
} from '../map-construct/map-construct'
import { placeRoom } from '../map-construct/room'
import { MapTheme } from '../map-construct/theme'
import { registerMapConstructor } from '../map-construct/map-construct'
import { Dir, DirU, Rect } from '../util/geometry'
import { shuffleArray } from '../util/util'
import { simpleMapConstructor } from './simple'

declare global {
export namespace MapPickerNodeConfigs {
Expand Down Expand Up @@ -160,58 +154,4 @@ export function simpleMapTunnelArrange({
}
}

registerMapConstructor('SimpleTunnel', (map, areaInfo, pathResolver, _mapsArranged, _mapsConstructed) => {
const theme = MapTheme.default
const { mic, rectsAbsolute } = baseMapConstruct(map, pathResolver(map.id), areaInfo.id, theme, [9, 2, 2, 2])

function pushTprEntity(tpr: TprArrange3d, isEntrance: boolean, index: number) {
const name = getTprName(isEntrance, index)
const dir = DirU.flip(tpr.dir as Dir)
if (tpr.destId == -1) {
const middle = Vec2.subC(Rect.middle(map.rects[0]), 16, 16)
return mic.entities.push({
type: 'Marker',
...middle,
level: 0,
settings: { name, dir: DirU.toString(dir) },
})
}

let x = tpr.x
let y = tpr.y

if (tpr.dir != Dir.SOUTH) y -= 16
if (tpr.dir != Dir.EAST) x -= 16

mic.entities.push({
type: 'Door',
x,
y,
level: 0,
settings: {
name,
map: pathResolver(tpr.destId),
marker: getTprName(!isEntrance, tpr.destIndex ?? 0),
dir: DirU.toString(dir),
},
})
}

map.entranceTprs.forEach((tpr, i) => pushTprEntity(tpr, true, i))
map.restTprs.forEach((tpr, i) => pushTprEntity(tpr, false, i))

const rects = convertRoomsArrangeToRoomsConstruct(map.rects)
for (const room of rects) {
placeRoom(room, mic, theme.config, true)
}

const constructed: sc.MapModel.Map = Object.assign(mic, { layers: undefined })

return {
...map,
rects,
constructed,
rectsAbsolute,
title: `map ${constructed.name}`,
}
})
registerMapConstructor('SimpleTunnel', simpleMapConstructor)
15 changes: 12 additions & 3 deletions src/maps/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
baseMapConstruct,
convertRoomsArrangeToRoomsConstruct,
getTprName,
MapConstructFunc,
registerMapConstructor,
} from '../map-construct/map-construct'
import { MapTheme } from '../map-construct/theme'
Expand Down Expand Up @@ -129,9 +130,15 @@ export function simpleMapArrange({
}
}

registerMapConstructor('Simple', (map, areaInfo, pathResolver, _mapsArranged, _mapsConstructed) => {
export const simpleMapConstructor: MapConstructFunc = (
map,
areaInfo,
pathResolver,
_mapsArranged,
_mapsConstructed
) => {
const theme = MapTheme.default
const { mic, rectsAbsolute } = baseMapConstruct(map, pathResolver(map.id), areaInfo.id, theme, [7, 1, 1, 1])
const { mic, rectsAbsolute } = baseMapConstruct(map, pathResolver(map.id), areaInfo.id, theme, [8, 1, 1, 1])

function pushTprEntity(tpr: TprArrange3d, isEntrance: boolean, index: number) {
const name = getTprName(isEntrance, index)
Expand Down Expand Up @@ -183,4 +190,6 @@ registerMapConstructor('Simple', (map, areaInfo, pathResolver, _mapsArranged, _m
rectsAbsolute,
title: `map ${constructed.name}`,
}
})
}

registerMapConstructor('Simple', simpleMapConstructor)

0 comments on commit 1703ba6

Please sign in to comment.