Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Aug 25, 2024
1 parent 8b605f4 commit c118dc4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/lib/region/database.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Region } from 'lib'
import { Region, RegionIsSaveable } from 'lib'
import { Vector } from 'lib/vector'
import { beforeAll, describe, expect, it, vi } from 'vitest'
import { ChunkCubeArea } from './areas/chunk-cube'
Expand All @@ -17,10 +17,6 @@ class TestK1Region extends Region {
get regionKey() {
return this.key
}

get isSabeable() {
return this.saveable
}
}
registerSaveableRegion('k1', TestK1Region)

Expand Down Expand Up @@ -51,7 +47,7 @@ describe('region initialization', () => {
expect(json.a.t).toBe(SphereArea.type)
expect(json.k).toBe(TestK1Region.kind)

expect(region.isSabeable).toBe(true)
expect(RegionIsSaveable in region).toBe(true)

expect(restoreRegionFromJSON(['test', json])).toBeInstanceOf(TestK1Region)
expect(restoreRegionFromJSON(['test', json])).toEqual(region)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/region/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ProxyDatabase } from 'lib/database/proxy'
import { t } from 'lib/text'
import { Area } from './areas/area'
import { SphereArea } from './areas/sphere'
import type { Region, RegionPermissions } from './kinds/region'
import { RegionIsSaveable, type Region, type RegionPermissions } from './kinds/region'

export type RLDB = JsonObject | undefined

Expand Down Expand Up @@ -53,7 +53,7 @@ export function registerSaveableRegion(kind: string, region: typeof Region) {
// @ts-expect-error Yes, we ARE breaking typescript
region.kind = kind
// @ts-expect-error Yes, we ARE breaking typescript
region.prototype.saveable = true
region.prototype[RegionIsSaveable] = true

kinds.push(region)
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib/region/kinds/region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,9 @@ export class Region {
}
}

/** Whenether region should be saved into the database or if its runtime-only, e.g. BossRegion */
protected readonly saveable: boolean = false

/** Updates this region in the database */
save() {
if (!this.saveable) return false
if (!(RegionIsSaveable in this)) return false

RegionDatabase[this.key] = this.toJSON()
}
Expand All @@ -234,3 +231,5 @@ export class Region {
Reflect.deleteProperty(RegionDatabase, this.key)
}
}

export const RegionIsSaveable = Symbol('region.saveable')

0 comments on commit c118dc4

Please sign in to comment.