Skip to content

Commit

Permalink
Reformat the code again
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 11, 2024
1 parent 84cffaf commit 9754db5
Show file tree
Hide file tree
Showing 22 changed files with 664 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 170,
"printWidth": 120,
"quoteProps": "as-needed",
"bracketSpacing": true,
"arrowParens": "avoid"
Expand Down
32 changes: 27 additions & 5 deletions src/area/area-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,21 @@ export class AreaBuilder {
this.builtArea = builtArea
}

private addMap(maps: sc.AreaLoadable.MapRoomList[], mapType: 'DUNGEON' | 'NO_DUNGEON', mapIndex: number, builder: MapBuilder, rects: AreaRect[], rooms: Room[]) {
private addMap(
maps: sc.AreaLoadable.MapRoomList[],
mapType: 'DUNGEON' | 'NO_DUNGEON',
mapIndex: number,
builder: MapBuilder,
rects: AreaRect[],
rooms: Room[]
) {
const path = builder.path!
const displayName = builder.displayName!
assertBool(rects.length == rooms.length)

const obj = rects.map((r, i) => [r, rooms[i]] as [AreaRect, Room]).sort((a, b) => a[1].placeOrder - b[1].placeOrder)
const obj = rects
.map((r, i) => [r, rooms[i]] as [AreaRect, Room])
.sort((a, b) => a[1].placeOrder - b[1].placeOrder)

rects = obj.map(e => e[0])
rooms = obj.map(e => e[1])
Expand Down Expand Up @@ -207,12 +216,20 @@ export class AreaBuilder {
})
}

