add prettier config and fix files
This commit is contained in:
parent
698967c987
commit
1d2473dae8
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
@ -1,19 +1,19 @@
|
|||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
import { MissionDefinition } from "./Definitions";
|
import { MissionDefinition } from './Definitions';
|
||||||
|
|
||||||
export default class Assets {
|
export default class Assets {
|
||||||
public static async LoadAssets() {
|
public static async LoadAssets() {
|
||||||
console.log("Loading Texture Assets");
|
console.log('Loading Texture Assets');
|
||||||
Assets.ButtonTexture = await PIXI.Assets.load({
|
Assets.ButtonTexture = await PIXI.Assets.load({
|
||||||
src: "/assets/gui/button_02.png",
|
src: '/assets/gui/button_02.png',
|
||||||
});
|
});
|
||||||
console.log("Loading Missions");
|
console.log('Loading Missions');
|
||||||
await this.LoadMissions();
|
await this.LoadMissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async LoadMissions() {
|
private static async LoadMissions() {
|
||||||
Assets.Missions = [
|
Assets.Missions = [
|
||||||
await this.LoadMission("/assets/missions/mission_01.json"),
|
await this.LoadMission('/assets/missions/mission_01.json'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import GameObject from "./GameObject";
|
import GameObject from './GameObject';
|
||||||
import Assets from "./Assets";
|
import Assets from './Assets';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
export default class Button extends GameObject {
|
export default class Button extends GameObject {
|
||||||
private caption: string;
|
private caption: string;
|
||||||
@ -63,9 +63,9 @@ export default class Button extends GameObject {
|
|||||||
text.y = this.bounds.height / 2;
|
text.y = this.bounds.height / 2;
|
||||||
this.container.x = this.bounds.x;
|
this.container.x = this.bounds.x;
|
||||||
this.container.y = this.bounds.y;
|
this.container.y = this.bounds.y;
|
||||||
this.container.on("click", () => {
|
this.container.on('click', () => {
|
||||||
if (!this.enabled) return;
|
if (!this.enabled) return;
|
||||||
this.events.emit("click");
|
this.events.emit('click');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import MainMenu from "../scenes/MainMenu";
|
import MainMenu from '../scenes/MainMenu';
|
||||||
import MissionMenuSelect from "../scenes/MissionSelectMenu";
|
import MissionMenuSelect from '../scenes/MissionSelectMenu';
|
||||||
import GameScene from "../scenes/GameScene";
|
import GameScene from '../scenes/GameScene';
|
||||||
import GameObject from "./GameObject";
|
import GameObject from './GameObject';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
import SceneBase from "../scenes/SceneBase";
|
import SceneBase from '../scenes/SceneBase';
|
||||||
|
|
||||||
export default class Game extends GameObject {
|
export default class Game extends GameObject {
|
||||||
private _currentScene: SceneBase | null = null;
|
private _currentScene: SceneBase | null = null;
|
||||||
@ -15,8 +15,8 @@ export default class Game extends GameObject {
|
|||||||
|
|
||||||
private onMainMenu() {
|
private onMainMenu() {
|
||||||
const mainScene = new MainMenu(this.bounds);
|
const mainScene = new MainMenu(this.bounds);
|
||||||
mainScene.events.on("newGame", this.onNewGame);
|
mainScene.events.on('newGame', this.onNewGame);
|
||||||
mainScene.events.on("settings", this.onSettings);
|
mainScene.events.on('settings', this.onSettings);
|
||||||
this.setScene(mainScene);
|
this.setScene(mainScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,30 +26,35 @@ export default class Game extends GameObject {
|
|||||||
this._currentScene.destroy();
|
this._currentScene.destroy();
|
||||||
}
|
}
|
||||||
this._currentScene = scene;
|
this._currentScene = scene;
|
||||||
console.log("Setting scene", this._currentScene.constructor);
|
console.log('Setting scene', this._currentScene.constructor);
|
||||||
this.container.addChild(scene.container);
|
this.container.addChild(scene.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onNewGame = () => {
|
private onNewGame = () => {
|
||||||
console.log("New Game");
|
console.log('New Game');
|
||||||
const missionSelectScene = new MissionMenuSelect(this.bounds);
|
const missionSelectScene = new MissionMenuSelect(this.bounds);
|
||||||
missionSelectScene.events.on("mission", (mission) => {
|
missionSelectScene.events.on('mission', (mission) => {
|
||||||
console.log("Mission selected", mission);
|
console.log('Mission selected', mission);
|
||||||
this.setScene(new GameScene(mission, this.bounds));
|
this.setScene(new GameScene(mission, this.bounds));
|
||||||
});
|
});
|
||||||
missionSelectScene.events.on("back", () => {
|
missionSelectScene.events.on('back', () => {
|
||||||
this.onMainMenu();
|
this.onMainMenu();
|
||||||
});
|
});
|
||||||
this.setScene(missionSelectScene);
|
this.setScene(missionSelectScene);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onSettings = () => {
|
private onSettings = () => {
|
||||||
console.log("Settings");
|
console.log('Settings');
|
||||||
};
|
};
|
||||||
|
|
||||||
protected triggerBoundsChanged(): void {
|
protected triggerBoundsChanged(): void {
|
||||||
if (this._currentScene) {
|
if (this._currentScene) {
|
||||||
this._currentScene.setBounds(0, 0, this.bounds.width, this.bounds.height);
|
this._currentScene.setBounds(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
this.bounds.width,
|
||||||
|
this.bounds.height
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
export default abstract class GameObject {
|
export default abstract class GameObject {
|
||||||
protected _container: PIXI.Container;
|
protected _container: PIXI.Container;
|
||||||
|
|
||||||
|
15
src/components/Creep.ts
Normal file
15
src/components/Creep.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import GameObject from '../base/GameObject';
|
||||||
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
|
export class Creep extends GameObject {
|
||||||
|
constructor(bounds?: PIXI.Rectangle) {
|
||||||
|
super(bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected draw() {
|
||||||
|
this.container.removeChildren();
|
||||||
|
|
||||||
|
this.container.x = this.bounds.x;
|
||||||
|
this.container.y = this.bounds.y;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
import GameObject from "../base/GameObject";
|
import GameObject from '../base/GameObject';
|
||||||
import { GameMapDefinition, TerrainType } from "../base/Definitions";
|
import { GameMapDefinition, TerrainType } from '../base/Definitions';
|
||||||
|
|
||||||
export class Cell extends GameObject {
|
export class Cell extends GameObject {
|
||||||
public type: TerrainType;
|
public type: TerrainType;
|
||||||
@ -65,7 +65,7 @@ export class Grid extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected draw() {
|
protected draw() {
|
||||||
console.log("Drawing Grid", this.bounds);
|
console.log('Drawing Grid', this.bounds);
|
||||||
this.container.removeChildren();
|
this.container.removeChildren();
|
||||||
let g = new PIXI.Graphics();
|
let g = new PIXI.Graphics();
|
||||||
g.rect(0, 0, this.bounds.width, this.bounds.height);
|
g.rect(0, 0, this.bounds.width, this.bounds.height);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import GameObject from "../base/GameObject";
|
import GameObject from '../base/GameObject';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
export default class MissionStats extends GameObject {
|
export default class MissionStats extends GameObject {
|
||||||
private hp: number = 100;
|
private hp: number = 100;
|
||||||
@ -15,7 +15,11 @@ export default class MissionStats extends GameObject {
|
|||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(initialHP: number, initialGold: number, bounds?: PIXI.Rectangle) {
|
constructor(
|
||||||
|
initialHP: number,
|
||||||
|
initialGold: number,
|
||||||
|
bounds?: PIXI.Rectangle
|
||||||
|
) {
|
||||||
super(bounds);
|
super(bounds);
|
||||||
this.hp = initialHP;
|
this.hp = initialHP;
|
||||||
this.gold = initialGold;
|
this.gold = initialGold;
|
||||||
@ -31,7 +35,7 @@ export default class MissionStats extends GameObject {
|
|||||||
const text = new PIXI.Text({
|
const text = new PIXI.Text({
|
||||||
text: `HP: ${this.hp}\nGold: ${this.gold}`,
|
text: `HP: ${this.hp}\nGold: ${this.gold}`,
|
||||||
style: new PIXI.TextStyle({
|
style: new PIXI.TextStyle({
|
||||||
fill: "white",
|
fill: 'white',
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import Button from "../base/Button";
|
import Button from '../base/Button';
|
||||||
import { MissionDefinition } from "../base/Definitions";
|
import { MissionDefinition } from '../base/Definitions';
|
||||||
import { Grid } from "../components/Grid";
|
import { Grid } from '../components/Grid';
|
||||||
import MissionStats from "../components/MissionStats";
|
import MissionStats from '../components/MissionStats';
|
||||||
import SceneBase from "./SceneBase";
|
import SceneBase from './SceneBase';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
export default class GameScene extends SceneBase {
|
export default class GameScene extends SceneBase {
|
||||||
private ticker: PIXI.Ticker;
|
private ticker: PIXI.Ticker;
|
||||||
@ -47,7 +47,7 @@ export default class GameScene extends SceneBase {
|
|||||||
public update() {}
|
public update() {}
|
||||||
|
|
||||||
protected draw() {
|
protected draw() {
|
||||||
console.log("Drawing Game Scene ", this.bounds);
|
console.log('Drawing Game Scene ', this.bounds);
|
||||||
this.container.removeChildren();
|
this.container.removeChildren();
|
||||||
const g = new PIXI.Graphics();
|
const g = new PIXI.Graphics();
|
||||||
g.rect(0, 0, this.bounds.width, this.bounds.height);
|
g.rect(0, 0, this.bounds.width, this.bounds.height);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Button from "../base/Button";
|
import Button from '../base/Button';
|
||||||
import SceneBase from "./SceneBase";
|
import SceneBase from './SceneBase';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
export default class MainMenu extends SceneBase {
|
export default class MainMenu extends SceneBase {
|
||||||
private _newGameButton: Button;
|
private _newGameButton: Button;
|
||||||
@ -8,19 +8,19 @@ export default class MainMenu extends SceneBase {
|
|||||||
|
|
||||||
constructor(bounds?: PIXI.Rectangle) {
|
constructor(bounds?: PIXI.Rectangle) {
|
||||||
super(bounds);
|
super(bounds);
|
||||||
this._newGameButton = new Button("New Game", new PIXI.Color("blue"));
|
this._newGameButton = new Button('New Game', new PIXI.Color('blue'));
|
||||||
this._newGameButton.events.on("click", () => {
|
this._newGameButton.events.on('click', () => {
|
||||||
this.events.emit("newGame");
|
this.events.emit('newGame');
|
||||||
});
|
});
|
||||||
this._settingsButton = new Button("Settings", new PIXI.Color("gray"));
|
this._settingsButton = new Button('Settings', new PIXI.Color('gray'));
|
||||||
this._settingsButton.events.on("click", () => {
|
this._settingsButton.events.on('click', () => {
|
||||||
this.events.emit("settings");
|
this.events.emit('settings');
|
||||||
});
|
});
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected draw() {
|
protected draw() {
|
||||||
console.log("Creating main menu scene", this.bounds);
|
console.log('Creating main menu scene', this.bounds);
|
||||||
this.container.removeChildren();
|
this.container.removeChildren();
|
||||||
const g = new PIXI.Graphics();
|
const g = new PIXI.Graphics();
|
||||||
g.rect(0, 0, this.bounds.width, this.bounds.height);
|
g.rect(0, 0, this.bounds.width, this.bounds.height);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import Assets from "../base/Assets";
|
import Assets from '../base/Assets';
|
||||||
import Button from "../base/Button";
|
import Button from '../base/Button';
|
||||||
import { MissionDefinition } from "../base/Definitions";
|
import { MissionDefinition } from '../base/Definitions';
|
||||||
import SceneBase from "./SceneBase";
|
import SceneBase from './SceneBase';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
export default class MissionMenuSelect extends SceneBase {
|
export default class MissionMenuSelect extends SceneBase {
|
||||||
private _buttons: Button[] = [];
|
private _buttons: Button[] = [];
|
||||||
@ -12,8 +12,8 @@ export default class MissionMenuSelect extends SceneBase {
|
|||||||
for (const mission of Assets.Missions) {
|
for (const mission of Assets.Missions) {
|
||||||
this.addMission(mission);
|
this.addMission(mission);
|
||||||
}
|
}
|
||||||
this.addButton("Back", () => {
|
this.addButton('Back', () => {
|
||||||
this.events.emit("back");
|
this.events.emit('back');
|
||||||
});
|
});
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
@ -36,13 +36,13 @@ export default class MissionMenuSelect extends SceneBase {
|
|||||||
|
|
||||||
private addMission(mission: MissionDefinition) {
|
private addMission(mission: MissionDefinition) {
|
||||||
this.addButton(mission.name, () => {
|
this.addButton(mission.name, () => {
|
||||||
this.events.emit("mission", mission);
|
this.events.emit('mission', mission);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private addButton(caption: string, onClick: () => void) {
|
private addButton(caption: string, onClick: () => void) {
|
||||||
const button = new Button(caption, new PIXI.Color("white"));
|
const button = new Button(caption, new PIXI.Color('white'));
|
||||||
button.events.on("click", onClick);
|
button.events.on('click', onClick);
|
||||||
this._buttons.push(button);
|
this._buttons.push(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
import GameObject from "../base/GameObject";
|
import GameObject from '../base/GameObject';
|
||||||
export default abstract class SceneBase extends GameObject {
|
export default abstract class SceneBase extends GameObject {
|
||||||
constructor(bounds: PIXI.Rectangle) {
|
constructor(bounds: PIXI.Rectangle) {
|
||||||
super(bounds);
|
super(bounds);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Button from "../base/Button";
|
import Button from '../base/Button';
|
||||||
import SceneBase from "./SceneBase";
|
import SceneBase from './SceneBase';
|
||||||
import * as PIXI from "pixi.js";
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
export default class SettingsMenu extends SceneBase {
|
export default class SettingsMenu extends SceneBase {
|
||||||
constructor(bounds: PIXI.Rectangle) {
|
constructor(bounds: PIXI.Rectangle) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user