Skip to content

Commit

Permalink
Fix all type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 11, 2024
1 parent 9754db5 commit b8f4911
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 180 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
"author": "krypek",
"license": "GPLv3",
"devDependencies": {
"@types/jquery": "^3.5.29",
"@types/node": "^20.4.4",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@types/jquery": "^3.5.30",
"@types/node": "^11.15.54",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"array-flat-polyfill": "^1.0.1",
"cc-blitzkrieg": "github:krypciak/cc-blitzkrieg",
"cc-map-util": "github:krypciak/cc-map-util",
"cc-vim": "github:krypciak/cc-vim",
"esbuild": "^0.18.15",
"ccmodmanager": "github:CCDirectLink/CCModManager",
"esbuild": "^0.18.20",
"nax-ccuilib": "github:conorlawton/nax-ccuilib",
"typescript": "^5.2.2",
"typescript": "^5.5.4",
"ultimate-crosscode-typedefs": "github:krypciak/ultimate-crosscode-typedefs"
}
}
262 changes: 129 additions & 133 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/dungeon/configs/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DungeonConfigSimpleFactory implements DungeonConfigFactory {
this.seed = seed
this.bPool = []

const dngGenConfig: DungeonGenerateConfig = this.armverycomplex()
const dngGenConfig: DungeonGenerateConfig = this.armsimple() // this.armverycomplex()
return dngGenConfig
}