private async handleBuilders(maps: sc.AreaLoadable.MapRoomList[], mapType: 'DUNGEON' | 'NO_DUNGEON', mapIndex: { v: number }, entries: FlattenedArmBuilders[]) {
private async handleBuilders(
maps: sc.AreaLoadable.MapRoomList[],
mapType: 'DUNGEON' | 'NO_DUNGEON',
mapIndex: { v: number },
entries: FlattenedArmBuilders[]
) {
for (const obj of entries) {
const builder = obj.entry.builder
builder.pathParent = this.areaInfo.name
assertBool(builder.path === undefined, 'MapBuilder copy fail')
builder.path = builder.pathParent + '/' + mapIndex.v.toLocaleString('en-US', { minimumIntegerDigits: 3, useGrouping: false })
builder.path =
builder.pathParent +
'/' +
mapIndex.v.toLocaleString('en-US', { minimumIntegerDigits: 3, useGrouping: false })

await builder.decideDisplayName(mapIndex.v)
assert(builder.displayName)
Expand Down Expand Up @@ -301,7 +318,12 @@ export class AreaBuilder {
}
}

async generateFloor(level: number, name: string, size: AreaPoint, rootArm: ArmRuntime): Promise<sc.AreaLoadable.FloorCustom> {
async generateFloor(
level: number,
name: string,
size: AreaPoint,
rootArm: ArmRuntime
): Promise<sc.AreaLoadable.FloorCustom> {
/* level filtering not implemented */
const entries: FlattenedArmBuilders[] = []
forEveryArmEntry(rootArm, (entry: ArmRuntimeEntry, parentArm: ArmRuntime, index: number) => {
Expand Down
7 changes: 6 additions & 1 deletion src/area/area-drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ export class CCCanvas {
const ctx = this.canvas.getContext('2d')!
ctx.imageSmoothingEnabled = false
ctx.lineWidth = this.scale
const r: Rect = new Rect(rect.x * this.scale, rect.y * this.scale, rect.width * this.scale, rect.height * this.scale)
const r: Rect = new Rect(
rect.x * this.scale,
rect.y * this.scale,
rect.width * this.scale,
rect.height * this.scale
)
ctx.strokeRect(r.x, r.y, r.width, r.height)

if (bgColor) {
Expand Down
36 changes: 29 additions & 7 deletions src/area/custom-MapAreaContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,38 @@ export function overrideMapAreaContainer() {
if (gamepad) {
pos = Vec2.create(this.area.hook.pos)
} else {
pos = Vec2.createC(mx - sc.menu.mapCamera.x - this.area.hook.pos.x + 1, my - sc.menu.mapCamera.y - this.area.hook.pos.y + 1)
pos = Vec2.createC(
mx - sc.menu.mapCamera.x - this.area.hook.pos.x + 1,
my - sc.menu.mapCamera.y - this.area.hook.pos.y + 1
)
}
Vec2.subC(pos, addPxSpace)

if (this.area.hook.children.length == 0) {
return
}

const mapGuis: GuiHookMapRoomList[] = this.area.hook.children[sc.map.getCurrentFloorIndex()].children as GuiHookMapRoomList[]
const mapGuis: GuiHookMapRoomList[] = this.area.hook.children[sc.map.getCurrentFloorIndex()]
.children as GuiHookMapRoomList[]
for (const hook of mapGuis) {
if (!hook.gui.room || !hook.gui.unlocked) {
continue
}

if (gamepad) {
this.mapNameGui.setPos(sc.menu.mapCursor.x + 5, sc.menu.mapCursor.y - this.mapNameGui.hook.size.y - 4)
this.mapNameGui.setPos(
sc.menu.mapCursor.x + 5,
sc.menu.mapCursor.y - this.mapNameGui.hook.size.y - 4
)
} else {
this.mapNameGui.setPos(mx - sc.menu.mapCamera.x, my - sc.menu.mapCamera.y - this.mapNameGui.hook.size.y - 1)
this.mapNameGui.setPos(
mx - sc.menu.mapCamera.x,
my - sc.menu.mapCamera.y - this.mapNameGui.hook.size.y - 1
)
}
const map: sc.AreaLoadable.MapRoomList = hook.gui.floor.maps[hook.gui.room.index!] as sc.AreaLoadable.MapRoomList
const map: sc.AreaLoadable.MapRoomList = hook.gui.floor.maps[
hook.gui.room.index!
] as sc.AreaLoadable.MapRoomList
for (const r of map.rects) {
if (!r.areaRect) {
r.areaRect = {
Expand All @@ -59,7 +71,12 @@ export function overrideMapAreaContainer() {
}
}
const rect = r.areaRect
if (pos.x >= rect.x && pos.x <= rect.x + rect.width && pos.y >= rect.y && pos.y <= rect.y + rect.height) {
if (
pos.x >= rect.x &&
pos.x <= rect.x + rect.width &&
pos.y >= rect.y &&
pos.y <= rect.y + rect.height
) {
if (this.hoverRoom != hook.gui.room) {
this.hoverRoom = hook.gui.room
this.mapNameGui.setText(hook.gui.room.text, wait)
Expand Down Expand Up @@ -290,7 +307,12 @@ export function overrideMapAreaContainer() {
map.rects.forEach(o => {
const rect = o.drawEmptyRect!
const shadowOffset = o.wallSides[Dir.NORTH] ? 1 : 0
c.empty.draw(rect.x + 1, rect.y + shadowOffset + 1, rect.width - 3, rect.height - shadowOffset - 3)
c.empty.draw(
rect.x + 1,
rect.y + shadowOffset + 1,
rect.width - 3,
rect.height - shadowOffset - 3
)
})

/*
Expand Down
6 changes: 5 additions & 1 deletion src/dungeon/configs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export class DungeonConfigMainFactory implements DungeonConfigFactory {

bPool.push(_sb)
const _db1: MapBuilderArrayGenerate = { arr: [], randomize: true, index: index++ }
DirUtil.forEachUniqueDir4((d1, d2, d3, d4) => _db1.arr.push(Object.assign(new DungeonIntersectionMapBuilder(areaInfo, 2, d1, d2, d3, d4), { exclusive: true })))
DirUtil.forEachUniqueDir4((d1, d2, d3, d4) =>
_db1.arr.push(
Object.assign(new DungeonIntersectionMapBuilder(areaInfo, 2, d1, d2, d3, d4), { exclusive: true })
)
)
bPool.push(_db1)

const dngGenConfig: DungeonGenerateConfig = {
Expand Down
54 changes: 45 additions & 9 deletions src/dungeon/configs/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class DungeonConfigSimpleFactory implements DungeonConfigFactory {
: () => {
throw new Error()
})((...arr: Dir[]) => {
const b = Object.assign(new SimpleMultipleExitMapBuilder(this.areaInfo, arr[0], arr[1], arr[2], arr[3]), { exclusive })
const b = Object.assign(new SimpleMultipleExitMapBuilder(this.areaInfo, arr[0], arr[1], arr[2], arr[3]), {
exclusive,
})
for (let i = 0; i < multi; i++) {
_db.arr.push(b)
}
Expand Down Expand Up @@ -107,9 +109,21 @@ export class DungeonConfigSimpleFactory implements DungeonConfigFactory {
/* fixed :) */
const _sb1: MapBuilderArrayGenerate = {
arr: [
Object.assign(Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.SOUTH, Dir.NORTH), { exclusive: true })),
Object.assign(Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.SOUTH, Dir.WEST), { exclusive: true })),
Object.assign(Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.EAST, Dir.SOUTH), { exclusive: true })),
Object.assign(
Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.SOUTH, Dir.NORTH), {
exclusive: true,
})
),
Object.assign(
Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.SOUTH, Dir.WEST), {
exclusive: true,
})
),
Object.assign(
Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.EAST, Dir.SOUTH), {
exclusive: true,
})
),
],
randomize: false,
index: this.bPool.length,
Expand All @@ -118,30 +132,52 @@ export class DungeonConfigSimpleFactory implements DungeonConfigFactory {

const _sb2: MapBuilderArrayGenerate = {
arr: [
Object.assign(Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.WEST, Dir.NORTH), { exclusive: true })),
Object.assign(Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.SOUTH, Dir.NORTH), { exclusive: true })),
Object.assign(
Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.WEST, Dir.NORTH), {
exclusive: true,
})
),
Object.assign(
Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.SOUTH, Dir.NORTH), {
exclusive: true,
})
),
],
randomize: false,
index: this.bPool.length,
}
this.bPool.push(_sb2)

