Skip to content

Commit

Permalink
Merge pull request #959 from baaron4/text-decoration
Browse files Browse the repository at this point in the history
Text decoration
  • Loading branch information
EliphasNUIT authored Jan 9, 2025
2 parents 9615073 + fe2438a commit 2944cbc
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 55 deletions.
60 changes: 40 additions & 20 deletions GW2EIBuilders/Resources/JS/CR-JS/animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Animator {
this.skillMechanicActorData = [];
this.actorOrientationData = new Map();
this.backgroundActorData = [];
this.screenSpaceActorData = [];
this.backgroundImages = [];
this.selectedActor = null;
// animation
Expand Down Expand Up @@ -215,40 +216,43 @@ class Animator {
let MetadataClass = null;
switch (metadata.type) {
case "ActorOrientation":
MetadataClass = ActorOrientationDecorationMetadata;
MetadataClass = ActorOrientationMetadata;
break;
case "Circle":
MetadataClass = CircleDecorationMetadata;
MetadataClass = CircleMetadata;
break;
case "Doughnut":
MetadataClass = DoughnutDecorationMetadata;
MetadataClass = DoughnutMetadata;
break;
case "Line":
MetadataClass = LineDecorationMetadata;
MetadataClass = LineMetadata;
break;
case "Pie":
MetadataClass = PieDecorationMetadata;
MetadataClass = PieMetadata;
break;
case "Rectangle":
MetadataClass = RectangleDecorationMetadata;
MetadataClass = RectangleMetadata;
break;
case "ProgressBar":
MetadataClass = ProgressBarDecorationMetadata;
MetadataClass = ProgressBarMetadata;
break;
case "BackgroundIconDecoration":
MetadataClass = IconDecorationMetadata;
case "BackgroundIcon":
MetadataClass = IconMetadata;
break;
case "IconDecoration":
MetadataClass = IconDecorationMetadata;
case "Icon":
MetadataClass = IconMetadata;
break;
case "IconOverheadDecoration":
MetadataClass = IconOverheadDecorationMetadata;
case "IconOverhead":
MetadataClass = IconOverheadMetadata;
break;
case "OverheadProgressBar":
MetadataClass = OverheadProgressBarDecorationMetadata;
MetadataClass = OverheadProgressBarMetadata;
break;
case "MovingPlatform":
MetadataClass = MovingPlatformDecorationMetadata;
MetadataClass = MovingPlatformMetadata;
break;
case "Text":
MetadataClass = TextMetadata;
break;
default:
throw "Unknown decoration type " + metadata.type;
Expand Down Expand Up @@ -305,7 +309,7 @@ class Animator {
case "MovingPlatform":
this.backgroundActorData.push(new MovingPlatformDrawable(decorationRendering));
break;
case "BackgroundIconDecoration":
case "BackgroundIcon":
this.backgroundActorData.push(new BackgroundIconMechanicDrawable(decorationRendering));
break;
default:
Expand All @@ -314,6 +318,13 @@ class Animator {
} else {
let DecorationClass;
switch (decorationRendering.type) {
case "Text":
if (decorationRendering.connectedTo.isScreenSpace) {
this.screenSpaceActorData.push(new TextDrawable(decorationRendering));
continue;
}
DecorationClass = TextDrawable;
break;
case "Circle":
DecorationClass = CircleMechanicDrawable;
break;
Expand All @@ -332,19 +343,19 @@ class Animator {
case "Line":
DecorationClass = LineMechanicDrawable;
break;
case "IconDecoration":
case "Icon":
DecorationClass = IconMechanicDrawable;
break;
case "IconOverheadDecoration":
case "IconOverhead":
this.overheadActorData.push(new IconOverheadMechanicDrawable(decorationRendering));
continue;
case "OverheadProgressBar":
this.overheadActorData.push(new OverheadProgressBarMechanicDrawable(decorationRendering));
continue;
case "SquadMarkerDecoration":
case "SquadMarker":
this.squadMarkerData.push(new IconMechanicDrawable(decorationRendering));
continue;
case "OverheadSquadMarkerDecoration":
case "OverheadSquadMarker":
this.overheadSquadMarkerData.push(new IconOverheadMechanicDrawable(decorationRendering));
continue;
default:
Expand Down Expand Up @@ -969,6 +980,15 @@ class Animator {
this.overheadSquadMarkerData[i].draw();
}
}
ctx.save();
{
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Screen space actors
for (let i = 0; i < animator.screenSpaceActorData.length; i++) {
animator.screenSpaceActorData[i].draw();
}
}
ctx.restore()
}
//ctx.restore();
}
Expand Down
91 changes: 72 additions & 19 deletions GW2EIBuilders/Resources/JS/CR-JS/decorations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,56 @@
/*global animator, ToRadians, overheadAnimationFrame, maxOverheadAnimationFrame, facingIcon, animateCanvas, noUpdateTime, SkillDecorationCategory*/
"use strict";

class GenericDecorationMetadata {
class GenericMetadata {
constructor(params) {

}
}

class GenericAttachedDecorationMetadata extends GenericDecorationMetadata{
class TextMetadata extends GenericMetadata{
constructor(params) {
super(params);
this.color = params.color;
this.backgroundColor = params.backgroundColor;
}
}

class ActorOrientationDecorationMetadata extends GenericAttachedDecorationMetadata {
class GenericAttachedMetadata extends GenericMetadata{
constructor(params) {
super(params);
}
}

class FormDecorationMetadata extends GenericAttachedDecorationMetadata {
class ActorOrientationMetadata extends GenericAttachedMetadata {
constructor(params) {
super(params);
}
}

class FormMetadata extends GenericAttachedMetadata {
constructor(params) {
super(params);
this.color = params.color;
}
}

class CircleDecorationMetadata extends FormDecorationMetadata {
class CircleMetadata extends FormMetadata {
constructor(params) {
super(params);
this.radius = InchToPixel * params.radius;
this.minRadius = InchToPixel * params.minRadius;
}
}

class DoughnutDecorationMetadata extends FormDecorationMetadata {
class DoughnutMetadata extends FormMetadata {
constructor(params) {
super(params);
this.outerRadius = InchToPixel * params.outerRadius;
this.innerRadius = InchToPixel * params.innerRadius;
}
}

class LineDecorationMetadata extends FormDecorationMetadata {
class LineMetadata extends FormMetadata {
constructor(params) {
super(params);
this.thickness = params.thickness;
Expand All @@ -56,7 +64,7 @@ class LineDecorationMetadata extends FormDecorationMetadata {
}
}

class PieDecorationMetadata extends CircleDecorationMetadata {
class PieMetadata extends CircleMetadata {
constructor(params) {
super(params);
this.openingAngle = params.openingAngle;
Expand All @@ -65,30 +73,30 @@ class PieDecorationMetadata extends CircleDecorationMetadata {
}
}

class RectangleDecorationMetadata extends FormDecorationMetadata {
class RectangleMetadata extends FormMetadata {
constructor(params) {
super(params);
this.width = InchToPixel * params.width;
this.height = InchToPixel * params.height;
}
}

class ProgressBarDecorationMetadata extends RectangleDecorationMetadata {
class ProgressBarMetadata extends RectangleMetadata {
constructor(params) {
super(params);
this.secondaryColor = params.secondaryColor;
}
}

class OverheadProgressBarDecorationMetadata extends ProgressBarDecorationMetadata {
class OverheadProgressBarMetadata extends ProgressBarMetadata {
constructor(params) {
super(params);
this.pixelWidth = params.pixelWidth;
this.pixelHeight = params.pixelHeight;
}
}

class GenericIconDecorationMetadata extends GenericAttachedDecorationMetadata{
class GenericIconMetadata extends GenericAttachedMetadata{
constructor(params) {
super(params);
this.imageUrl = params.image;
Expand All @@ -100,32 +108,32 @@ class GenericIconDecorationMetadata extends GenericAttachedDecorationMetadata{
}
}

class BackgroundIconDecorationMetadata extends GenericIconDecorationMetadata {
class BackgroundIconMetadata extends GenericIconMetadata {
constructor(params) {
super(params);
}
}

class IconDecorationMetadata extends GenericIconDecorationMetadata {
class IconMetadata extends GenericIconMetadata {
constructor(params) {
super(params);
this.opacity = params.opacity;
}
}

class IconOverheadDecorationMetadata extends IconDecorationMetadata {
class IconOverheadMetadata extends IconMetadata {
constructor(params) {
super(params);
}
}

class BackgroundDecorationMetadata extends GenericDecorationMetadata{
class BackgroundMetadata extends GenericMetadata{
constructor(params) {
super(params);
}
}

class MovingPlatformDecorationMetadata extends BackgroundDecorationMetadata{
class MovingPlatformMetadata extends BackgroundMetadata{
constructor(params, ) {
super(params);
this.imageUrl = params.image;
Expand Down Expand Up @@ -195,9 +203,10 @@ function interpolatedPositionFetcher(connection, master) {
}

function staticPositionFetcher(connection, master) {
const factor = connection.isScreenSpace ? resolutionMultiplier : 1;
return {
x: connection.position[0],
y: connection.position[1]
x: factor * connection.position[0],
y: factor * connection.position[1]
};
}

Expand Down Expand Up @@ -1257,3 +1266,47 @@ class IconOverheadMechanicDrawable extends IconMechanicDrawable {
return offset;
}
}

//

class TextDrawable extends MechanicDrawable {
constructor(params) {
super(params);
this.text = params.text;
const bold = !!params.bold;
const fontSize = params.fontSize * resolutionMultiplier + "px";
const fontType = params.fontType || "Comic Sans MS";
this.font = (bold ? "bold " : "") + fontSize + " " + fontType;
}
get color() {
return this.metadata.color;
}
get backgroundColor() {
return this.metadata.backgroundColor;
}

draw() {
if (!this.canDraw()) {
return;
}
const pos = this.getPosition();
const rot = this.getRotation();
if (pos === null || rot === null) {
return;
}

const ctx = animator.mainContext;
ctx.save();
this.moveContext(ctx, pos, rot);
const normalizedRot = Math.abs((ToRadians(rot + this.rotationOffset) / Math.PI) % 2);
if (0.5 < normalizedRot && normalizedRot < 1.5) {
// make sure the text remains upright
ctx.rotate(-ToRadians(180));
}
ctx.font = this.font;
ctx.fillStyle = this.color;
ctx.textAlign = "center";
ctx.fillText(this.text, 0, 0);
ctx.restore();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace GW2EIEvtcParser.EIData;
[JsonDerivedType(typeof(PositionConnectorDescription))]
[JsonDerivedType(typeof(InterpolationConnectorDescription))]
[JsonDerivedType(typeof(AgentConnectorDescription))]
[JsonDerivedType(typeof(ScreenSpaceConnectorDescription))]
public abstract class ConnectorDescription
{
protected ConnectorDescription(Connector connector, CombatReplayMap map, ParsedEvtcLog log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public abstract class GeographicalConnectorDescription : ConnectorDescription
{
public readonly IReadOnlyList<float>? Offset;
public readonly bool OffsetAfterRotation;
public readonly bool IsScreenSpace;
internal GeographicalConnectorDescription(GeographicalConnector connector, CombatReplayMap map, ParsedEvtcLog log) : base(connector, map, log)
{
if (connector.Offset.HasValue)
Expand All @@ -14,5 +15,6 @@ internal GeographicalConnectorDescription(GeographicalConnector connector, Comba
connector.InvertYOffset ? -connector.Offset.Value.Y : connector.Offset.Value.Y,
];
}
IsScreenSpace = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace GW2EIEvtcParser.EIData;

public class ScreenSpaceConnectorDescription : ConnectorDescription
{
public readonly IReadOnlyList<float> Position;
public readonly bool IsScreenSpace;
internal ScreenSpaceConnectorDescription(ScreenSpaceConnector connector, CombatReplayMap map, ParsedEvtcLog log) : base(connector, map, log)
{
IsScreenSpace = true;
Position = [connector.Position.X, connector.Position.Y];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace GW2EIEvtcParser.EIData;
[JsonDerivedType(typeof(RectangleDecorationMetadataDescription))]
[JsonDerivedType(typeof(ProgressBarDecorationMetadataDescription))]
[JsonDerivedType(typeof(OverheadProgressBarDecorationMetadataDescription))]
[JsonDerivedType(typeof(TextDecorationMetadataDescription))]
public abstract class CombatReplayDecorationMetadataDescription : CombatReplayDescription
{
internal CombatReplayDecorationMetadataDescription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class BackgroundIconDecorationMetadataDescription : ImageDecorationMetada

internal BackgroundIconDecorationMetadataDescription(BackgroundIconDecorationMetadata decoration) : base(decoration)
{
Type = "BackgroundIconDecoration";
Type = "BackgroundIcon";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class IconDecorationMetadataDescription : ImageDecorationMetadataDescript

internal IconDecorationMetadataDescription(IconDecorationMetadata decoration) : base(decoration)
{
Type = "IconDecoration";
Type = "Icon";
Opacity = decoration.Opacity;
}
}
Loading

0 comments on commit 2944cbc

Please sign in to comment.