Skip to content

Commit

Permalink
refactored to use one output file
Browse files Browse the repository at this point in the history
  • Loading branch information
shixish committed Apr 3, 2016
1 parent 7b6bc5c commit 4a6108f
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 153 deletions.
6 changes: 2 additions & 4 deletions code/ts/BaseCreep.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
"use strict";
var _ = require('lodash'),
Globals = require('Globals');

declare var module: any;
(module).exports = class BaseCreep { //Abstract class
class BaseCreep { //Abstract class
public creep: Creep;

constructor(creep: Creep) {
Expand Down
8 changes: 3 additions & 5 deletions code/ts/BuilderCreep.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="Inventory.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var Globals = require('Globals'),
Inventory = require('Inventory'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class BuilderCreep extends BaseCreep {
class BuilderCreep extends BaseCreep {
public creep: Creep;
public hasStorage: boolean;

Expand Down
7 changes: 2 additions & 5 deletions code/ts/CourierCreep.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var _ = require('lodash'),
Globals = require('Globals'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class CourierCreep extends BaseCreep {
class CourierCreep extends BaseCreep {
public creep: Creep;

constructor(creep: Creep) {
Expand Down
8 changes: 4 additions & 4 deletions code/ts/Globals.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="../dts/require.d.ts" />

"use strict";
// var _ = require('lodash'),
// Inventory = require('Inventory');
var _ = require('lodash');

let PartCosts = {};
PartCosts[MOVE] = 50;
Expand All @@ -14,8 +15,7 @@ let PartCosts = {};

PathFinder.use(true);

declare var module: any;
(module).exports = {
var Globals = {
USERNAME: 'ShiXish',
MIN_TICKS_TO_LIVE: 500,
MAX_UNITS_METRIC: 3,
Expand Down
6 changes: 2 additions & 4 deletions code/ts/GuardCreep.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var Globals = require('Globals'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class GuardCreep extends BaseCreep {
class GuardCreep extends BaseCreep {
public creep: Creep;
public flag: Flag;

Expand Down
6 changes: 2 additions & 4 deletions code/ts/HarvesterCreep.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var Globals = require('Globals'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class HarvesterCreep extends BaseCreep {
class HarvesterCreep extends BaseCreep {
public creep: Creep;
public source: Source;
public link: Link;
Expand Down
5 changes: 2 additions & 3 deletions code/ts/Inventory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
"use strict";
var Globals = require('Globals');

declare var module: any;
(module).exports = class Inventory {
class Inventory {
// static flush() {
// for (let r in Game.rooms) {
// let room = Game.rooms[r];
Expand Down
6 changes: 2 additions & 4 deletions code/ts/LinkerCreep.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var Globals = require('Globals'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class LinkerCreep extends BaseCreep {
class LinkerCreep extends BaseCreep {
public creep: Creep;
public storage: Storage;
public link: Link;
Expand Down
7 changes: 2 additions & 5 deletions code/ts/MinerCreep.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var _ = require('lodash'),
Globals = require('Globals'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class MinerCreep extends BaseCreep {
class MinerCreep extends BaseCreep {
public creep: Creep;

constructor(creep: Creep) {
Expand Down
6 changes: 2 additions & 4 deletions code/ts/RangerCreep.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var Globals = require('Globals'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class RangerCreep extends BaseCreep {
class RangerCreep extends BaseCreep {
public creep: Creep;
public flag: Flag;

Expand Down
9 changes: 3 additions & 6 deletions code/ts/RunnerCreep.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="Inventory.ts" />
/// <reference path="BaseCreep.ts" />
"use strict";
var _ = require('lodash'),
Globals = require('Globals'),
Inventory = require('Inventory'),
BaseCreep = require('BaseCreep');

declare var module: any;
(module).exports = class RunnerCreep extends BaseCreep {
class RunnerCreep extends BaseCreep {
public creep: Creep;
public flag: Flag;

Expand Down
9 changes: 4 additions & 5 deletions code/ts/SourceController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="Inventory.ts" />
/// <reference path="HarvesterCreep.ts" />
"use strict";
var Globals = require('Globals'),
Inventory = require('Inventory'),
HarvesterCreep = require('HarvesterCreep');

declare var module: any;
(module).exports = class SourceController {
class SourceController {
public source: Source;
public link: Link;
public container: Container;
Expand Down
29 changes: 13 additions & 16 deletions code/ts/SpawnController.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="Inventory.ts" />
/// <reference path="BaseCreep.ts" />
/// <reference path="CourierCreep.ts" />
/// <reference path="HarvesterCreep.ts" />
/// <reference path="MinerCreep.ts" />
/// <reference path="BuilderCreep.ts" />
/// <reference path="GuardCreep.ts" />
/// <reference path="RangerCreep.ts" />
/// <reference path="RunnerCreep.ts" />
/// <reference path="LinkerCreep.ts" />
"use strict";
var _ = require('lodash'),
Globals = require('Globals'),
Inventory = require('Inventory'),
CourierCreep = require('CourierCreep'),
HarvesterCreep = require('HarvesterCreep'),
MinerCreep = require('MinerCreep'),
BuilderCreep = require('BuilderCreep'),
GuardCreep = require('GuardCreep'),
RangerCreep = require('RangerCreep'),
RunnerCreep = require('RunnerCreep'),
LinkerCreep = require('LinkerCreep');

declare var module: any;
(module).exports = class SpawnController {
class SpawnController {
structure: Spawn;
controller_level: number;

Expand Down Expand Up @@ -166,9 +163,9 @@ declare var module: any;
creep_memory['obsolete'] = true; //can't repair claim creeps.
}
//TODO:: USE : creep.getActiveBodyparts
let response = this.structure.createCreep(creep_body, null, creep_memory);
let response:any = this.structure.createCreep(creep_body, null, creep_memory);
if (!(response < 0)) {
let name = response;
let name:string = response;
console.log("Making a new " + creep_memory.role + " named " + name + " in room " + room.name);
Inventory.invNewCreep(creep_memory.role, name, room);
return response;//new creep name
Expand Down
7 changes: 3 additions & 4 deletions code/ts/TowerController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="Inventory.ts" />
"use strict";
var Globals = require('Globals'),
Inventory = require('Inventory');

declare var module: any;
(module).exports = class TowerController {
class TowerController {
private structure: Tower;
private max_repair_tiers = {
3: 25000,//tower at 3
Expand Down
93 changes: 15 additions & 78 deletions code/ts/main.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,20 @@
/// <reference path="../../node_modules/screeps-typescript-declarations/dist/screeps.d.ts" />
/// <reference path="Globals.ts" />
/// <reference path="Inventory.ts" />
/// <reference path="BaseCreep.ts" />
/// <reference path="CourierCreep.ts" />
/// <reference path="HarvesterCreep.ts" />
/// <reference path="MinerCreep.ts" />
/// <reference path="BuilderCreep.ts" />
/// <reference path="GuardCreep.ts" />
/// <reference path="RangerCreep.ts" />
/// <reference path="RunnerCreep.ts" />
/// <reference path="LinkerCreep.ts" />
/// <reference path="TowerController.ts" />
/// <reference path="SpawnController.ts" />
/// <reference path="SourceController.ts" />
"use strict";
// let _ = require('lodash'),
var Globals = require('Globals'),
CourierCreep = require('CourierCreep'),
HarvesterCreep = require('HarvesterCreep'),
MinerCreep = require('MinerCreep'),
LinkerCreep = require('LinkerCreep'),
BuilderCreep = require('BuilderCreep'),
GuardCreep = require('GuardCreep'),
RangerCreep = require('RangerCreep'),
RunnerCreep = require('RunnerCreep'),
TowerController = require('TowerController'),
SpawnController = require('SpawnController'),
SourceController = require('SourceController'),
Inventory = require('Inventory');
// Harvester = require('harvester'),
// Guard = require('guard'),
// Builder = require('builder'),
// Spawn = require('spawn');

// var USERNAME = 'ShiXish',
// MIN_TICKS_TO_LIVE = 200,
// MAX_UNITS_METRIC = 3,
// MAX_HITS_REPAIR = 200000;

// interface Room {
// storeSources();
// sources();
// }

// Room.prototype.storeSources = function() {
// let sources = this.find(FIND_SOURCES);
// this.memory.sources = {};
// for (let s in sources) {
// let source = sources[s];
// this.memory.sources[source.id] = {};
// // console.log(source.id);
// }
// }

// Room.prototype.sources = function() {
// if (!this.memory.sources) this.storeSources();
// // let sources = [];
// // for (let s in this.memory.sources){
// // let source_id = this.memory.sources[s];
// // sources.push(Game.getObjectById(source_id));
// // }
// // return sources;
// return this.memory.sources;
// }

declare var module: any;
let structure_controllers = {
'tower': TowerController,
'spawn': SpawnController,
Expand All @@ -74,6 +38,7 @@ function run_structure(type:string, structure: Structure) {
}
}

declare var module: any;
(module).exports.loop = function () {
Inventory.update();

Expand Down Expand Up @@ -131,33 +96,5 @@ function run_structure(type:string, structure: Structure) {
}else {
console.log("Unknown creep role:", creep);
}

/*
if (creep.memory.role == 'courier') {
let courier = new CourierCreep(creep);
courier.work();
} else if(creep.memory.role == 'linker') {
let linker = new LinkerCreep(creep);
linker.work();
} else if (creep.memory.role == 'harvester') {
let harvester = new HarvesterCreep(creep);
harvester.work();
} else if (creep.memory.role == 'miner') {
let miner = new MinerCreep(creep);
miner.work();
} else if (creep.memory.role == 'builder') {
let builder = new BuilderCreep(creep);
builder.work();
} else if (creep.memory.role == 'guard') {
let guard = new GuardCreep(creep);
guard.work();
} else if (creep.memory.role == 'ranger') {
let ranger = new RangerCreep(creep);
ranger.work();
} else if (creep.memory.role == 'runner') {
let runner = new RunnerCreep(creep);
runner.work();
}
*/
}
}
9 changes: 7 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ gulp.task('screeps', function() {
var tsResult = gulp.src(['code/ts/**.ts', 'code/dts/**.ts', "./node_modules/screeps-typescript-declarations/dist/screeps.d.ts"])
.pipe(ts({
// noImplicitAny: true,
// out: 'main.js',
out: 'main.js',
// declaration: true,
// noExternalResolve: true,
noExternalResolve: true,
// module: 'commonjs',
// module: 'amd',
// module: 'umd',
// module: 'system',
// moduleResolution: 'node',
target: 'ES6',
removeComments: true,
}));
Expand Down

0 comments on commit 4a6108f

Please sign in to comment.