const _sb3: MapBuilderArrayGenerate = {
arr: [Object.assign(Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.EAST, Dir.NORTH), { exclusive: true }))],
arr: [
Object.assign(
Object.assign(new SimpleSingleTunnelEndMapBuilder(this.areaInfo, Dir.EAST, Dir.NORTH), {
exclusive: true,
})
),
],
randomize: false,
index: this.bPool.length,
}
this.bPool.push(_sb3)

const _db1: MapBuilderArrayGenerate = {
arr: [Object.assign(new SimpleMultipleExitMapBuilder(this.areaInfo, Dir.SOUTH, Dir.NORTH, Dir.EAST), { exclusive: true })],
arr: [
Object.assign(new SimpleMultipleExitMapBuilder(this.areaInfo, Dir.SOUTH, Dir.NORTH, Dir.EAST), {
exclusive: true,
}),
],
randomize: false,
index: this.bPool.length,
}
this.bPool.push(_db1)

const _db2: MapBuilderArrayGenerate = {
arr: [Object.assign(new SimpleMultipleExitMapBuilder(this.areaInfo, Dir.SOUTH, Dir.WEST), { exclusive: true })],
arr: [
Object.assign(new SimpleMultipleExitMapBuilder(this.areaInfo, Dir.SOUTH, Dir.WEST), {
exclusive: true,
}),
],
randomize: false,
index: this.bPool.length,
}
Expand Down
10 changes: 8 additions & 2 deletions src/dungeon/dungeon-arm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export function copyArmRuntime(arm: ArmRuntime): ArmRuntime {
return newArm
}