Expand Down
4 changes: 2 additions & 2 deletions src/dungeon/dungeon-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class DungeonBuilder {
async build(
id: string,
seed: string,
// configFactory: DungeonConfigFactory = new DungeonConfigSimpleFactory()
configFactory: DungeonConfigFactory = new DungeonConfigMainFactory()
configFactory: DungeonConfigFactory = new DungeonConfigSimpleFactory()
// configFactory: DungeonConfigFactory = new DungeonConfigMainFactory()
) {
if (seed === '') {
Math.seedrandomSeed(Math.random().toString())
Expand Down
30 changes: 22 additions & 8 deletions src/dungeon/dungeon-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface DungeonSaveConfig {
areaDbEntries: Record<string, sc.MapModel.Area>
sels: Record<keyof typeof blitzkrieg.sels, string>
}
const fs: typeof import('fs') = (0, eval)("require('fs')")

export class DungeonPaths {
static baseName: string = 'dnggen'
Expand Down Expand Up @@ -82,13 +83,26 @@ export class DungeonPaths {
}

clearDir() {
blitzkrieg.FsUtil.mkdirsClear(this.baseDir)
const path = this.baseDir
clear(path)
function clear(path: string) {
fs.readdirSync(path).forEach((file: string) => {
const filePath = `${path}/${file}`

if (fs.lstatSync(filePath).isDirectory()) {
clear(filePath)
fs.rmdirSync(filePath)
} else {
fs.unlinkSync(filePath)
}
})
}
}

saveMap(builder: MapBuilder): Promise<void> {
assert(builder.rpv)
console.log('map: ', ig.copy(builder.rpv.map))
blitzkrieg.FsUtil.mkdirs(`${this.mapsDir}/${builder.pathParent}`)
fs.mkdirSync(`${this.mapsDir}/${builder.pathParent}`, { recursive: true })
const path = `${this.mapsDir}/${builder.path}.json`
const gamePath = `${this.mapsDirGame}/${builder.path}.json`

Expand All @@ -100,22 +114,22 @@ export class DungeonPaths {
assert(builder.builtArea, 'called saveToFile() before finalizing build')
assert(builder.dbEntry, 'area db entry not generated')

blitzkrieg.FsUtil.mkdirs(this.areaDir)
fs.mkdirSync(this.areaDir, { recursive: true })
const path = this.areaFile
this.config.paths[this.areaFileGame] = path
this.config.areaDbEntries[builder.areaInfo.name] = builder.dbEntry
blitzkrieg.FsUtil.writeFileSync(path, builder.builtArea)
fs.writeFileSync(path, JSON.stringify(builder.builtArea))
}

saveConfig() {
blitzkrieg.FsUtil.writeFileSync(this.configFile, this.config)
fs.writeFileSync(this.configFile, JSON.stringify(this.config))
}

loadConfig(): boolean {
if (!blitzkrieg.FsUtil.doesFileExist(this.configFile)) {
return false
}
this.config = JSON.parse(blitzkrieg.FsUtil.readFileSync(this.configFile))
this.config = JSON.parse(fs.readFileSync(this.configFile, 'utf8'))

return true
}
Expand All @@ -142,7 +156,7 @@ export class DungeonPaths {
registerSelections(load: boolean = false) {
for (const selEntry of Object.entries(this.config.sels)) {
const [poolName, path] = selEntry as [keyof typeof blitzkrieg.sels, string]
const pool: SelectionManager = blitzkrieg.sels[poolName] as SelectionManager
const pool = blitzkrieg.sels[poolName] as SelectionManager<any>
while (pool.jsonFiles.includes(path)) {
const indexToDel: number = pool.jsonFiles.indexOf(path)
Object.keys(pool.selMap).forEach(k => {
Expand All @@ -166,7 +180,7 @@ export class DungeonPaths {
if (index === undefined) {
throw new Error('pool name doesnt exist: ' + poolName)
}
const pool: SelectionManager = blitzkrieg.sels[poolName] as SelectionManager
const pool = blitzkrieg.sels[poolName] as SelectionManager<any>
pool.setMapEntry(sel.mapName, new blitzkrieg.SelectionMapEntry([sel], index))
}
}
1 change: 1 addition & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { poststartGameStart, prestartGameStart, startDnggenGame } from '@root/ga
import { DungeonPaths } from '@root/dungeon/dungeon-paths'
import { Mod1 } from 'cc-blitzkrieg/src/types'
import { godlikeStats } from './util/misc'
import './util/modify-prototypes'

declare global {
const dnggen: DngGen
Expand Down
8 changes: 5 additions & 3 deletions src/room/puzzle-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { MapBuilder, RoomPlaceVars } from '@root/room/map-builder'
import { ArmEnd, ArmRuntime } from '@root/dungeon/dungeon-arm'
import { ItemHandler } from './item-handler'
import { setToClosestSelSide } from '@root/util/misc'
import type { PuzzleSelection, PuzzleRoomType, PuzzleCompletionType } from 'cc-blitzkrieg/src/puzzle-selection'
import { PuzzleSelection, PuzzleRoomType, PuzzleCompletionType } from 'cc-blitzkrieg/src/puzzle-selection'
import { EntityRect, MapRect, Rect, generateUniqueId } from 'cc-map-util/src/rect'

interface PuzzleData {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class PuzzleRoom extends Room {
/* entry is from blitzkrieg puzzle list */
if (entry.fileIndex == 0 && entry.sels.length > 0) {
const filtered: Readonly<PuzzleSelection>[] = entry.sels
.filter(sel => sel.data.type != 'dis')
.filter(sel => sel.data.type != PuzzleRoomType.Dis)
.map(e => Object.freeze(e as PuzzleSelection))
puzzleMap.set(mapName, filtered)
for (const sel of filtered) {
Expand Down Expand Up @@ -121,7 +121,9 @@ export class PuzzleRoom extends Room {
let solveConditionUnique: string | undefined
switch (puzzle.completion) {
case blitzkrieg.PuzzleCompletionType.Normal:
solveCondition = blitzkrieg.PuzzleSelectionManager.getPuzzleSolveCondition(puzzle.sel)
const res = blitzkrieg.PuzzleSelectionManager.getPuzzleSolveCondition(puzzle.sel)
if (!res) throw new Error('no puzzle solution found!')
solveCondition = res[0]
break
case blitzkrieg.PuzzleCompletionType.GetTo:
if (puzzle.roomType == blitzkrieg.PuzzleRoomType.WholeRoom) {
Expand Down
4 changes: 1 addition & 3 deletions src/room/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ export class Room extends MapRect {
arr.push(this)
this.ios.forEach(io => {
// @ts-expect-error cant import RoomIOTunnel because of a circular dependency so im doing this
if (io.tunnel) {
arr.push(io.tunnel)
}
if (io.tunnel) arr.push(io.tunnel)
})
}

Expand Down
6 changes: 3 additions & 3 deletions src/util/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export class MapBallChanger implements MapEntity {
mapId: mapId++,
changerType: {
type: "CHANGE_DIR",
options: { dir: DirUtil.convertToStringFace8(dir) },
settings: { dir: DirUtil.convertToStringFace8(dir) },
},
})
}
Expand All @@ -489,8 +489,8 @@ export class MapBallChanger implements MapEntity {
name,
mapId: mapId++,
changerType: {
type: "CHANGE_SPEED"
options: { factor },
type: "CHANGE_SPEED",
settings: { factor },
},
})
}
Expand Down
35 changes: 35 additions & 0 deletions src/util/modify-prototypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* in preload */
export {}
declare global {
interface Object {
fromEntries<T, K extends string | number | symbol>(entries: [K, T][]): Record<K, T>
}
interface Array<T> {
flat(): T extends Array<any> ? T : T[]
flatMap<U>(callback: (value: T, index: number, array: T[]) => U | U[], thisArg?: this | undefined): U[]
}
}

if (!Object.fromEntries) {
Object.fromEntries = function <T, K extends string | number | symbol>(entries: [K, T][]): Record<K, T> {
return entries.reduce(
(acc: Record<K, T>, e: [K, T]) => {
acc[e[0]] = e[1]
return acc
},
{} as Record<K, T>
)
}
}

if (!Array.prototype.flat) {
Array.prototype.flat = function <T>(this: T[][]): T[] {
return this.reduce((acc, val) => acc.concat(val), [])
}
}

if (!Array.prototype.flatMap) {
Array.prototype.flatMap = function (callback, ...args) {
return this.map(callback, ...args).flat()
}
}
41 changes: 20 additions & 21 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
"node_modules/cc-vim/src/global.d.ts",
],
"compilerOptions": {
"target": "ES2018", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */

"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "./src/", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": "./src/", /* Specify the base directory to resolve non-relative module names. */
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
"@root/*": ["*"],
"cc-map-util/*": ["../node_modules/cc-map-util/src/*"],
},

"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */

"noEmit": true, /* Disable emitting files from a compilation. */

"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */

"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"target": "ES2018", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "./src/", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": "./src/", /* Specify the base directory to resolve non-relative module names. */
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
"@root/*": [
"*"
],
"cc-map-util/*": [
"../node_modules/cc-map-util/src/*"
],
},
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
"noEmit": true, /* Disable emitting files from a compilation. */
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}

0 comments on commit b8f4911

Please sign in to comment.