Skip to content

Commit c315d51

Browse files
committed
refactor: remove PropType, ItemType
1 parent de7ea34 commit c315d51

5 files changed

Lines changed: 11 additions & 35 deletions

File tree

game/field.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ export class Field implements IField {
693693
spawn.id,
694694
spawn.i,
695695
spawn.j,
696-
spawn.type,
697696
spawn.def,
698697
),
699698
)

model/field-block.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { seed } from "../util/random.ts"
44
import { floorN, modulo } from "../util/math.ts"
55
import { loadImage } from "../util/load.ts"
66
import type { Dir, IBox } from "./types.ts"
7-
import type { ItemType, LoadOptions, PropType as PropType } from "./types.ts"
7+
import type { LoadOptions } from "./types.ts"
88
import {
99
ActorDefinition,
1010
Catalog,
@@ -33,7 +33,6 @@ export class ItemSpawn implements IBox {
3333
readonly id: string
3434
readonly i: number
3535
readonly j: number
36-
readonly type: ItemType
3736
readonly def: ItemDefinition
3837
readonly x: number
3938
readonly y: number
@@ -42,28 +41,26 @@ export class ItemSpawn implements IBox {
4241
constructor(
4342
i: number,
4443
j: number,
45-
type: ItemType,
4644
def: ItemDefinition,
4745
) {
48-
this.id = `${i}.${j}.${type}` // Unique ID for the spawn
46+
this.id = `${i}.${j}.${def.type}` // Unique ID for the spawn
4947
this.i = i
5048
this.j = j
51-
this.type = type
5249
this.def = def
5350
this.x = i * CELL_SIZE
5451
this.y = j * CELL_SIZE
5552
}
5653

5754
equals(other: ItemSpawn): boolean {
5855
return this.i === other.i && this.j === other.j &&
59-
this.type === other.type
56+
this.def.type === other.def.type
6057
}
6158

6259
toJSON(): BlockMapSource["items"][number] {
6360
return {
6461
i: this.i,
6562
j: this.j,
66-
type: this.type,
63+
type: this.def.type,
6764
}
6865
}
6966
}
@@ -73,7 +70,6 @@ export class PropSpawn implements IBox {
7370
readonly id: string
7471
readonly i: number
7572
readonly j: number
76-
readonly type: PropType
7773
readonly def: PropDefinition
7874
readonly x: number
7975
readonly y: number
@@ -83,14 +79,12 @@ export class PropSpawn implements IBox {
8379
constructor(
8480
i: number,
8581
j: number,
86-
type: PropType,
8782
def: PropDefinition,
8883
data: unknown,
8984
) {
90-
this.id = `${i}.${j}.${type}` // Unique ID for the spawn
85+
this.id = `${i}.${j}.${def.type}` // Unique ID for the spawn
9186
this.i = i
9287
this.j = j
93-
this.type = type
9488
this.data = data
9589
this.def = def
9690
this.x = i * CELL_SIZE
@@ -99,14 +93,14 @@ export class PropSpawn implements IBox {
9993

10094
equals(other: PropSpawn): boolean {
10195
return this.i === other.i && this.j === other.j &&
102-
this.type === other.type
96+
this.def.type === other.def.type
10397
}
10498

10599
toJSON(): BlockMapSource["props"][number] {
106100
const json: BlockMapSource["props"][number] = {
107101
i: this.i,
108102
j: this.j,
109-
type: this.type,
103+
type: this.def.type,
110104
}
111105
if (this.data !== undefined) {
112106
json.data = this.data
@@ -329,15 +323,13 @@ export class BlockMap {
329323
new ItemSpawn(
330324
item.i,
331325
item.j,
332-
item.type as ItemType,
333326
catalog.items[item.type]!,
334327
)
335328
)
336329
this.props = (source.props ?? []).map((prop) =>
337330
new PropSpawn(
338331
prop.i,
339332
prop.j,
340-
prop.type as PropType,
341333
catalog.props[prop.type]!,
342334
prop.data,
343335
)

model/item.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
IField,
99
IFollower,
1010
IItem,
11-
ItemType,
1211
LoadOptions,
1312
Move,
1413
} from "./types.ts"
@@ -27,7 +26,6 @@ export class Item implements IItem {
2726
readonly id: string
2827
i: number
2928
j: number
30-
readonly type: ItemType
3129
readonly def: ItemDefinition
3230
readonly w = CELL_SIZE
3331
readonly h = CELL_SIZE
@@ -80,33 +78,29 @@ export class Item implements IItem {
8078
spawn.id,
8179
spawn.i,
8280
spawn.j,
83-
spawn.type,
8481
spawn.def,
8582
)
8683
}
8784

8885
/**
8986
* @param i The column of the grid coordinate
9087
* @param j The row of the grid coordinate
91-
* @param type The type of item
9288
* @param def The item definition
9389
*/
9490
constructor(
9591
id: string | null,
9692
i: number,
9793
j: number,
98-
type: ItemType,
9994
def: ItemDefinition,
10095
) {
10196
this.id = id ?? `item-${i}-${j}-${crypto.randomUUID()}`
10297
this.i = i
10398
this.j = j
104-
this.type = type
10599
this.def = def
106100
}
107101

108102
onCollect(actor: Actor, field: IField) {
109-
switch (this.def.type) {
103+
switch (this.def.collect) {
110104
case "apple": {
111105
const delegate = new CollectApple()
112106
delegate.onCollect(actor, field, this)

model/prop.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
IField,
66
IProp,
77
LoadOptions,
8-
PropType,
98
PushedEvent,
109
} from "./types.ts"
1110
import { PropSpawn } from "./field-block.ts"
@@ -22,7 +21,6 @@ export class Prop implements IProp {
2221
readonly id: string | null
2322
readonly i: number
2423
readonly j: number
25-
readonly type: PropType
2624
readonly def: PropDefinition
2725
readonly data: unknown
2826
#motion: Motion | null = null
@@ -59,7 +57,6 @@ export class Prop implements IProp {
5957
spawn.id,
6058
spawn.i,
6159
spawn.j,
62-
spawn.type,
6360
spawn.def,
6461
pushed,
6562
spawn.data,
@@ -69,22 +66,21 @@ export class Prop implements IProp {
6966
/**
7067
* @param i The column of the grid coordinate
7168
* @param j The row of the grid coordinate
72-
* @param type The type of item
73-
* @param src The path to the asset image
69+
* @param def The definition of the prop
70+
* @param pushed The pushed delegate
71+
* @param data The additional data
7472
*/
7573
constructor(
7674
id: string | null,
7775
i: number,
7876
j: number,
79-
type: PropType,
8077
def: PropDefinition,
8178
pushed: PushedDelegate | null,
8279
data: unknown,
8380
) {
8481
this.id = id
8582
this.i = i
8683
this.j = j
87-
this.type = type
8884
this.def = def
8985
this.#pushed = pushed
9086
this.data = data

model/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,19 @@ export type IEntity = IBox & ILoader & {
2929
image(): ImageBitmap
3030
}
3131

32-
export type ItemType = "apple" | "green-apple" | "mushroom" | "purple-mushroom"
33-
3432
export type IItem = IEntity & IStepper & IFollowable & {
3533
id: string
3634
isFollowing: boolean
3735
onCollect(actor: IActor, field: IField): void
3836
}
3937

40-
export type PropType = "stool" | "table"
41-
4238
export type IProp =
4339
& IEntity
4440
& IStepper
4541
& FieldEventTarget
4642
& { onEnter(actor: IActor, field: IField): void }
4743
& {
4844
id: string | null
49-
type: PropType
5045
canEnter: boolean
5146
}
5247

0 commit comments

Comments
 (0)