Skip to content

Commit 840b489

Browse files
committed
fix: saving dimension type in area
1 parent 7c28031 commit 840b489

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/lib/region/areas/area.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { stringifyError } from 'lib/util'
44
import { AbstractPoint } from 'lib/utils/point'
55
import { Vec } from 'lib/vector'
66

7-
export type AreaCreator = new (o: any) => Area
7+
export type AreaCreator = new (db: any, dimensionType?: DimensionType) => Area
88
export type AreaWithType<T = AreaCreator> = T & { type: string }
99

1010
export interface AreaAsJson extends JsonObject {
1111
t: string
1212
d: JsonObject
13+
dd?: DimensionType
1314
}
1415

1516
export abstract class Area<T extends JsonObject = JsonObject> {
@@ -19,15 +20,17 @@ export abstract class Area<T extends JsonObject = JsonObject> {
1920

2021
static asSaveableArea<T extends AreaCreator>(this: T) {
2122
const b = this as AreaWithType<T>
22-
b.type = new (this as unknown as AreaCreator)({}).type
23+
world.afterEvents.worldLoad.subscribe(() => {
24+
b.type = new (this as unknown as AreaCreator)({}).type
2325

24-
if ((this as unknown as typeof Area).loaded) {
25-
throw new Error(
26-
`Registering area type ${b.type} failed. Regions are already restored from json. Registering area should occur on the import-time.`,
27-
)
28-
}
26+
if ((this as unknown as typeof Area).loaded) {
27+
throw new Error(
28+
`Registering area type ${b.type} failed. Regions are already restored from json. Registering area should occur on the import-time.`,
29+
)
30+
}
2931

30-
;(this as unknown as typeof Area).areas.push(b as unknown as AreaWithType)
32+
;(this as unknown as typeof Area).areas.push(b as unknown as AreaWithType)
33+
})
3134
return b
3235
}
3336

@@ -40,7 +43,7 @@ export abstract class Area<T extends JsonObject = JsonObject> {
4043
return
4144
}
4245

43-
return new area(a.d)
46+
return new area(a.d, a.dd)
4447
}
4548

4649
constructor(
@@ -92,7 +95,7 @@ export abstract class Area<T extends JsonObject = JsonObject> {
9295
* restore the same state
9396
*/
9497
toJSON(): AreaAsJson {
95-
return { t: this.type, d: this.database }
98+
return { t: this.type, d: this.database, dd: this.dimensionType === 'overworld' ? undefined : this.dimensionType }
9699
}
97100

98101
protected get dimension() {

0 commit comments

Comments
 (0)