1
0
Fork 0

Fixed some targetting issues

This commit is contained in:
Michaël Lemaire 2017-10-01 18:33:48 +02:00
parent 79e8ab789d
commit 5a730762d1
13 changed files with 482 additions and 57 deletions

View file

@ -44,7 +44,6 @@ Battle
* Display effects description instead of attribute changes
* End the battle as soon as victory or defeat condition is detected (do not wait for the turn to end)
* Show a cooldown indicator on move action icon, if the simulation would cause the engine to overheat
* Mark action icons unavailable next turn, if if will overheat
* Any displayed info should be based on a ship copy stored in ArenaShip, and in sync with current log index (not the game state ship)
* Add engine trail effect, and sound
* Allow to skip animations, and allow no animation mode
@ -58,6 +57,7 @@ Battle
* Allow to move targetting indicator with arrow keys
* Add targetting shortcuts for "previous target", "next enemy" and "next ally"
* Area targetting should include the hotkeyed ship at best (apply exclusion and power limit), not necessarily center on it
* Fix "toggle action" targetting with simulated move not activating the action after the move
Ships models and equipments
---------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB

View file

@ -2043,6 +2043,286 @@
stdDeviation="0.32193829"
id="feGaussianBlur9015-4" />
</filter>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient5642"
id="radialGradient7427-3"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,1.8700249,0,21.900508)"
cx="359.19373"
cy="-25.506496"
fx="359.19373"
fy="-25.506496"
r="16.402095" />
<filter
inkscape:label="Evanescent"
inkscape:menu="Blurs"
inkscape:menu-tooltip="Blur the contents of objects, preserving the outline and adding progressive transparency at edges"
style="color-interpolation-filters:sRGB"
id="filter5649-3">
<feGaussianBlur
result="result6"
stdDeviation="3"
in="SourceGraphic"
id="feGaussianBlur5651-5" />
<feColorMatrix
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 "
result="result7"
in="SourceGraphic"
id="feColorMatrix5653-6" />
<feComposite
operator="in"
in="result6"
in2="result7"
id="feComposite5655-29" />
</filter>
<filter
style="color-interpolation-filters:sRGB"
inkscape:label="Digit shadow"
id="filter10663-6-1">
<feFlood
flood-opacity="0.709804"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood10653-7-27" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite10655-5-0" />
<feGaussianBlur
in="composite1"
stdDeviation="0"
result="blur"
id="feGaussianBlur10657-3-9" />
<feOffset
dx="1"
dy="1"
result="offset"
id="feOffset10659-5-3" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite10661-6-6" />
</filter>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient5642"
id="radialGradient5570"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,1.8700249,0,21.900508)"
cx="359.19373"
cy="-25.506496"
fx="359.19373"
fy="-25.506496"
r="16.402095" />
<filter
inkscape:label="Evanescent"
inkscape:menu="Blurs"
inkscape:menu-tooltip="Blur the contents of objects, preserving the outline and adding progressive transparency at edges"
style="color-interpolation-filters:sRGB"
id="filter5586">
<feGaussianBlur
result="result6"
stdDeviation="3"
in="SourceGraphic"
id="feGaussianBlur5580" />
<feColorMatrix
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 "
result="result7"
in="SourceGraphic"
id="feColorMatrix5582" />
<feComposite
operator="in"
in="result6"
in2="result7"
id="feComposite5584" />
</filter>
<filter
style="color-interpolation-filters:sRGB"
inkscape:label="Digit shadow"
id="filter5598">
<feFlood
flood-opacity="0.709804"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood5588" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite5590" />
<feGaussianBlur
in="composite1"
stdDeviation="0"
result="blur"
id="feGaussianBlur5592" />
<feOffset
dx="1"
dy="1"
result="offset"
id="feOffset5594" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite5596" />
</filter>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4953"
id="radialGradient7411-2"
gradientUnits="userSpaceOnUse"
cx="128"
cy="128"
fx="128"
fy="128"
r="110.79634" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4953"
id="radialGradient5900"
gradientUnits="userSpaceOnUse"
cx="128"
cy="128"
fx="128"
fy="128"
r="110.79634" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient5642"
id="radialGradient7427-2"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,1.8700249,0,21.900508)"
cx="359.19373"
cy="-25.506496"
fx="359.19373"
fy="-25.506496"
r="16.402095" />
<filter
inkscape:label="Evanescent"
inkscape:menu="Blurs"
inkscape:menu-tooltip="Blur the contents of objects, preserving the outline and adding progressive transparency at edges"
style="color-interpolation-filters:sRGB"
id="filter5649-36">
<feGaussianBlur
result="result6"
stdDeviation="3"
in="SourceGraphic"
id="feGaussianBlur5651-12" />
<feColorMatrix
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 "
result="result7"
in="SourceGraphic"
id="feColorMatrix5653-93" />
<feComposite
operator="in"
in="result6"
in2="result7"
id="feComposite5655-1" />
</filter>
<filter
style="color-interpolation-filters:sRGB"
inkscape:label="Digit shadow"
id="filter10663-6-9">
<feFlood
flood-opacity="0.709804"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood10653-7-4" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite10655-5-7" />
<feGaussianBlur
in="composite1"
stdDeviation="0"
result="blur"
id="feGaussianBlur10657-3-8" />
<feOffset
dx="1"
dy="1"
result="offset"
id="feOffset10659-5-4" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite10661-6-5" />
</filter>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient5642"
id="radialGradient6676"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,1.8700249,0,21.900508)"
cx="359.19373"
cy="-25.506496"
fx="359.19373"
fy="-25.506496"
r="16.402095" />
<filter
inkscape:label="Evanescent"
inkscape:menu="Blurs"
inkscape:menu-tooltip="Blur the contents of objects, preserving the outline and adding progressive transparency at edges"
style="color-interpolation-filters:sRGB"
id="filter6692">
<feGaussianBlur
result="result6"
stdDeviation="3"
in="SourceGraphic"
id="feGaussianBlur6686" />
<feColorMatrix
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 "
result="result7"
in="SourceGraphic"
id="feColorMatrix6688" />
<feComposite
operator="in"
in="result6"
in2="result7"
id="feComposite6690" />
</filter>
<filter
style="color-interpolation-filters:sRGB"
inkscape:label="Digit shadow"
id="filter6704">
<feFlood
flood-opacity="0.709804"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood6694" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite6696" />
<feGaussianBlur
in="composite1"
stdDeviation="0"
result="blur"
id="feGaussianBlur6698" />
<feOffset
dx="1"
dy="1"
result="offset"
id="feOffset6700" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite6702" />
</filter>
</defs>
<sodipodi:namedview
id="base"
@ -2051,11 +2331,11 @@
borderopacity="1"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:zoom="1.4142136"
inkscape:cx="1030.8433"
inkscape:cy="-58.928706"
inkscape:zoom="2.8284272"
inkscape:cx="553.74511"
inkscape:cy="-146.19875"
inkscape:document-units="px"
inkscape:current-layer="use5861"
inkscape:current-layer="use6422"
showgrid="false"
units="px"
showguides="true"
@ -2086,7 +2366,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -4716,42 +4996,58 @@
inkscape:export-ydpi="96"
inkscape:export-xdpi="96"
inkscape:export-filename="/home/michael/workspace/perso/spacetac/out/assets/images/battle/action-active.png"
transform="matrix(1.4676871,0,0,1.4676871,236.16704,1372.3105)"
transform="matrix(1.4676871,0,0,1.4676871,235.74578,1372.3105)"
inkscape:tile-y0="-85.964287"
inkscape:tile-x0="195"
id="use6422">
<g
inkscape:export-ydpi="96"
inkscape:export-xdpi="96"
inkscape:export-filename="/home/michael/workspace/perso/spacetac/graphics/exported/battle/actionbar/frame-fading.png"
transform="matrix(0.68134414,0,0,0.68134414,-45.404679,-33.276515)"
style="display:inline;enable-background:new"
id="use5659">
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path6765"
d="m 355.99997,-72.499939 h 99.99999 l 10.5,99.999992 H 345.49997 Z"
style="display:inline;fill:#505050;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.4595745;filter:url(#filter9715);enable-background:new" />
<rect
y="-68.999939"
x="359.49997"
height="92.999992"
width="92.999992"
id="rect6767"
style="display:inline;fill:#181c1f;fill-opacity:1;fill-rule:evenodd;stroke:#a0a0a0;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.16382979;enable-background:new" />
</g>
<use
transform="translate(0.28703373)"
style="display:inline;enable-background:new"
x="0"
y="0"
xlink:href="#g7815"
id="use9149"
xlink:href="#g7801"
id="use5661"
width="100%"
height="100%"
transform="matrix(0.68134414,0,0,0.68134414,179.47397,-935.01564)" />
<g
id="g10139">
<path
transform="matrix(0.68134414,0,0,0.68134414,-48.536808,-33.276515)"
style="fill:#1e282b;fill-opacity:1;fill-rule:evenodd;stroke:#bb621e;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter5649)"
d="M 346.99998,-48.74995 V 4.000051 h 20.5 l 9,-58.000001 z"
id="path7715"
inkscape:connector-curvature="0"
inkscape:export-filename="/home/michael/workspace/perso/spacetac/graphics/exported/battle/actionbar/consumption-fading.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:21.33333397px;line-height:25px;font-family:DAGGERSQUARE;-inkscape-font-specification:DAGGERSQUARE;letter-spacing:0px;word-spacing:0px;display:inline;fill:#ffdd4b;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter10663-6);enable-background:new"
x="9.1257"
y="53.499992"
id="text7723"
transform="matrix(0.68134414,0,0,0.68134414,185.87963,-82.673919)"><tspan
sodipodi:role="line"
id="tspan7721"
x="9.1257"
y="53.499992">3</tspan></text>
</g>
height="100%" />
<use
transform="translate(0.28703373)"
style="display:inline;enable-background:new"
x="0"
y="0"
xlink:href="#path7813"
id="use5663"
width="100%"
height="100%" />
<use
transform="translate(0.28706073,1.5565435e-6)"
style="display:inline;enable-background:new"
x="0"
y="0"
xlink:href="#g7666"
id="use5545"
width="100%"
height="100%" />
</g>
<g
id="g6108"

