Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------
import { Sprite } from "pixi.js";
import { injectable, inject, named, IHook } from "@robotlegsjs/core";
import { RectangleMediator } from "./RectangleMediator";
@injectable()
export class HookWithMediatorAndViewInjectionReportFunction implements IHook {
@inject(RectangleMediator)
public mediator: RectangleMediator;
@inject(Sprite)
public view: Sprite;
@inject("Function")
@named("reportView")
public reportView: Function;
public hook(): void {
this.reportView(this.view, this.mediator.width, this.mediator.height);
}
}
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------
import { injectable, inject } from "@robotlegsjs/core";
import { Sprite } from "pixi.js";
import { MediatorWatcher } from "./MediatorWatcher";
@injectable()
export class ExampleMediator2 {
@inject(MediatorWatcher)
public mediatorWatcher: MediatorWatcher;
@inject(Sprite)
public view: Sprite;
public initialize(): void {
this.mediatorWatcher.notify("ExampleMediator2");
}
public destroy(): void {
this.mediatorWatcher.notify("ExampleMediator2 destroy");
}
}
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------
import { injectable, inject } from "@robotlegsjs/core";
import { DisplayObject } from "pixi.js";
import { MediatorWatcher } from "./MediatorWatcher";
@injectable()
export class ExampleDisplayObjectMediator {
@inject(MediatorWatcher)
public mediatorWatcher: MediatorWatcher;
@inject(DisplayObject)
public view: DisplayObject;
public initialize(): void {
this.mediatorWatcher.notify("ExampleDisplayObjectMediator");
}
}
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------
import { Sprite } from "pixi.js";
import { injectable, inject, IGuard } from "@robotlegsjs/core";
@injectable()
export class OnlyIfViewHasChildrenGuard implements IGuard {
@inject(Sprite)
public view: Sprite;
public approve(): boolean {
return this.view.children.length > 0;
}
}
@inject("Function")
@named("preInitializeCallback")
@optional()
public preInitializeCallback: Function;
@inject("Function")
@named("initializeCallback")
@optional()
public initializeCallback: Function;
@inject("Function")
@named("postInitializeCallback")
@optional()
public postInitializeCallback: Function;
@inject("Function")
@named("preDestroyCallback")
@optional()
public preDestroyCallback: Function;
@inject("Function")
@named("destroyCallback")
@optional()
public destroyCallback: Function;
@inject("Function")
@named("postDestroyCallback")
@optional()
public postDestroyCallback: Function;
public initialized: Boolean = false;
import { ICommand, inject, injectable } from "@robotlegsjs/core";
import { GameEvent } from "./../../events/GameEvent";
import { GameManager } from "./../managers/GameManager";
import { SwapModel } from "./../models/SwapModel";
import { TouchPhase } from "./../models/TouchPhase";
@injectable()
export class SwapPiecesCommand implements ICommand {
@inject(SwapModel) private swapModel: SwapModel;
@inject(GameManager) private gameManager: GameManager;
@inject(GameEvent) private gameEvent: GameEvent;
public execute(): void {
this.swapModel.status = SwapModel.WAIT;
this.swapModel.setPosition(this.gameEvent.extra.phase, this.gameEvent.extra.col, this.gameEvent.extra.row);
if (this.gameEvent.extra.phase === TouchPhase.ENDED) {
this.swapModel.status = SwapModel.SWAP;
this.gameManager.nextStep.bind(this)();
}
}
}
import { inject, injectable } from "@robotlegsjs/core";
import { Mediator } from "@robotlegsjs/pixi";
import { FlowService } from "./../services/FlowService";
import { GameService } from "./../services/GameService";
import { GameOverPopup } from "./../views/GameOverPopup";
@injectable()
export class GameOverPopupMediator extends Mediator {
@inject(FlowService) private flowService: FlowService;
@inject(GameService) private gameService: GameService;
public initialize(): void {
this.eventMap.mapListener(this.view.homeButton, "click", this.homeButton_onClick, this);
this.eventMap.mapListener(this.view.retryButton, "click", this.retryButton_onClick, this);
}
public destroy(): void {
this.eventMap.unmapListeners();
}
private homeButton_onClick(e: any): void {
this.flowService.setHomeView();
this.flowService.closePopup();
}
private retryButton_onClick(e: any): void {
this.flowService.closePopup();
this.gameService.createLevel();
}
import { inject, injectable } from "@robotlegsjs/core";
import { Mediator } from "@robotlegsjs/pixi";
import { FlowService } from "./../services/FlowService";
import { GameService } from "./../services/GameService";
import { PausePopup } from "./../views/PausePopup";
@injectable()
export class PausePopupMediator extends Mediator {
@inject(FlowService) private flowService: FlowService;
@inject(GameService) private gameService: GameService;
public initialize(): void {
this.eventMap.mapListener(this.view.levelSelectButton, "click", this.levelSelectButton_onClick, this);
this.eventMap.mapListener(this.view.resumeButton, "click", this.resumeButton_onClick, this);
this.eventMap.mapListener(this.view.retryButton, "click", this.retryButton_onClick, this);
}
public destroy(): void {
this.eventMap.unmapListeners();
}
private levelSelectButton_onClick(e: any): void {
this.flowService.setLevelSelectView();
this.flowService.closePopup();
}
private resumeButton_onClick(e: any): void {
this.flowService.closePopup();
this.flowService.showStartingPopup();
import { ICommand, inject, injectable } from "@robotlegsjs/core";
import { GameModel } from "./../models/GameModel";
import { GameStatus } from "./../models/GameStatus";
import { FlowService } from "./../services/FlowService";
@injectable()
export class GameOverCommand implements ICommand {
@inject(GameModel) private model: GameModel;
@inject(FlowService) private flowService: FlowService;
public execute(): void {
this.model.status = GameStatus.GAMEOVER;
this.flowService.showGameOverPopup();
}
}
import { inject, injectable } from "@robotlegsjs/core";
import { Mediator } from "@robotlegsjs/pixi";
import { FlowService } from "./../services/FlowService";
import { OptionsView } from "./../views/OptionsView";
@injectable()
export class OptionsViewMediator extends Mediator {
@inject(FlowService) private flowService: FlowService;
public initialize(): void {
this.eventMap.mapListener(this.view.backButton, "click", this.backButton_onClick, this);
this.eventMap.mapListener(this.view.deleteButton, "click", this.deleteButton_onClick, this);
}
public destroy(): void {
this.eventMap.unmapListeners();
}
private backButton_onClick(e: any, thisObject: any): void {
this.flowService.setHomeView();
}
private deleteButton_onClick(e: any): void {
this.flowService.showAlertPopup();
}
}