New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excalibur events should be organized and strongly typed #894

Open
eonarheim opened this Issue Oct 3, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@eonarheim
Member

eonarheim commented Oct 3, 2017

Context

Excalibur currently uses magic strings in places for events, which is a source of bugs. Excalibur should use strongly typed events seen in Events.ts and also organize events by type in a separate folder.

Proposal

Refactor the excalibur codebase to use strongly type events whenever an event string is required and organize event definitions into a separate folder. Move events all to the same ex. namespace

Acceptance criteria:

  • No magic string events
  • Organize events into separate files an folder
  • Move pointer and keyboard events from ex.Input. to ex.

For example in offscreen culling magic strings

if (!actor.isOffScreen) {
         if ((actorScreenCoords.x + width * zoom < 0 || 
            actorScreenCoords.y + height * zoom < 0 ||
            actorScreenCoords.x > engine.canvasWidth ||
            actorScreenCoords.y > engine.canvasHeight) &&
            isSpriteOffScreen ) {
            
            eventDispatcher.emit('exitviewport', new ExitViewPortEvent(actor));
            actor.isOffScreen = true;
         }
      } else {
         if ((actorScreenCoords.x + width * zoom > 0 &&
            actorScreenCoords.y + height * zoom > 0 &&
            actorScreenCoords.x < engine.canvasWidth &&
            actorScreenCoords.y < engine.canvasHeight) ||
            !isSpriteOffScreen) {
            
            eventDispatcher.emit('enterviewport', new EnterViewPortEvent(actor));               
            actor.isOffScreen = false;
         }
      }

Desired folder structure:

Events/
   ActorEvents.ts
   PointerEvents.ts
   EngineEvents.ts
   KeyboardEvents.ts

@jedeen jedeen added this to the vNext milestone Oct 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment