try to move everything to typescript, but inheritance doesn't work
This commit is contained in:
parent
1d67b4b8e7
commit
2d6f770272
8 changed files with 104 additions and 90 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
package-lock.json
|
||||
.cache
|
||||
23
package.json
23
package.json
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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!'));
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 6.1 KiB |
|
|
@ -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);
|
||||
});
|
||||
|
|
@ -18,11 +18,9 @@
|
|||
image-rendering: crisp-edges;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="node_modules/pixi.js/dist/pixi.js"></script>
|
||||
<script src="node_modules/ecsy/build/ecsy.js"></script>
|
||||
</head>
|
||||
<script> var exports = {}; </script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="src/demo.js" type="module"></script>
|
||||
<script src="game.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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/"
|
||||
]
|
||||
}
|
||||
/* 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. */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue