diff --git a/.gitignore b/.gitignore index 2f94b93..dde891f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules package-lock.json +.cache \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index 400da33..0000000 --- a/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "cabin_server", - "version": "1.0.0", - "description": "", - "main": "server.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node server.js" - }, - "repository": { - "type": "git", - "url": "git+ssh://git@gitlab.com/totallyRonja/cabingame.git" - }, - "author": "", - "license": "ISC", - "bugs": { - "url": "https://gitlab.com/totallyRonja/cabingame/issues" - }, - "homepage": "https://gitlab.com/totallyRonja/cabingame#readme", - "dependencies": { - "express": "^4.17.1" - } -} diff --git a/server.js b/server.js deleted file mode 100644 index afd2bed..0000000 --- a/server.js +++ /dev/null @@ -1,9 +0,0 @@ -const express = require('express'); -var path = require("path"); -const app = express(); - -express.static.mime.define({'application/javascript': ['js']}); - -app.use(express.static('src')) - -app.listen(8080, () => console.log('Listening on port 8080!')); diff --git a/src/assets/Background.png b/src/assets/Background.png index 5709f13..6b6d494 100644 Binary files a/src/assets/Background.png and b/src/assets/Background.png differ diff --git a/src/src/demo.js b/src/game.ts similarity index 78% rename from src/src/demo.js rename to src/game.ts index 2fb531e..7746f2e 100644 --- a/src/src/demo.js +++ b/src/game.ts @@ -1,3 +1,7 @@ +import * as PIXI from "pixi.js" +import * as ECSY from "ecsy" +import { Entity } from "ecsy"; + const NUM_ELEMENTS = 60; const SPEED_MULTIPLIER = 1; const SHAPE_SIZE = 10; @@ -24,7 +28,7 @@ window.addEventListener( 'resize', recalculateSize, false ); function recalculateSize(){ let multiplier = Math.min(0, 0); - app.view.style.width = canvasWidth * "px"; + app.view.style.width = canvasWidth + "px"; app.view.style.height = "720px"; } @@ -37,23 +41,20 @@ app.stage.addChild(bgTex); // Velocity component class Velocity { - constructor() { - this.x = this.y = 0; - } + x = 0; + y = 0; } // Position component class Position { - constructor() { - this.x = this.y = 0; - } + x = 0; + y = 0; } // Shape component class Shape { - constructor() { - this.shape = null; - } + onStage = false + shape: PIXI.Graphics } // Renderable component @@ -66,9 +67,9 @@ class Renderable extends ECSY.TagComponent {} // MovableSystem class MovableSystem extends ECSY.System { // This method will get called on every frame by default - execute(delta) { + execute(delta : number) { // Iterate through all the entities on the query - this.queries.moving.results.forEach(entity => { + MovableSystem.queries.moving.results.forEach((entity: Entity) => { var velocity = entity.getComponent(Velocity); var position = entity.getMutableComponent(Position); position.x += velocity.x * delta; @@ -80,22 +81,23 @@ class MovableSystem extends ECSY.System { if (position.y < - SHAPE_HALF_SIZE) position.y = canvasHeight + SHAPE_HALF_SIZE; }); } -} -// Define a query of entities that have "Velocity" and "Position" components -MovableSystem.queries = { - moving: { - components: [Velocity, Position] + static queries = { + moving: { + components: [Velocity, Position], + results: [] + } } } + // RendererSystem class RendererSystem extends ECSY.System { // This method will get called on every frame by default - execute(delta) { + execute(delta : number) { // Iterate through all the entities on the query - this.queries.renderables.results.forEach(entity => { + RendererSystem.queries.renderables.results.forEach((entity: Entity) => { var shape = entity.getComponent(Shape); var position = entity.getComponent(Position); this.drawShape(position, shape); @@ -104,7 +106,7 @@ class RendererSystem extends ECSY.System { //app.renderer.render(app.stage); } - drawShape(position, shape) { + drawShape(position : Position, shape : Shape) { if(!shape.onStage){ app.stage.addChild(shape.shape); shape.onStage = true; @@ -113,12 +115,15 @@ class RendererSystem extends ECSY.System { shape.shape.x = position.x; shape.shape.y = position.y; } + + static queries = { + renderables: { + components: [Renderable, Shape], + results: [] + } + } } -// Define a query of entities that have "Renderable" and "Shape" components -RendererSystem.queries = { - renderables: { components: [Renderable, Shape] } -} // Create world and register the systems on it var world = new ECSY.World(); @@ -167,9 +172,11 @@ for (let i = 0; i < NUM_ELEMENTS; i++) { .addComponent(Position, getRandomPosition()) .addComponent(Renderable) } - + +let time = 0 // Run! -app.ticker.add((delta) => { +PIXI.Ticker.shared.add((delta : number) => { + time += delta; // Run all the systems - world.execute(delta); + world.execute(delta, time); }); \ No newline at end of file diff --git a/src/index.html b/src/index.html index ccd432e..a77ae77 100644 --- a/src/index.html +++ b/src/index.html @@ -18,11 +18,9 @@ image-rendering: crisp-edges; } - - - - + + - + \ No newline at end of file diff --git a/src/package.json b/src/package.json index d085101..d51fc54 100644 --- a/src/package.json +++ b/src/package.json @@ -1,15 +1,9 @@ { - "name": "cabin", - "version": "1.0.0", - "description": "", - "main": "index.js", + "devDependencies": { + "typescript": "^3.7.5" + }, "dependencies": { - "ecsy": "^0.2.1", - "pixi.js": "^5.2.0" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC" + "ecsy": "^0.2.2", + "pixi.js": "^5.2.1" + } } diff --git a/src/tsconfig.json b/src/tsconfig.json index e9abbc4..c919fc6 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,16 +1,62 @@ -// not used because typescript is weird - { "compilerOptions": { - "outDir": "./dist/", // path to output directory - "sourceMap": true, // allow sourcemap support - "strictNullChecks": false, // enable strict null checks as a best practice - "module": "commonjs", // specify module code generation - "target": "es6", // specify ECMAScript target version - "allowJs": true, // allow a partial TypeScript and JavaScript codebase - - }, - "include": [ - "./src/" - ] -} \ No newline at end of file + /* Basic Options */ + "target": "ES6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "lib", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + // "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + // "declarationDir": "lib" /* Output directory for generated declaration files. */ + } +}