From 14b06915c65b7192f52ea796e45174eda74faecb Mon Sep 17 00:00:00 2001 From: koneko <67551503+koneko@users.noreply.github.com> Date: Tue, 19 Nov 2024 23:54:25 +0100 Subject: [PATCH] begin rewriting --- {src => bsrc}/base/Assets.ts | 0 {src => bsrc}/base/Button.ts | 0 {src => bsrc}/base/Definitions.ts | 0 {src => bsrc}/base/Game.ts | 0 {src => bsrc}/base/GameObject.ts | 0 {src => bsrc}/base/ScrollingFrame.ts | 0 {src => bsrc}/components/Creep.ts | 0 {src => bsrc}/components/Grid.ts | 0 {src => bsrc}/components/MissionStats.ts | 0 {src => bsrc}/components/Sidebar.ts | 0 {src => bsrc}/components/Tower.ts | 0 {src => bsrc}/components/TowerPicker.ts | 0 {src => bsrc}/components/WaveManager.ts | 0 bsrc/main.ts | 23 +++++++++ {src => bsrc}/scenes/GameScene.ts | 0 {src => bsrc}/scenes/MainMenu.ts | 0 {src => bsrc}/scenes/MissionSelectMenu.ts | 0 {src => bsrc}/scenes/SceneBase.ts | 0 {src => bsrc}/scenes/SettingsMenu.ts | 0 bsrc/typescript.svg | 1 + bsrc/vite-env.d.ts | 1 + public/style.css | 15 ++++-- src/classes/Bastion.ts | 21 +++++++++ src/classes/DynamicObject.ts | 28 +++++++++++ src/main.ts | 57 ++++++++++++++--------- src/scenes/Main.ts | 0 tsconfig.json | 40 ++++++++-------- 27 files changed, 140 insertions(+), 46 deletions(-) rename {src => bsrc}/base/Assets.ts (100%) rename {src => bsrc}/base/Button.ts (100%) rename {src => bsrc}/base/Definitions.ts (100%) rename {src => bsrc}/base/Game.ts (100%) rename {src => bsrc}/base/GameObject.ts (100%) rename {src => bsrc}/base/ScrollingFrame.ts (100%) rename {src => bsrc}/components/Creep.ts (100%) rename {src => bsrc}/components/Grid.ts (100%) rename {src => bsrc}/components/MissionStats.ts (100%) rename {src => bsrc}/components/Sidebar.ts (100%) rename {src => bsrc}/components/Tower.ts (100%) rename {src => bsrc}/components/TowerPicker.ts (100%) rename {src => bsrc}/components/WaveManager.ts (100%) create mode 100644 bsrc/main.ts rename {src => bsrc}/scenes/GameScene.ts (100%) rename {src => bsrc}/scenes/MainMenu.ts (100%) rename {src => bsrc}/scenes/MissionSelectMenu.ts (100%) rename {src => bsrc}/scenes/SceneBase.ts (100%) rename {src => bsrc}/scenes/SettingsMenu.ts (100%) create mode 100644 bsrc/typescript.svg create mode 100644 bsrc/vite-env.d.ts create mode 100644 src/classes/Bastion.ts create mode 100644 src/classes/DynamicObject.ts create mode 100644 src/scenes/Main.ts diff --git a/src/base/Assets.ts b/bsrc/base/Assets.ts similarity index 100% rename from src/base/Assets.ts rename to bsrc/base/Assets.ts diff --git a/src/base/Button.ts b/bsrc/base/Button.ts similarity index 100% rename from src/base/Button.ts rename to bsrc/base/Button.ts diff --git a/src/base/Definitions.ts b/bsrc/base/Definitions.ts similarity index 100% rename from src/base/Definitions.ts rename to bsrc/base/Definitions.ts diff --git a/src/base/Game.ts b/bsrc/base/Game.ts similarity index 100% rename from src/base/Game.ts rename to bsrc/base/Game.ts diff --git a/src/base/GameObject.ts b/bsrc/base/GameObject.ts similarity index 100% rename from src/base/GameObject.ts rename to bsrc/base/GameObject.ts diff --git a/src/base/ScrollingFrame.ts b/bsrc/base/ScrollingFrame.ts similarity index 100% rename from src/base/ScrollingFrame.ts rename to bsrc/base/ScrollingFrame.ts diff --git a/src/components/Creep.ts b/bsrc/components/Creep.ts similarity index 100% rename from src/components/Creep.ts rename to bsrc/components/Creep.ts diff --git a/src/components/Grid.ts b/bsrc/components/Grid.ts similarity index 100% rename from src/components/Grid.ts rename to bsrc/components/Grid.ts diff --git a/src/components/MissionStats.ts b/bsrc/components/MissionStats.ts similarity index 100% rename from src/components/MissionStats.ts rename to bsrc/components/MissionStats.ts diff --git a/src/components/Sidebar.ts b/bsrc/components/Sidebar.ts similarity index 100% rename from src/components/Sidebar.ts rename to bsrc/components/Sidebar.ts diff --git a/src/components/Tower.ts b/bsrc/components/Tower.ts similarity index 100% rename from src/components/Tower.ts rename to bsrc/components/Tower.ts diff --git a/src/components/TowerPicker.ts b/bsrc/components/TowerPicker.ts similarity index 100% rename from src/components/TowerPicker.ts rename to bsrc/components/TowerPicker.ts diff --git a/src/components/WaveManager.ts b/bsrc/components/WaveManager.ts similarity index 100% rename from src/components/WaveManager.ts rename to bsrc/components/WaveManager.ts diff --git a/bsrc/main.ts b/bsrc/main.ts new file mode 100644 index 0000000..5f5c14b --- /dev/null +++ b/bsrc/main.ts @@ -0,0 +1,23 @@ +import * as PIXI from "pixi.js"; +import Game from "./base/Game"; +import Assets from "./base/Assets"; +(async () => { + const app = new PIXI.Application(); + await app.init({ + width: 640, + height: 360, + resizeTo: document.body, + backgroundColor: "white", + sharedTicker: true, + preference: "webgl", + }); + + document.body.appendChild(app.canvas); + await Assets.LoadAssets(); + const game = new Game(app.screen); + app.stage.addChild(game.container); + window.addEventListener("resize", () => { + app.renderer.resize(window.innerWidth, window.innerHeight); + game.setBounds(0, 0, app.screen.width, app.screen.height); + }); +})(); diff --git a/src/scenes/GameScene.ts b/bsrc/scenes/GameScene.ts similarity index 100% rename from src/scenes/GameScene.ts rename to bsrc/scenes/GameScene.ts diff --git a/src/scenes/MainMenu.ts b/bsrc/scenes/MainMenu.ts similarity index 100% rename from src/scenes/MainMenu.ts rename to bsrc/scenes/MainMenu.ts diff --git a/src/scenes/MissionSelectMenu.ts b/bsrc/scenes/MissionSelectMenu.ts similarity index 100% rename from src/scenes/MissionSelectMenu.ts rename to bsrc/scenes/MissionSelectMenu.ts diff --git a/src/scenes/SceneBase.ts b/bsrc/scenes/SceneBase.ts similarity index 100% rename from src/scenes/SceneBase.ts rename to bsrc/scenes/SceneBase.ts diff --git a/src/scenes/SettingsMenu.ts b/bsrc/scenes/SettingsMenu.ts similarity index 100% rename from src/scenes/SettingsMenu.ts rename to bsrc/scenes/SettingsMenu.ts diff --git a/bsrc/typescript.svg b/bsrc/typescript.svg new file mode 100644 index 0000000..d91c910 --- /dev/null +++ b/bsrc/typescript.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bsrc/vite-env.d.ts b/bsrc/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/bsrc/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/public/style.css b/public/style.css index b36f3cc..abf102a 100644 --- a/public/style.css +++ b/public/style.css @@ -1,10 +1,15 @@ * { - margin: 0; - padding: 0; + margin: 0; + padding: 0; } body, html { - width: 100vw; - height: 100vh; - overflow: hidden; + width: 100vw; + height: 100vh; + overflow: hidden; + background-color: red; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; } diff --git a/src/classes/Bastion.ts b/src/classes/Bastion.ts new file mode 100644 index 0000000..1203bf4 --- /dev/null +++ b/src/classes/Bastion.ts @@ -0,0 +1,21 @@ +import * as PIXI from 'pixi.js'; +import DynamicObject from './DynamicObject'; + +export class Foundation { + public static Master: Master; + public static WindowHeight: number; + public static WindowWidth: number; +} + +export default class Master { + public DynamicObjects: DynamicObject[]; + public ticker: PIXI.Ticker; + constructor() { + Foundation.Master = this; + this.ticker = new PIXI.Ticker(); + this.ticker.maxFPS = 60; + this.ticker.minFPS = 30; + this.ticker.add(() => this.update(this.ticker.elapsedMS)); // bruh + } + public update(elapsedMS) {} +} diff --git a/src/classes/DynamicObject.ts b/src/classes/DynamicObject.ts new file mode 100644 index 0000000..eb32f25 --- /dev/null +++ b/src/classes/DynamicObject.ts @@ -0,0 +1,28 @@ +import * as PIXI from 'pixi.js'; +import { Foundation } from './Bastion'; + +export default abstract class DynamicObject { + protected _container: PIXI.Container; + + protected bounds: PIXI.Rectangle; + + private _events: PIXI.EventEmitter = new PIXI.EventEmitter(); + + public abstract events: Enumerator; + + public destroy() { + this._events.removeAllListeners(); + if (this._container.parent) this._container.parent.removeChild(this._container); + this._container.destroy(); + } + + public get container(): PIXI.Container { + return this._container; + } + + constructor(bounds?: PIXI.Rectangle) { + this.bounds = bounds ?? new PIXI.Rectangle(0, 0, 0, 0); + this._container = new PIXI.Container(); + Foundation.Master.DynamicObjects.push(this); + } +} diff --git a/src/main.ts b/src/main.ts index 5f5c14b..45d46ed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,23 +1,38 @@ -import * as PIXI from "pixi.js"; -import Game from "./base/Game"; -import Assets from "./base/Assets"; -(async () => { - const app = new PIXI.Application(); - await app.init({ - width: 640, - height: 360, - resizeTo: document.body, - backgroundColor: "white", - sharedTicker: true, - preference: "webgl", - }); +import * as PIXI from 'pixi.js'; +import Master, { Foundation } from './classes/Bastion'; - document.body.appendChild(app.canvas); - await Assets.LoadAssets(); - const game = new Game(app.screen); - app.stage.addChild(game.container); - window.addEventListener("resize", () => { - app.renderer.resize(window.innerWidth, window.innerHeight); - game.setBounds(0, 0, app.screen.width, app.screen.height); - }); +(async () => { + const app = new PIXI.Application(); + const aspectRatio = 4 / 3; + const maxWidth = window.innerWidth; + const maxHeight = window.innerHeight; + const width = Math.min(maxWidth * 0.75, maxHeight * aspectRatio); + const height = width / aspectRatio; + Foundation.WindowWidth = width; + Foundation.WindowHeight = height; + + await app.init({ + width: width, + height: height, + backgroundColor: 'white', + sharedTicker: true, + preference: 'webgl', + }); + + document.body.appendChild(app.canvas); + window.addEventListener('resize', () => { + const newWidth = Math.min(window.innerWidth * 0.75, window.innerHeight * aspectRatio); + const newHeight = newWidth / aspectRatio; + Foundation.WindowWidth = newWidth; + Foundation.WindowHeight = newHeight; + app.renderer.resize(newWidth, newHeight); + }); + new Master(); + // await Assets.LoadAssets(); + // const game = new Game(app.screen); + // app.stage.addChild(game.container); + // window.addEventListener("resize", () => { + // app.renderer.resize(window.innerWidth, window.innerHeight); + // game.setBounds(0, 0, app.screen.width, app.screen.height); + // }); })(); diff --git a/src/scenes/Main.ts b/src/scenes/Main.ts new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/tsconfig.json index 5837dc5..cbbd5ac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,23 @@ { - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "module": "ESNext", - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "skipLibCheck": true, + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "isolatedModules": true, - "moduleDetection": "force", - "noEmit": true, - "noImplicitAny": false, - "esModuleInterop": true, - "strict": false, - "allowJs": true, - "checkJs": false - }, - "include": ["src/**/*"], - "exclude": ["node_modules", "build"] + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + "noImplicitAny": false, + "esModuleInterop": true, + "strict": false, + "allowJs": true, + "checkJs": false + }, + "include": ["bsrc/**/*"], + "exclude": ["node_modules", "build"] }