File tree Expand file tree Collapse file tree 4 files changed +46
-1
lines changed Expand file tree Collapse file tree 4 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { Pathfinding } from './pathfinding';
16
16
import { Attack , AttackDamageType } from './player/attack' ;
17
17
import { Behavior } from './behaviors' ;
18
18
import { Effect , EffectType } from './effect' ;
19
+ import { ActorMetadata } from './metadata' ;
19
20
20
21
21
22
export type ActorType = 'player' | 'npc' ;
@@ -33,7 +34,16 @@ export abstract class Actor {
33
34
public readonly inventory : ItemContainer = new ItemContainer ( 28 ) ;
34
35
public readonly bank : ItemContainer = new ItemContainer ( 376 ) ;
35
36
public readonly actionPipeline = new ActionPipeline ( this ) ;
36
- public readonly metadata : { [ key : string ] : any } = { } ;
37
+
38
+ /**
39
+ * The map of available metadata for this actor.
40
+ *
41
+ * You cannot guarantee that this will be populated with data, so you should always check for the existence of the
42
+ * metadata you are looking for before using it.
43
+ *
44
+ * @author jameskmonger
45
+ */
46
+ public readonly metadata : Partial < ActorMetadata > = { } ;
37
47
38
48
/**
39
49
* @deprecated - use new action system instead
Original file line number Diff line number Diff line change
1
+ /**
2
+ * The definition of the metadata available on an {@link Actor}.
3
+ *
4
+ * You cannot guarantee that all of these properties will be present on an actor,
5
+ * so you should always check for their existence before using them.
6
+ *
7
+ * @author jameskmonger
8
+ */
9
+ export type ActorMetadata = {
10
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * The definition of the metadata directly available on a {@link Player}.
3
+ *
4
+ * This is a subset of the metadata available on an {@link Actor}. See {@link ActorMetadata} for more information.
5
+ *
6
+ * You cannot guarantee that all of these properties will be present on an actor,
7
+ * so you should always check for their existence before using them.
8
+ *
9
+ * @author jameskmonger
10
+ */
11
+ export type PlayerMetadata = {
12
+ } ;
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ import { dialogue } from '../dialogue';
45
45
import { Npc } from '../npc' ;
46
46
import { combatStyles } from '../combat' ;
47
47
import { SkillName } from '../skills' ;
48
+ import { PlayerMetadata } from './metadata' ;
48
49
49
50
50
51
export const playerOptions : { option : string , index : number , placement : 'TOP' | 'BOTTOM' } [ ] = [
@@ -117,6 +118,18 @@ export class Player extends Actor {
117
118
public cutscene : Cutscene = null ;
118
119
public playerEvents : EventEmitter = new EventEmitter ( ) ;
119
120
121
+ /**
122
+ * Override the Actor's `metadata` property to provide a more specific type.
123
+ *
124
+ * You cannot guarantee that this will be populated with data, so you should always check for the existence of the
125
+ * metadata you are looking for before using it.
126
+ *
127
+ * The ! is used to tell the compiler that we know this property will be defined.
128
+ *
129
+ * @author jameskmonger
130
+ */
131
+ public readonly metadata ! : ( Actor [ 'metadata' ] & Partial < PlayerMetadata > ) ;
132
+
120
133
private readonly _socket : Socket ;
121
134
private readonly _inCipher : Isaac ;
122
135
private readonly _outCipher : Isaac ;
You can’t perform that action at this time.
0 commit comments