begin rewriting

This commit is contained in:
koneko 2024-11-19 23:54:25 +01:00
parent 84d85814cc
commit 14b06915c6
27 changed files with 140 additions and 46 deletions

23
bsrc/main.ts Normal file
View File

@ -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);
});
})();

1
bsrc/typescript.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#007ACC" d="M0 128v128h256V0H0z"></path><path fill="#FFF" d="m56.612 128.85l-.081 10.483h33.32v94.68h23.568v-94.68h33.321v-10.28c0-5.69-.122-10.444-.284-10.566c-.122-.162-20.4-.244-44.983-.203l-44.74.122l-.121 10.443Zm149.955-10.742c6.501 1.625 11.459 4.51 16.01 9.224c2.357 2.52 5.851 7.111 6.136 8.208c.08.325-11.053 7.802-17.798 11.988c-.244.162-1.22-.894-2.317-2.52c-3.291-4.795-6.745-6.867-12.028-7.233c-7.76-.528-12.759 3.535-12.718 10.321c0 1.992.284 3.17 1.097 4.795c1.707 3.536 4.876 5.649 14.832 9.956c18.326 7.883 26.168 13.084 31.045 20.48c5.445 8.249 6.664 21.415 2.966 31.208c-4.063 10.646-14.14 17.879-28.323 20.276c-4.388.772-14.79.65-19.504-.203c-10.28-1.828-20.033-6.908-26.047-13.572c-2.357-2.6-6.949-9.387-6.664-9.874c.122-.163 1.178-.813 2.356-1.504c1.138-.65 5.446-3.129 9.509-5.485l7.355-4.267l1.544 2.276c2.154 3.29 6.867 7.801 9.712 9.305c8.167 4.307 19.383 3.698 24.909-1.26c2.357-2.153 3.332-4.388 3.332-7.68c0-2.966-.366-4.266-1.91-6.501c-1.99-2.845-6.054-5.242-17.595-10.24c-13.206-5.69-18.895-9.224-24.096-14.832c-3.007-3.25-5.852-8.452-7.03-12.8c-.975-3.617-1.22-12.678-.447-16.335c2.723-12.76 12.353-21.659 26.25-24.3c4.51-.853 14.994-.528 19.424.569Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

1
bsrc/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

View File

@ -7,4 +7,9 @@ html {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
overflow: hidden; overflow: hidden;
background-color: red;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
} }

21
src/classes/Bastion.ts Normal file
View File

@ -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) {}
}

View File

@ -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);
}
}

View File

@ -1,23 +1,38 @@
import * as PIXI from "pixi.js"; import * as PIXI from 'pixi.js';
import Game from "./base/Game"; import Master, { Foundation } from './classes/Bastion';
import Assets from "./base/Assets";
(async () => { (async () => {
const app = new PIXI.Application(); 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({ await app.init({
width: 640, width: width,
height: 360, height: height,
resizeTo: document.body, backgroundColor: 'white',
backgroundColor: "white",
sharedTicker: true, sharedTicker: true,
preference: "webgl", preference: 'webgl',
}); });
document.body.appendChild(app.canvas); document.body.appendChild(app.canvas);
await Assets.LoadAssets(); window.addEventListener('resize', () => {
const game = new Game(app.screen); const newWidth = Math.min(window.innerWidth * 0.75, window.innerHeight * aspectRatio);
app.stage.addChild(game.container); const newHeight = newWidth / aspectRatio;
window.addEventListener("resize", () => { Foundation.WindowWidth = newWidth;
app.renderer.resize(window.innerWidth, window.innerHeight); Foundation.WindowHeight = newHeight;
game.setBounds(0, 0, app.screen.width, app.screen.height); 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);
// });
})(); })();

0
src/scenes/Main.ts Normal file
View File

View File

@ -18,6 +18,6 @@
"allowJs": true, "allowJs": true,
"checkJs": false "checkJs": false
}, },
"include": ["src/**/*"], "include": ["bsrc/**/*"],
"exclude": ["node_modules", "build"] "exclude": ["node_modules", "build"]
} }