export function forEveryArmEntry(arm: ArmRuntime, func: (entry: ArmRuntimeEntry, arm: ArmRuntime, index: number) => void) {
export function forEveryArmEntry(
arm: ArmRuntime,
func: (entry: ArmRuntimeEntry, arm: ArmRuntime, index: number) => void
) {
const entries: ArmRuntimeEntry[] = []
if (arm.stack) {
arm.stack.forEach((e, i) => func(e, arm, i))
Expand All @@ -78,7 +81,10 @@ export function forEveryArmEntry(arm: ArmRuntime, func: (entry: ArmRuntimeEntry,
return entries
}

export function flatOutArmTopDown(arm: ArmRuntime, allowCache: boolean = true): { entry: ArmRuntimeEntry; arm: ArmRuntime }[] {
export function flatOutArmTopDown(
arm: ArmRuntime,
allowCache: boolean = true
): { entry: ArmRuntimeEntry; arm: ArmRuntime }[] {
if (allowCache && arm.flatRuntimeCache) {
return arm.flatRuntimeCache
}
Expand Down
27 changes: 24 additions & 3 deletions src/dungeon/dungeon-arrange.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { AreaBuilder, AreaInfo } from '@root/area/area-builder'
import { assert, assertBool } from 'cc-map-util/util'
import { AreaPoint, Dir, PosDir } from 'cc-map-util/pos'
import { Arm, ArmEnd, ArmRuntime, ArmRuntimeEntry, ExclusiveMapBuilder, MapBuilderPool, copyArmRuntime, copyBuilderPool } from '@root/dungeon/dungeon-arm'
import {
Arm,
ArmEnd,
ArmRuntime,
ArmRuntimeEntry,
ExclusiveMapBuilder,
MapBuilderPool,
copyArmRuntime,
copyBuilderPool,
} from '@root/dungeon/dungeon-arm'
import { randomSeedInt, setRandomSeed, shuffleArray } from '@root/util/misc'

export interface DungeonGenerateConfig<T extends Arm = Arm> {
Expand Down Expand Up @@ -67,7 +76,11 @@ export class DungeonArranger {
return retArm
}

private recursiveTryPlaceArmEntry(arm: ArmRuntime, lastEntry: ArmRuntimeEntry, armIndex?: number): ArmRuntime | undefined {
private recursiveTryPlaceArmEntry(
arm: ArmRuntime,
lastEntry: ArmRuntimeEntry,
armIndex?: number
): ArmRuntime | undefined {
assertBool(typeof arm.length === 'number')
/* if arm is completed */
if (arm.stack.length == arm.length + 1) {
Expand Down Expand Up @@ -121,7 +134,15 @@ export class DungeonArranger {
arm.stack = arm.stack.slice(0, len)
assertBool(arm.stack.length == len, 'why')
}
const retArm = this.recursiveTryArmBuilder(possibleBuilder, arm, lastEntry, poolIndex, skipPoolCopy, isEnd, armIndex)
const retArm = this.recursiveTryArmBuilder(
possibleBuilder,
arm,
lastEntry,
poolIndex,
skipPoolCopy,
isEnd,
armIndex
)
if (retArm) {
return retArm
}
Expand Down
27 changes: 22 additions & 5 deletions src/game-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ export function prestartGameStart() {
this.parent()
ig.lang.labels.sc.gui['title-screen'].generateDungeon = 'Generate dungeon'
const self1 = this
this._createButton('generateDungeon', this.buttons.last().hook.pos.y + 39, 100 - this.buttons.length, () => {
startDnggenGame(self1)
})
this._createButton(
'generateDungeon',
this.buttons.last().hook.pos.y + 39,
100 - this.buttons.length,
() => {
startDnggenGame(self1)
}
)
},
})
}
Expand Down Expand Up @@ -70,14 +75,26 @@ async function registerStyles() {
ig.MapStyle.registerStyle('default', 'puzzle2', { sheet: 'media/entity/style/default-puzzle-2-fix.png' })
ig.MapStyle.registerStyle('default', 'magnet', { sheet: 'media/map/shockwave-dng.png', x: 160, y: 272 })
ig.MapStyle.registerStyle('default', 'bouncer', { sheet: 'media/map/shockwave-dng-props.png', x: 0, y: 0 })
ig.MapStyle.registerStyle('default', 'waterblock', { sheet: 'media/map/shockwave-dng.png', x: 384, y: 304, puddleX: 352, puddleY: 448 })
ig.MapStyle.registerStyle('default', 'waterblock', {
sheet: 'media/map/shockwave-dng.png',
x: 384,
y: 304,
puddleX: 352,
puddleY: 448,
})
ig.MapStyle.registerStyle('default', 'waveblock', { sheet: 'media/map/shockwave-dng.png', x: 96, y: 480 })
ig.MapStyle.registerStyle('default', 'tesla', { sheet: 'media/map/shockwave-dng.png', x: 240, y: 352 })
ig.MapStyle.registerStyle('default', 'waveSwitch', { sheet: 'media/map/shockwave-dng.png', x: 16, y: 696 })
ig.MapStyle.registerStyle('default', 'anticompressor', { sheet: 'media/map/shockwave-dng.png', x: 240, y: 400 })
ig.MapStyle.registerStyle('default', 'dynPlatformSmall', { sheet: 'media/map/shockwave-dng.png', x: 48, y: 640 })
ig.MapStyle.registerStyle('default', 'dynPlatformMedium', { sheet: 'media/map/shockwave-dng.png', x: 0, y: 640 })
ig.MapStyle.registerStyle('default', 'lorry', { sheet: 'media/map/shockwave-dng.png', railX: 176, railY: 304, lorryX: 128, lorryY: 304 })
ig.MapStyle.registerStyle('default', 'lorry', {
sheet: 'media/map/shockwave-dng.png',
railX: 176,
railY: 304,
lorryX: 128,
lorryY: 304,
})
ig.MapStyle.registerStyle('default', 'rotateBlocker', { sheet: 'media/map/shockwave-dng.png', x: 256, y: 720 })
ig.MapStyle.registerStyle('default', 'destruct', { sheet: 'media/entity/style/shockwave-dng-destruct.png' })
ig.MapStyle.registerStyle('default', 'effect', { sheet: 'area.cold-dng' })
Expand Down
Loading

0 comments on commit 9754db5

Please sign in to comment.