Before

Width:  |  Height:  |  Size: 312 KiB

After

Width:  |  Height:  |  Size: 320 KiB

View file

@ -24,7 +24,7 @@ module TK.SpaceTac {
ship.values.power.set(2);
expect(action.checkCannotBeApplied(ship)).toBe("not enough power");
});
})
it("check if equipment can be used with overheat", function () {
let equipment = new Equipment();
@ -64,7 +64,7 @@ module TK.SpaceTac {
expect(action.checkCannotBeApplied(ship)).toBe(null);
expect(action.getCooldownDuration()).toBe(0);
expect(action.getCooldownDuration(true)).toBe(3);
});
})
it("wears down equipment and power generators", function () {
let ship = new Ship();
@ -81,6 +81,25 @@ module TK.SpaceTac {
expect(power.wear).toBe(1);
expect(equipment.wear).toBe(1);
});
})
it("guesses targetting mode", function () {
let ship = new Ship();
let action = new BaseAction("test", "Test");
expect(action.getTargettingMode(ship)).toEqual(ActionTargettingMode.SELF_CONFIRM);
action = new BaseAction("test", "Test");
spyOn(action, "getRangeRadius").and.returnValue(50);
expect(action.getTargettingMode(ship)).toEqual(ActionTargettingMode.SHIP);
action = new BaseAction("test", "Test");
spyOn(action, "getRangeRadius").and.returnValue(50);
spyOn(action, "getBlastRadius").and.returnValue(20);
expect(action.getTargettingMode(ship)).toEqual(ActionTargettingMode.SPACE);
action = new BaseAction("test", "Test");
spyOn(action, "getBlastRadius").and.returnValue(20);
expect(action.getTargettingMode(ship)).toEqual(ActionTargettingMode.SURROUNDINGS);
})
});
}

