Skip to content

Commit

Permalink
Add DngPuzzleTunnelRoom
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 25, 2024
1 parent 4ffbbc9 commit 67d6765
Show file tree
Hide file tree
Showing 12 changed files with 667 additions and 284 deletions.
52 changes: 35 additions & 17 deletions src/dungeon/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BuildQueue } from '../build-queue/build-queue'
import { drawMapArrangeQueue } from '../map-arrange/drawer'
import { MapArrange, MapArrangeData } from '../map-arrange/map-arrange'
import { MapPicker, mapPickerConfigurable } from '../map-arrange/map-picker/configurable'
import { AreaInfo, constructMapsFromMapsArrange } from '../map-construct/map-construct'
import { AreaInfo, constructMapsFromMapsArrange, getTprName } from '../map-construct/map-construct'
import { initAllPuzzles } from '../maps/puzzle-data'
import { Dir } from '../util/geometry'
import { Item } from '../util/items'
Expand All @@ -23,8 +23,8 @@ export class DungeonBuilder {

function tunnel(count: number, followedBy?: MapPicker.ConfigNode): MapPicker.ConfigNode {
return {
type: 'SimpleTunnel',
roomSize: roomSizeReg,
type: 'DngPuzzleTunnel',
// roomSize: roomSizeReg,
tunnelSize: tunnelSizeReg,
count,
randomizeDirTryOrder,
Expand Down Expand Up @@ -58,24 +58,37 @@ export class DungeonBuilder {
}

const mapPicker: MapPicker = mapPickerConfigurable({
startDir: Dir.WEST,
startDir: Dir.SOUTH,
// root: {
// type: 'DngPuzzleTunnel',
// tunnelSize: tunnelSizeReg,
// count: 1,
// randomizeDirTryOrder,
// forcePuzzle: 'rhombus-dng/room-3-2@0',
// },
root: {
type: 'DngPuzzleTunnel',
tunnelSize: tunnelSizeReg,
// size: roomSizeReg,
count: 5,
randomizeDirTryOrder,
// forcePuzzleMap: 'rhombus-dng/room-1',

type: 'Simple',
size: roomSizeReg,
count: 1,
followedBy: {
type: 'Simple',
size: roomSizeReg,
count: 1,
type: 'DngPuzzleTunnelRoom',
roomSize: roomSizeReg,
entranceTunnelSize: tunnelSizeReg,
tunnelSize: tunnelSizeReg,
count: 11,
randomizeDirTryOrder,
// forcePuzzle: 'rhombus-dng/room-3-2@0',

followedBy: {
type: 'Simple',
size: roomSizeReg,
count: 1,
},
},
// followedBy: branch(
// 1,
// () => 1,
// () => 1,
// () => 2,
// () => 2,
// () => 2
// ),
},
Expand Down Expand Up @@ -114,7 +127,12 @@ export class DungeonBuilder {

ig.game.teleport(
mapsConstruct[0].constructed.name,
ig.TeleportPosition.createFromJson({ marker: 'entrance_0', level: 0, baseZPos: 0, size: { x: 0, y: 0 } })
ig.TeleportPosition.createFromJson({
marker: getTprName(true, 0),
level: 0,
baseZPos: 0,
size: { x: 0, y: 0 },
})
)
}
}
1 change: 1 addition & 0 deletions src/map-arrange/map-arrange.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BuildQueueAccesor, Id, NextQueueEntryGenerator } from '../build-queue/build-queue'
import { PuzzleData } from '../maps/puzzle-data'
import { Dir, Dir3d, Rect } from '../util/geometry'
import { random } from '../util/util'
import { Vec2 } from '../util/vec2'
import { MapPicker } from './map-picker/configurable'

Expand Down
91 changes: 72 additions & 19 deletions src/map-construct/layer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MapThemeConfig } from '../map-construct/theme'
import { Coll } from '../util/map'
import { Array2d } from '../util/util'
import { Array2d, assert } from '../util/util'

export interface MapConstructionLayers {
background: number[][][]
Expand Down Expand Up @@ -40,11 +40,6 @@ export function getEmptyLayers(
const layer: sc.MapModel.MapLayer[] = []
const levels: sc.MapModel.Map['levels'] = []

let background: number[][][] = [],
shadow: number[][] = [],
coll: number[][][] = [],
nav: number[][][] = []

for (let level = 0; level < levelCount; level++) {
levels.push({ height: level * 16 * 2 })

Expand All @@ -54,8 +49,6 @@ export function getEmptyLayers(
tilesetName: theme.tileset,
level,
})

background.push(backgroundLayer.data)
layer.push(backgroundLayer)

if (level == 0 && theme.addShadows) {
Expand All @@ -65,7 +58,6 @@ export function getEmptyLayers(
tilesetName: theme.shadowTileset,
level,
})
shadow = shadowLayer.data
layer.push(shadowLayer)
}
const collisionLayer = emptyLayer(size, Coll.Wall, {
Expand All @@ -74,7 +66,6 @@ export function getEmptyLayers(
tilesetName: 'media/map/collisiontiles-16x16.png',
level,
})
coll.push(collisionLayer.data)
layer.push(collisionLayer)

const navigationLayer = emptyLayer(size, 0, {
Expand All @@ -83,7 +74,6 @@ export function getEmptyLayers(
tilesetName: 'media/map/pathmap-tiles.png',
level,
})
nav.push(navigationLayer.data)
layer.push(navigationLayer)
}

Expand All @@ -93,18 +83,81 @@ export function getEmptyLayers(
tilesetName: 'media/map/lightmap-tiles.png',
level: 'last',
})
const light: number[][] = lightLayer.data
layer.push(lightLayer)

return {
layers: {
background,
shadow,
light,
coll,
nav,
},
levels,
layer,
layers: constructionLayersFromMapLayers(layer),
}
}

export function constructionLayersFromMapLayers(layers: sc.MapModel.MapLayer[]): MapConstructionLayers {
let background: number[][][] = []
let shadow!: number[][]
let coll: number[][][] = []
let nav: number[][][] = []
let light!: number[][]

/* this assuses the layers are in proper order and are generated by getEmptyLayers */
for (const layer of layers) {
if (layer.type == 'Background') {
if (layer.name == 'NEW_SHADOW') {
assert(!shadow)
shadow = layer.data
} else if (layer.name == 'NEW_BACKGROUND') {
background.push(layer.data)
}
} else if (layer.type == 'Collision') coll.push(layer.data)
else if (layer.type == 'Navigation') nav.push(layer.data)
else if (layer.type == 'Light') {
assert(!light)
light = layer.data
}
}

assert(shadow)
assert(light)

return {
background,
shadow,
light,
coll,
nav,
}
}

export function fixMapLayerOrdering(layers: sc.MapModel.MapLayer[]): sc.MapModel.MapLayer[] {
return layers
// layers.sort((a, b) => a.id - b.id)
// const byLevel = layers.reduce(
// (acc, layer) => {
// const lvl = (acc[layer.level] ??= [])
// lvl.push(layer)
// return acc
// },
// {} as Record<string, sc.MapModel.MapLayer[]>
// )
//
// function putLayerOnTop(layers: sc.MapModel.MapLayer[], name: string) {
// const bgLayerI = layers.findIndex(layer => layer.name == name)
// if (bgLayerI != -1) {
// const layer = layers[bgLayerI]
// layers.splice(bgLayerI, 1)
// layers.push(layer)
// }
// }
// for (const key in byLevel) {
// const layers = byLevel[key]
// putLayerOnTop(layers, 'NEW_BACKGROUND')
// putLayerOnTop(layers, 'NEW_SHADOW')
// }
//
// return Object.values(byLevel)
// .flat()
// .map((layer, i) => {
// layer.id = i
// return layer
// })
}
9 changes: 8 additions & 1 deletion src/map-construct/map-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Id } from '../build-queue/build-queue'
import { assert } from '../util/util'
import { Item } from '../util/items'
import { Dir, Rect } from '../util/geometry'
import { MapConstructionLayers } from './layer'
import { constructionLayersFromMapLayers, MapConstructionLayers } from './layer'
import { getEmptyLayers } from './layer'
import { MapTheme } from './theme'

Expand Down Expand Up @@ -102,6 +102,13 @@ export function baseMapConstruct(
return mic
}

export function mapInConstructionFromMap(map: sc.MapModel.Map) {
return {
...map,
layers: constructionLayersFromMapLayers(map.layer),
}
}

export function getTprName(isEntrance: boolean, index: number): string {
return `${isEntrance ? 'entrance' : 'rest'}_${index}`
}
Expand Down
18 changes: 11 additions & 7 deletions src/map-construct/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ export type MapThemeConfig = {
edgeShadowBottomRight: number[][]
edgeShadowBottomLeft: number[][]
}
) & ({
addLight?: false
} | {
addLight: true
lightTile: number
lightStep: number
})
) &
(
| {
addLight?: false
}
| {
addLight: true
lightTile: number
lightStep: number
}
)

export class MapTheme {
constructor(public config: MapThemeConfig) {}
Expand Down
Loading

0 comments on commit 67d6765

Please sign in to comment.