mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-12 01:44:05 +00:00
use GameView in renderers
This commit is contained in:
@@ -7,10 +7,11 @@ import { renderNumber, renderTroops } from '../../Utils';
|
||||
import { EventBus } from '../../../core/EventBus';
|
||||
import { UIState } from '../UIState';
|
||||
import { SendSetTargetTroopRatioEvent } from '../../Transport';
|
||||
import { GameView } from '../../../core/GameView';
|
||||
|
||||
@customElement('control-panel')
|
||||
export class ControlPanel extends LitElement implements Layer {
|
||||
private game: Game;
|
||||
public game: GameView;
|
||||
public clientID: ClientID;
|
||||
public eventBus: EventBus;
|
||||
public uiState: UIState;
|
||||
@@ -51,8 +52,7 @@ export class ControlPanel extends LitElement implements Layer {
|
||||
@state()
|
||||
private _goldPerSecond: number;
|
||||
|
||||
init(game: Game) {
|
||||
this.game = game;
|
||||
init() {
|
||||
this.attackRatio = .20;
|
||||
this.uiState.attackRatio = this.attackRatio;
|
||||
this.currentTroopRatio = this.targetTroopRatio;
|
||||
|
||||
@@ -17,6 +17,7 @@ import { Layer } from "./Layer";
|
||||
import { SendAllianceReplyIntentEvent } from "../../Transport";
|
||||
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
||||
import { onlyImages, sanitize } from '../../../core/Util';
|
||||
import { GameView } from '../../../core/GameView';
|
||||
|
||||
interface Event {
|
||||
description: string;
|
||||
@@ -35,7 +36,7 @@ interface Event {
|
||||
@customElement('events-display')
|
||||
export class EventsDisplay extends LitElement implements Layer {
|
||||
public eventBus: EventBus;
|
||||
public game: Game;
|
||||
public game: GameView;
|
||||
public clientID: ClientID;
|
||||
|
||||
private events: Event[] = [];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Game } from "../../../core/game/Game"
|
||||
|
||||
export interface Layer {
|
||||
init(game: Game)
|
||||
init()
|
||||
tick()
|
||||
renderLayer(context: CanvasRenderingContext2D)
|
||||
shouldTransform(): boolean
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ClientID } from '../../../core/Schemas';
|
||||
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
||||
import { EventBus, GameEvent } from '../../../core/EventBus';
|
||||
import { renderNumber } from '../../Utils';
|
||||
import { GameView } from '../../../core/GameView';
|
||||
|
||||
interface Entry {
|
||||
name: string
|
||||
@@ -23,12 +24,11 @@ export class GoToPlayerEvent implements GameEvent {
|
||||
@customElement('leader-board')
|
||||
export class Leaderboard extends LitElement implements Layer {
|
||||
|
||||
private game: Game
|
||||
public game: GameView
|
||||
public clientID: ClientID
|
||||
public eventBus: EventBus
|
||||
|
||||
init(game: Game) {
|
||||
this.game = game
|
||||
init() {
|
||||
}
|
||||
|
||||
tick() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import targetIcon from '../../../../resources/images/TargetIcon.png';
|
||||
import { ClientID } from "../../../core/Schemas"
|
||||
import { EventBus } from "../../../core/EventBus"
|
||||
import { AlternateViewEvent } from "../../InputHandler"
|
||||
import { GameView } from "../../../core/GameView"
|
||||
|
||||
|
||||
class RenderInfo {
|
||||
@@ -47,7 +48,7 @@ export class NameLayer implements Layer {
|
||||
private alternateView = false
|
||||
|
||||
constructor(
|
||||
private game: Game,
|
||||
private game: GameView,
|
||||
private eventBus: EventBus,
|
||||
private theme: Theme,
|
||||
private transformHandler: TransformHandler,
|
||||
@@ -72,7 +73,7 @@ export class NameLayer implements Layer {
|
||||
return true
|
||||
}
|
||||
|
||||
public init(game: Game) {
|
||||
public init() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,12 @@ import { MouseMoveEvent } from '../../InputHandler';
|
||||
import { euclideanDist, distSortUnit } from '../../../core/Util';
|
||||
import { renderNumber, renderTroops } from '../../Utils';
|
||||
import { PauseGameEvent } from '../../Transport';
|
||||
import { GameView } from '../../../core/GameView';
|
||||
|
||||
@customElement('player-info-overlay')
|
||||
export class PlayerInfoOverlay extends LitElement implements Layer {
|
||||
@property({ type: Object })
|
||||
public game!: Game;
|
||||
public game!: GameView;
|
||||
|
||||
@property({ type: String })
|
||||
public clientID!: ClientID;
|
||||
@@ -41,8 +42,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
|
||||
|
||||
private _isActive = false
|
||||
|
||||
init(game: Game) {
|
||||
this.game = game;
|
||||
init() {
|
||||
this.eventBus.on(MouseMoveEvent, (e: MouseMoveEvent) => this.onMouseEvent(e));
|
||||
this._isActive = true
|
||||
this.showPauseButton = this.game.config().gameConfig().gameType == GameType.Singleplayer
|
||||
|
||||
@@ -9,6 +9,7 @@ import anchorIcon from '../../../../resources/images/AnchorIcon.png';
|
||||
import missileSiloIcon from '../../../../resources/images/MissileSiloUnit.png';
|
||||
import shieldIcon from '../../../../resources/images/ShieldIcon.png';
|
||||
import cityIcon from '../../../../resources/images/CityIcon.png';
|
||||
import { GameView } from "../../../core/GameView";
|
||||
|
||||
interface UnitRenderConfig {
|
||||
icon: string;
|
||||
@@ -47,7 +48,7 @@ export class StructureLayer implements Layer {
|
||||
}
|
||||
};
|
||||
|
||||
constructor(private game: Game, private eventBus: EventBus) {
|
||||
constructor(private game: GameView, private eventBus: EventBus) {
|
||||
this.theme = game.config().theme();
|
||||
this.loadUnitImages();
|
||||
}
|
||||
@@ -69,7 +70,7 @@ export class StructureLayer implements Layer {
|
||||
tick() {
|
||||
}
|
||||
|
||||
init(game: Game) {
|
||||
init() {
|
||||
this.eventBus.on(UnitEvent, e => this.onUnitEvent(e));
|
||||
this.redraw()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Game } from "../../../core/game/Game";
|
||||
import { throws } from "assert";
|
||||
import { Layer } from "./Layer";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
import { GameView } from "../../../core/GameView";
|
||||
|
||||
export class TerrainLayer implements Layer {
|
||||
private canvas: HTMLCanvasElement
|
||||
@@ -10,14 +11,14 @@ export class TerrainLayer implements Layer {
|
||||
private imageData: ImageData
|
||||
|
||||
|
||||
constructor(private game: Game) { }
|
||||
constructor(private game: GameView) { }
|
||||
shouldTransform(): boolean {
|
||||
return true
|
||||
}
|
||||
tick() {
|
||||
}
|
||||
|
||||
init(game: Game) {
|
||||
init() {
|
||||
console.log('redrew terrain layer')
|
||||
this.redraw()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { TransformHandler } from "../TransformHandler";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { initRemoteSender } from "../../../core/Consolex";
|
||||
import { AlternateViewEvent } from "../../InputHandler";
|
||||
import { GameView } from "../../../core/GameView";
|
||||
|
||||
export class TerritoryLayer implements Layer {
|
||||
private canvas: HTMLCanvasElement
|
||||
@@ -26,7 +27,7 @@ export class TerritoryLayer implements Layer {
|
||||
private alternativeView = false
|
||||
|
||||
|
||||
constructor(private game: Game, private eventBus: EventBus) {
|
||||
constructor(private game: GameView, private eventBus: EventBus) {
|
||||
this.theme = game.config().theme()
|
||||
}
|
||||
|
||||
@@ -59,7 +60,7 @@ export class TerritoryLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
init(game: Game) {
|
||||
init() {
|
||||
this.eventBus.on(TileEvent, e => this.tileUpdate(e))
|
||||
this.eventBus.on(AlternateViewEvent, e => { this.alternativeView = e.alternateView })
|
||||
this.redraw()
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ClientID } from "../../../core/Schemas";
|
||||
import { Layer } from "./Layer";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
import { consolex } from "../../../core/Consolex";
|
||||
import { GameView } from "../../../core/GameView";
|
||||
|
||||
interface MenuOption {
|
||||
label: string;
|
||||
@@ -20,7 +21,7 @@ export class UILayer implements Layer {
|
||||
|
||||
constructor(
|
||||
private eventBus: EventBus,
|
||||
private game: Game,
|
||||
private game: GameView,
|
||||
private clientID: ClientID,
|
||||
private transformHandler: TransformHandler
|
||||
) {
|
||||
@@ -52,7 +53,7 @@ export class UILayer implements Layer {
|
||||
tick() {
|
||||
}
|
||||
|
||||
init(game: Game) {
|
||||
init() {
|
||||
this.createWinModal()
|
||||
this.initRightClickMenu()
|
||||
this.eventBus.on(WinEvent, (e) => this.onWinEvent(e))
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Layer } from "./Layer";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { AlternateViewEvent } from "../../InputHandler";
|
||||
import { ClientID } from "../../../core/Schemas";
|
||||
import { GameView } from "../../../core/GameView";
|
||||
|
||||
enum Relationship {
|
||||
Self,
|
||||
@@ -28,7 +29,7 @@ export class UnitLayer implements Layer {
|
||||
private oldShellTile = new Map<Unit, Tile>()
|
||||
|
||||
|
||||
constructor(private game: Game, private eventBus: EventBus, private clientID: ClientID) {
|
||||
constructor(private game: GameView, private eventBus: EventBus, private clientID: ClientID) {
|
||||
this.theme = game.config().theme();
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ export class UnitLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
init(game: Game) {
|
||||
init() {
|
||||
this.eventBus.on(UnitEvent, e => this.onUnitEvent(e));
|
||||
this.eventBus.on(AlternateViewEvent, e => this.onAlternativeViewEvent(e))
|
||||
this.redraw()
|
||||
|
||||
@@ -14,6 +14,7 @@ import shieldIcon from '../../../../../resources/images/ShieldIconWhite.svg';
|
||||
import cityIcon from '../../../../../resources/images/CityIconWhite.svg';
|
||||
import { renderNumber } from '../../../Utils';
|
||||
import { ContextMenuEvent } from '../../../InputHandler';
|
||||
import { GameView } from '../../../../core/GameView';
|
||||
|
||||
interface BuildItemDisplay {
|
||||
unitType: UnitType
|
||||
@@ -35,7 +36,7 @@ const buildTable: BuildItemDisplay[][] = [
|
||||
|
||||
@customElement('build-menu')
|
||||
export class BuildMenu extends LitElement {
|
||||
public game: Game;
|
||||
public game: GameView;
|
||||
public eventBus: EventBus;
|
||||
private myPlayer: Player;
|
||||
private clickedCell: Cell;
|
||||
|
||||
@@ -20,6 +20,7 @@ import { EmojiTable } from "./EmojiTable";
|
||||
import { UIState } from "../../UIState";
|
||||
import { BuildMenu } from "./BuildMenu";
|
||||
import { consolex } from "../../../../core/Consolex";
|
||||
import { GameView } from "../../../../core/GameView";
|
||||
|
||||
|
||||
enum Slot {
|
||||
@@ -53,7 +54,7 @@ export class RadialMenu implements Layer {
|
||||
|
||||
constructor(
|
||||
private eventBus: EventBus,
|
||||
private game: Game,
|
||||
private game: GameView,
|
||||
private transformHandler: TransformHandler,
|
||||
private clientID: ClientID,
|
||||
private emojiTable: EmojiTable,
|
||||
@@ -363,7 +364,7 @@ export class RadialMenu implements Layer {
|
||||
}
|
||||
|
||||
if (myPlayerBordersOcean && otherPlayerBordersOcean) {
|
||||
const dst = targetTransportTile(this.game, tile)
|
||||
const dst = targetTransportTile(this.game.width(), tile)
|
||||
if (dst != null) {
|
||||
if (myPlayer.canBuild(UnitType.TransportShip, dst)) {
|
||||
this.activateMenuElement(Slot.Boat, "#3f6ab1", boatIcon, () => {
|
||||
|
||||
Reference in New Issue
Block a user