View file

@ -12,7 +12,9 @@ module TK.SpaceTac {
// Apply on one selected ship
SHIP,
// Apply on a space area
SPACE
SPACE,
// Apply on the ship owning the action, but has an effect on surroundings
SURROUNDINGS
}
/**
@ -31,7 +33,7 @@ module TK.SpaceTac {
equipment: Equipment | null
// Create the action
constructor(code: string, name: string, equipment: Equipment | null = null) {
constructor(code = "nothing", name = "Idle", equipment: Equipment | null = null) {
this.code = code;
this.name = name;
this.equipment = equipment;
@ -48,9 +50,16 @@ module TK.SpaceTac {
* Get the targetting mode
*/
getTargettingMode(ship: Ship): ActionTargettingMode {
if (this.getBlastRadius(ship)) {
return ActionTargettingMode.SPACE;
} else if (this.getRangeRadius(ship)) {
let blast = this.getBlastRadius(ship);
let range = this.getRangeRadius(ship);
if (blast) {
if (range) {
return ActionTargettingMode.SPACE;
} else {
return ActionTargettingMode.SURROUNDINGS;
}
} else if (range) {
return ActionTargettingMode.SHIP;
} else {
return ActionTargettingMode.SELF_CONFIRM;

View file

@ -28,6 +28,14 @@ module TK.SpaceTac {
this.effects = effects;
}
getTargettingMode(ship: Ship): ActionTargettingMode {
if (this.activated) {
return ActionTargettingMode.SELF;
} else {
return super.getTargettingMode(ship);
}
}
getActionPointsUsage(ship: Ship, target: Target | null): number {
return this.activated ? 0 : this.power;
}

View file

@ -101,8 +101,8 @@ module TK.SpaceTac.UI {
this.interactive = interactive;
this.battleview.animations.setVisible(this.icon_waiting, !this.interactive, 100);
this.battleview.animations.setVisible(this.power, interactive, 100, 1, 0);
this.battleview.animations.setVisible(this.actions, interactive, 100, 1, 0);
this.battleview.animations.setVisible(this.power, interactive, 100, 1, 0.3);
this.battleview.animations.setVisible(this.actions, interactive, 100, 1, 0.3);
}
}

View file

@ -27,34 +27,58 @@ module TK.SpaceTac.UI.Specs {
let action = nn(TestTools.addWeapon(ship, 50, 3).action);
let icon = new ActionIcon(bar, ship, action, 0);
expect(icon.container.name).toBe("battle-actionbar-frame-enabled", "5/5");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-enabled", "5/5");
expect(icon.img_power.visible).toBe(true, "5/5");
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-enabled", "5/5");
icon.refresh(null, 1);
expect(icon.container.name).toBe("battle-actionbar-frame-enabled", "4/5");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-enabled", "4/5");
expect(icon.img_power.visible).toBe(true, "4/5");
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-enabled", "4/5");
icon.refresh(null, 4);
expect(icon.img_power.name).toBe("battle-actionbar-consumption-fading", "1/5");
expect(icon.container.name).toBe("battle-actionbar-frame-fading", "1/5");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-enabled", "1/5");
expect(icon.img_power.visible).toBe(true, "1/5");
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-enabled", "1/5");
ship.setValue("power", 2);
icon.refresh();
expect(icon.container.name).toBe("battle-actionbar-frame-disabled", "2/2");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-disabled", "2/2");
expect(icon.img_power.visible).toBe(true, "2/2");
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-disabled", "2/2");
icon.refresh(null, 6);
expect(icon.container.name).toBe("battle-actionbar-frame-disabled", "0/2");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-disabled", "0/2");
expect(icon.img_power.visible).toBe(true, "0/2");
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-disabled", "0/2");
})
it("displays toggle state", function () {
let bar = testgame.battleview.action_bar;
let ship = new Ship();
TestTools.setShipAP(ship, 5);
let equipment = new Equipment(SlotType.Weapon);
ship.addSlot(SlotType.Weapon).attach(equipment);
let action = new ToggleAction(equipment, 2);
equipment.action = action;
let icon = new ActionIcon(bar, ship, action, 0);
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-enabled", "initial");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-enabled", "initial");
expect(icon.img_sticky.name).toBe("battle-actionbar-sticky-untoggled", "initial");
expect(icon.img_sticky.visible).toBe(true, "initial");
action.activated = true;
icon.refresh();
expect(icon.img_bottom.name).toBe("battle-actionbar-bottom-toggled", "initial");
expect(icon.img_power.name).toBe("battle-actionbar-consumption-toggled", "initial");
expect(icon.img_sticky.name).toBe("battle-actionbar-sticky-toggled", "initial");
expect(icon.img_sticky.visible).toBe(true, "initial");
})
it("displays overheat/cooldown", function () {
@ -62,7 +86,20 @@ module TK.SpaceTac.UI.Specs {
})
it("displays currently targetting", function () {
testgame.battleview.animations.setImmediate();
let bar = testgame.battleview.action_bar;
let ship = new Ship();
TestTools.setShipAP(ship, 5);
let action = nn(TestTools.addWeapon(ship, 50, 3).action);
let icon = new ActionIcon(bar, ship, action, 0);
expect(icon.img_targetting.visible).toBe(false, "initial");
icon.refresh(action);
expect(icon.img_targetting.visible).toBe(true, "selected");
icon.refresh(new BaseAction("other", "Other action"));
expect(icon.img_targetting.visible).toBe(false, "other");
})
});
}

