Switch to TypeScript
This commit is contained in:
parent
1648b7e3d0
commit
bf71f55130
45 changed files with 754 additions and 159 deletions
49
src/world/module.ts
Normal file
49
src/world/module.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import {modules} from '../data';
|
||||
import {images as assets} from '../assets';
|
||||
|
||||
export default class Module {
|
||||
constructor(x, y, ship, {
|
||||
name = 'Unnamed Module',
|
||||
type = 'block',
|
||||
id = 'unknown',
|
||||
mass = 1,
|
||||
fuelCapacity = 0,
|
||||
...properties
|
||||
}) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.mass = mass;
|
||||
this.ship = ship;
|
||||
this.id = id;
|
||||
this.images = assets.modules[this.type][this.id];
|
||||
this.data = modules[this.type][this.id];
|
||||
|
||||
if (this.type == 'thruster') {
|
||||
this.power = 0;
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
if (this.type == 'thruster') {
|
||||
this.power = 0;
|
||||
}
|
||||
}
|
||||
|
||||
get com() {
|
||||
return this.ship.getWorldPoint(...this.localCom);
|
||||
}
|
||||
|
||||
get currentImage() {
|
||||
if (this.type == 'thruster') {
|
||||
return this.power > 0 ? this.images.on : this.images.off;
|
||||
} else {
|
||||
return this.images;
|
||||
}
|
||||
}
|
||||
|
||||
get localCom() {
|
||||
return [this.x + 0.5, this.y + 0.5];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue