From 2d6f770272c9bf6664fa3527b83512ba2bc097f7 Mon Sep 17 00:00:00 2001 From: Ronja Date: Tue, 4 Feb 2020 23:01:07 +0100 Subject: [PATCH] try to move everything to typescript, but inheritance doesn't work --- .gitignore | 1 + package.json | 23 ----------- server.js | 9 ----- src/assets/Background.png | Bin 1379 -> 6234 bytes src/{src/demo.js => game.ts} | 61 ++++++++++++++++------------- src/index.html | 8 ++-- src/package.json | 18 +++------ src/tsconfig.json | 74 ++++++++++++++++++++++++++++------- 8 files changed, 104 insertions(+), 90 deletions(-) delete mode 100644 package.json delete mode 100644 server.js rename src/{src/demo.js => game.ts} (78%) 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 5709f13c023c76268eed6ed1c860aa1d282efce3..6b6d49441fad5c4998a66f957edf771066070295 100644 GIT binary patch literal 6234 zcmZ8mdsxzU+qZSFZEV)+dCN3y`BdvMvm_6x=u?`mqbn=(1f~g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E&e3XZn%J>rRdPh^6F$7>|2Y9($csjn`8e`Ao{k6m$W<^kj$Yj#37t|C{3; zD2bwiCE}vCxK=_$4YAP6im!+zij|&-Oh~2GlR4h6{M_h2db>BmXDUWhL z3MtO6x1Pm?-S!HR^-vKZj@NQ+Cp5x#*UQB0KuuKV;d8D9C4&Xu`*9kf)yQDfWS%HSzwYS@5+yG8V}ch%O+PAJ zBSX}R;?}fIoY2U6%SuMxYvS5ALycEwNTeU9%0X<9Bhq0%>Z)H67so;hE{>WTqRKkZ z3zQ>b-+2Eo;rWV!s3{3_4Uq29XjF*zC)F&mQ(BE{*ESo^6*6(+h;-187{==~Lddo_ zd|r$8n*At?WFk*g7J-d40PeY)5=U1|mC+L!6OivVb41_)659V}h`Dqssb>oRo9-zZ z*KCE$Y3FH9_p%=+x$?1E8K=#h>EoV8h3f7e)Y0=yY4#n`k<;2;DWAkhGu}1=qKeo` zwkI^6cf{HlXgWM@*F$lkADq6!g@g0Nd(nNu@N&JGD~=HMy8*>G!&WJ*%}F%x=hy4` za9yM#O6IR}nDcnNUSIF$VZWa#aqXS6Mp{ZPnPO~F%=7(vysXBfCeC+{uki7FSc$&a z9C0G-)@MxE2(4*DpJ0QyJ(f}bF2brx&1k=v^iW(PI>Gd5IseQg< { + 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. */ + } +}