View file

@ -157,8 +157,11 @@ module TK.SpaceTac.UI {
refresh(used: BaseAction | null = null, power_consumption = 0): void {
let disabled = bool(this.action.checkCannotBeApplied(this.ship));
let selected = (used === this.action);
let fading = bool(this.action.checkCannotBeApplied(this.ship, this.ship.getValue("power") - power_consumption));
let toggled = (this.action instanceof ToggleAction) && this.action.activated;
let fading = bool(this.action.checkCannotBeApplied(this.ship, this.ship.getValue("power") - power_consumption));
if (this.action == used && this.action.cooldown.willOverheat()) {
fading = true;
}
// inputs
if (disabled != this.disabled) {
@ -166,8 +169,14 @@ module TK.SpaceTac.UI {
}
// frame
if (disabled != this.disabled) {
let name = disabled ? "battle-actionbar-frame-disabled" : "battle-actionbar-frame-enabled";
if (disabled != this.disabled || fading != this.fading) {
let name = "battle-actionbar-frame-enabled";
if (disabled) {
name = "battle-actionbar-frame-disabled";
} else if (fading) {
name = "battle-actionbar-frame-fading";
}
let info = this.view.getImageInfo(name);
this.container.name = name;
this.container.loadTexture(info.key);
@ -194,7 +203,7 @@ module TK.SpaceTac.UI {
}
// left
if (disabled != this.disabled || selected != this.selected || fading != this.fading || toggled != this.toggled) {
if (disabled != this.disabled || selected != this.selected || toggled != this.toggled) {
let power = this.action.getActionPointsUsage(this.ship, null);
this.img_power.visible = toggled || (power > 0);
this.text_power.text = `${power}`;
@ -203,8 +212,6 @@ module TK.SpaceTac.UI {
this.view.changeImage(this.img_power, "battle-actionbar-consumption-disabled");
} else if (toggled) {
this.view.changeImage(this.img_power, "battle-actionbar-consumption-toggled");
} else if (fading) {
this.view.changeImage(this.img_power, "battle-actionbar-consumption-fading");
} else if (selected) {
this.view.changeImage(this.img_power, "battle-actionbar-consumption-targetting");
} else {

View file

@ -39,7 +39,7 @@ module TK.SpaceTac.UI.Specs {
targetting.drawPart(part, true, null);
expect(drawvector).toHaveBeenCalledTimes(3);
expect(drawvector).toHaveBeenCalledWith(0xe09c47, 10, 20, 50, 30, 12);
});
})
it("updates impact indicators on ships inside the blast radius", function () {
let targetting = newTargetting();
@ -75,7 +75,7 @@ module TK.SpaceTac.UI.Specs {
expect(collect).toHaveBeenCalledTimes(3);
expect(collect).toHaveBeenCalledWith(new Target(20, 12), 50, true);
expect(targetting.fire_impact.visible).toBe(false);
});
})
it("updates graphics from simulation", function () {
let targetting = newTargetting();
@ -114,6 +114,39 @@ module TK.SpaceTac.UI.Specs {
expect(targetting.move_ghost.visible).toBe(true);
expect(targetting.move_ghost.position).toEqual(jasmine.objectContaining({ x: 80, y: 20 }));
expect(targetting.move_ghost.rotation).toBeCloseTo(0.534594, 5);
});
})
it("snaps on ships according to targetting mode", function () {
let targetting = newTargetting();
let playing_ship = nn(testgame.battleview.battle.playing_ship);
let action = TestTools.addWeapon(playing_ship).action;
let ship1 = testgame.battleview.battle.play_order[1];
let ship2 = testgame.battleview.battle.play_order[2];
ship1.setArenaPosition(8000, 50);
ship2.setArenaPosition(8000, 230);
targetting.setAction(action, ActionTargettingMode.SPACE);
targetting.setTargetFromLocation({ x: 8000, y: 60 });
expect(targetting.target).toEqual(Target.newFromLocation(8000, 60), "space");
targetting.setAction(action, ActionTargettingMode.SHIP);
targetting.setTargetFromLocation({ x: 8000, y: 60 });
expect(targetting.target).toEqual(Target.newFromShip(ship1), "ship 1");
targetting.setTargetFromLocation({ x: 8100, y: 200 });
expect(targetting.target).toEqual(Target.newFromShip(ship2), "ship 2");
targetting.setAction(action, ActionTargettingMode.SURROUNDINGS);
targetting.setTargetFromLocation({ x: 8000, y: 60 });
expect(targetting.target).toEqual(Target.newFromLocation(8000, 60), "surroundings 1");
targetting.setTargetFromLocation({ x: playing_ship.arena_x + 10, y: playing_ship.arena_y - 20 });
expect(targetting.target).toEqual(Target.newFromShip(playing_ship), "surroundings 2");
targetting.setAction(action, ActionTargettingMode.SELF);
targetting.setTargetFromLocation({ x: 8000, y: 60 });
expect(targetting.target).toEqual(Target.newFromShip(playing_ship), "self 1");
targetting.setTargetFromLocation({ x: 0, y: 0 });
expect(targetting.target).toEqual(Target.newFromShip(playing_ship), "self 2");
})
});
}

View file

@ -286,6 +286,12 @@ module TK.SpaceTac.UI {
this.setTarget(Target.newFromShip(nearest ? nearest : this.ship));
} else if (this.mode == ActionTargettingMode.SPACE) {
this.setTarget(Target.newFromLocation(location.x, location.y));
} else if (this.mode == ActionTargettingMode.SURROUNDINGS) {
if (arenaDistance(this.ship.location, location) < 50) {
this.setTarget(Target.newFromShip(this.ship));
} else {
this.setTarget(Target.newFromLocation(location.x, location.y));
}
} else {
this.setTarget(Target.newFromShip(this.ship));
}

View file

@ -23,12 +23,22 @@ module TK.SpaceTac.UI {
* This is a wrapper around phaser's tweens.
*/
export class Animations {
private tweens: Phaser.TweenManager;
private tweens: Phaser.TweenManager
private immediate = false
constructor(tweens: Phaser.TweenManager) {
this.tweens = tweens;
}
/**
* Set all future animations to be immediate (and synchronous)
*
* This is mostly useful in tests
*/
setImmediate(immediate = true): void {
this.immediate = immediate;
}
/**
* Create a tween on an object.
*
@ -63,7 +73,7 @@ module TK.SpaceTac.UI {
obj.visible = true;
}
if (duration) {
if (duration && !this.immediate) {
let tween = this.createTween(obj);
tween.to({ alpha: alpha }, duration);
if (obj.input) {
@ -96,7 +106,7 @@ module TK.SpaceTac.UI {
obj.input.enabled = false;
}
if (duration) {
if (duration && !this.immediate) {
let tween = this.createTween(obj);
tween.to({ alpha: alpha }, duration);
if (alpha == 0) {