Skip to content

Commit

Permalink
fix event decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
RSamaium committed Jan 27, 2024
1 parent 891fd71 commit 6a64c71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 2 additions & 8 deletions packages/server/src/Game/Map.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RpgCommonMap, Utils, RpgShape, RpgCommonGame, AbstractObject } from '@rpgjs/common'
import { TiledParserFile, TiledParser, TiledTileset } from '@rpgjs/tiled'
import { EventOptions } from '../decorators/event'
import { EventData, EventOptions } from '../decorators/event'
import { RpgPlayer, RpgEvent, RpgClassEvent } from '../Player/Player'
import { Move } from '../Player/MoveManager'
import { RpgServerEngine } from '../server'
Expand Down Expand Up @@ -398,13 +398,7 @@ export class RpgMap extends RpgCommonMap {

if ('$decorator' in event) {
const options = event.$decorator
event.mode = options.mode || EventMode.Shared
event.width = options.width
event.height = options.height
event.hitbox = options.hitbox
event._name = options.name
event.prototype._name = options.name
event.prototype.mode = event.mode
EventData(options)(event)
}

// The event is ignored if the mode is different.
Expand Down
14 changes: 10 additions & 4 deletions packages/server/src/decorators/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface EventOptions {
* @memberof EventData
* */
mode?: EventMode,

width?: number,
height?: number,

Expand All @@ -31,8 +31,8 @@ export interface EventOptions {
* @prop { { width: number, height: number }} [hitbox]
* @memberof EventData
* */
hitbox?: {
width?: number,
hitbox?: {
width?: number,
height?: number
},

Expand All @@ -47,6 +47,12 @@ export interface EventOptions {

export function EventData(options: EventOptions) {
return (target) => {
target.$decorator = options
target.mode = options.mode || EventMode.Shared
target.width = options.width
target.height = options.height
target.hitbox = options.hitbox
target._name = options.name
target.prototype._name = options.name
target.prototype.mode = target.mode
}
}

0 comments on commit 6a64c71

Please sign in to comment.