1
0
Fork 0

Removed obsolete Tools module (now from tscommon)

This commit is contained in:
Michaël Lemaire 2017-01-27 01:07:06 +01:00
parent 92764542df
commit da6e961b1e
9 changed files with 7 additions and 82 deletions

@ -1 +1 @@
Subproject commit c79c6fa24da6b065163a45139722d368f0ca6d0f
Subproject commit 9fb3488f5f8b3c1ea82c34dbc48d831d15c3a48a

View file

@ -21,7 +21,7 @@ module TS.SpaceTac.Game {
var obj = container[obj_name];
var obj_path = path + "." + obj_name;
if (typeof obj === "object") {
result = Tools.merge(result, this.collectSerializableClasses(obj, obj_path));
result = merge(result, this.collectSerializableClasses(obj, obj_path));
} else if (typeof obj === "function" && obj.prototype instanceof Serializable) {
result[obj_path] = obj;
}

View file

@ -272,7 +272,7 @@ module TS.SpaceTac.Game {
* Clean sticky effects that are no longer active
*/
cleanStickyEffects() {
let [active, ended] = Tools.binpartition(this.sticky_effects, effect => effect.duration > 0);
let [active, ended] = binpartition(this.sticky_effects, effect => effect.duration > 0);
this.sticky_effects = active;
ended.forEach(effect => this.addBattleEvent(new EffectRemovedEvent(this, effect)));
}

View file

@ -1,38 +0,0 @@
module TS.SpaceTac.Game.Specs {
class TestObj {
a: string;
b: any;
constructor() {
this.a = "test";
this.b = { c: 5.1, d: ["unit", "test", 5] };
}
get(): string {
return this.a;
}
}
describe("Tools", () => {
it("copies full javascript objects", function () {
var ini = new TestObj();
var cop = Tools.copyObject(ini);
expect(cop).not.toBe(ini);
expect(cop).toEqual(ini);
expect(cop.get()).toEqual("test");
});
it("merges objects", function () {
expect(Tools.merge({}, {})).toEqual({});
expect(Tools.merge({ "a": 1 }, { "b": 2 })).toEqual({ "a": 1, "b": 2 });
expect(Tools.merge({ "a": 1 }, { "a": 3, "b": 2 })).toEqual({ "a": 3, "b": 2 });
});
it("partitions arrays by a predicate", function () {
expect(Tools.binpartition([1, 2, 3, 4], i => i % 2 == 0)).toEqual([[2, 4], [1, 3]]);
});
});
}

View file

@ -1,37 +0,0 @@
module TS.SpaceTac.Game {
// Generic tools functions
export class Tools {
// Copy an object (only a shallow copy of immediate properties)
static copyObject<T>(object: T): T {
var objectCopy = <T>Object.create(object.constructor.prototype);
for (var key in object) {
if (object.hasOwnProperty(key)) {
objectCopy[key] = object[key];
}
}
return objectCopy;
}
// Merge an object into another
static merge(base: any, incoming: any): any {
var result = Tools.copyObject(base);
for (var obj_name in incoming) {
if (obj_name) {
result[obj_name] = incoming[obj_name];
}
}
return result;
}
// Partition a list by a predicate, returning the items that pass the predicate, then the ones that don't pass it
static binpartition<T>(array: T[], predicate: (T) => boolean): [T[], T[]] {
let pass = [];
let fail = [];
array.forEach(item => (predicate(item) ? pass : fail).push(item));
return [pass, fail];
}
}
}

View file

@ -18,7 +18,7 @@ module TS.SpaceTac.Game {
* Get a copy, modified by template modifiers
*/
getModifiedCopy(modifiers: EffectTemplateModifier[], power: number): BaseEffect {
let result = Tools.copyObject(this);
let result = copy(this);
modifiers.forEach(modifier => {
result[modifier.name] = modifier.range.getProportional(power);
});

View file

@ -30,7 +30,7 @@ module TS.SpaceTac.Game {
}
getModifiedCopy(modifiers: EffectTemplateModifier[], power: number): BaseEffect {
let [current, base] = Tools.binpartition(modifiers, modifier => modifier.name == "duration");
let [current, base] = binpartition(modifiers, modifier => modifier.name == "duration");
let result = <StickyEffect>super.getModifiedCopy(current, power);
result.base = result.base.getModifiedCopy(base, power);
return result;

View file

@ -9,7 +9,7 @@ module TS.SpaceTac.Game {
constructor(ship: Ship, attribute: Attribute) {
super("attr", ship);
this.attribute = Tools.copyObject(attribute);
this.attribute = copy(attribute);
}
}
}

View file

@ -156,7 +156,7 @@ module TS.SpaceTac.View {
this.target_corrected = target;
this.blast_radius = blast_radius;
if (dispatch) {
this.target_initial = target ? Game.Tools.copyObject(target) : null;
this.target_initial = target ? copy(target) : null;
this.targetHovered.dispatch(this.target_corrected);
}
this.update();