-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created spaceship generator for debugging purposes.
- Loading branch information
Jim Buck
committed
Oct 5, 2018
1 parent
02cf957
commit f8ea65d
Showing
1 changed file
with
100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,126 @@ | ||
import { Stuff, Integer, Min, Max, Decimals, Pattern } from './decorators'; | ||
import { EOL } from 'os'; | ||
import { Model, Integer, Range, Float, Pattern, Choice, Enum, Collection, Include } from './decorators'; | ||
import { Activator } from './lib/services/activator'; | ||
import { Bool } from './lib/decorators/common-decorators'; | ||
|
||
let ships = Stuff.create<Spaceship>(2); | ||
enum ModuleType { | ||
SleepingQuarters, | ||
DiningRoom, | ||
RecRoom, | ||
Agricultural, | ||
MedicalBay, | ||
Engineering, | ||
FitnessCenter, | ||
ResearchStation, | ||
NavigationStation, | ||
WeaponsBay, | ||
ShieldRoom, | ||
CargoBay, | ||
} | ||
|
||
enum ModuleSize { | ||
Small, | ||
Medium, | ||
Large | ||
} | ||
|
||
@Stuff() | ||
@Model() | ||
class Engine { | ||
|
||
@Pattern(/(Rocketdyne|Areojet|Boeing|Lockheed|Kerbal) (A-Z)-\d{2,3}(D|X\S){0,1}/) | ||
@Choice(['Rocketdyne', 'Areojet', 'Boeing', 'Lockheed', 'SpaceX', 'Kerbal']) | ||
manufacturer: string; | ||
|
||
@Pattern(/[A-Z]{1,3}-\d{1,3}[DXS]{0,1}/) | ||
model: string; | ||
|
||
@Decimals(3) @Min(0) @Max(4000) | ||
horsepower: number; | ||
@Float(1) @Range(5, 12) | ||
thrust: number; | ||
|
||
@Decimals(0) @Min(1967) @Max(2020) | ||
@Integer() @Range(1967, 2020) | ||
year: number; | ||
|
||
@Float(3) @Range(200, 2000) | ||
mass: number; | ||
|
||
public toString() { | ||
return `${this.manufacturer} ${this.model} (${this.year})`; | ||
} | ||
} | ||
|
||
@Stuff() | ||
@Model() | ||
class Module { | ||
|
||
@Enum(ModuleType) | ||
type: string; | ||
|
||
@Enum(ModuleSize) | ||
size: number; | ||
|
||
@Bool(3 / 4) | ||
operational: boolean; | ||
|
||
@Float(3) @Range(200, 5000) | ||
mass: number; | ||
|
||
public toString() { | ||
return `${ModuleSize[this.size]} ${this.type} (Operational: ${this.operational})`; | ||
} | ||
} | ||
|
||
@Stuff() | ||
@Model() | ||
class Spaceship { | ||
|
||
@Decimals(0) @Min(0) @Max(10) | ||
landingGear: number; | ||
@Pattern(/[A-Z] Wing/) | ||
name: string; | ||
|
||
@Include() | ||
primaryEngines: Engine; | ||
|
||
@Integer() @Min(1) @Max(5) | ||
@Integer() @Range(1, 5) | ||
primaryEngineCount: number; | ||
|
||
@Include() | ||
secondaryEngines: Engine; | ||
|
||
@Integer() @Min(0) @Max(20) | ||
@Integer() @Range(0, 20) | ||
secondaryEngineCount: number; | ||
|
||
@Collection(Module) @Range(3, 8) | ||
modules: Array<Module>; | ||
} | ||
|
||
@Float(3) @Range(5000, 20000) | ||
hullMass: number; | ||
|
||
get totalThrust() { | ||
return (this.primaryEngines.thrust * this.primaryEngineCount) | ||
+ (this.secondaryEngines.thrust * this.secondaryEngineCount); | ||
} | ||
|
||
get totalMass() { | ||
let total = this.hullMass; | ||
|
||
total += this.primaryEngines.mass * this.primaryEngineCount; | ||
total += this.secondaryEngines.mass * this.secondaryEngineCount; | ||
|
||
this.modules.forEach(m => total += m.mass); | ||
|
||
return Math.round(total*100)/100; | ||
} | ||
|
||
public toString() { | ||
return `${this.name}: | ||
Engines: | ||
${this.primaryEngineCount}x ${this.primaryEngines} | ||
${this.secondaryEngineCount}x ${this.secondaryEngines} | ||
Modules: | ||
${this.modules.map(m => m.toString()).join(EOL + ' ')} | ||
Stats: | ||
Total Thrust: ${this.totalThrust} tons | ||
Total Mass: ${this.totalMass} kg`; | ||
} | ||
} | ||
|
||
let activator = new Activator(); | ||
|
||
let things = activator.create(Spaceship, 10); | ||
console.log(things.map(t => t.toString()).join(EOL + EOL)); |