Skip to content

Commit

Permalink
v0.9.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
paissaheavyindustries committed Jan 25, 2023
1 parent 6bc00e1 commit e3291ca
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 20 deletions.
83 changes: 80 additions & 3 deletions Telesto/Doodle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Telesto.Interop;
using Vector3 = System.Numerics.Vector3;
using Vector4 = System.Numerics.Vector4;

Expand All @@ -24,7 +26,9 @@ internal enum CoordinateTypeEnum
{
Screen,
World,
Entity
Entity,
Doodle,
Waymark
}


Expand Down Expand Up @@ -83,8 +87,30 @@ internal Vector3 UnadjustedPosition(Plugin p)
);
}
break;
case CoordinateTypeEnum.Doodle:
string[] spl = name.Split("/");
Doodle d = p.GetDoodleByName(spl[0]);
if (d != null)
{
Coordinate c = d.GetCoordinateByName(spl.Length > 1 ? spl[1] : "");
if (c != null)
{
return c.UnadjustedPosition(p);
}
}
return new Vector3();
case CoordinateTypeEnum.Waymark:
Waymark wm = p.GetWaymarkByName(name);
if (wm != null && wm.Active == true)
{
return new Vector3(
wm.X_Float,
wm.Y_Float,
wm.Z_Float
);
}
return new Vector3();
}

}

internal void RefreshVector(Plugin p)
Expand Down Expand Up @@ -132,11 +158,51 @@ internal void RefreshVector(Plugin p)
);
}
break;
case CoordinateTypeEnum.Doodle:
string[] spl = name.Split("/");
Doodle d = p.GetDoodleByName(spl[0]);
if (d != null)
{
Coordinate c = d.GetCoordinateByName(spl.Length > 1 ? spl[1] : "");
if (c != null)
{
Vector3 uap = c.UnadjustedPosition(p);
cp = p.TranslateToScreen(
uap.X,
uap.Y,
uap.Z
);
}
else
{
cp = new Vector3();
}
}
else
{
cp = new Vector3();
}
break;
case CoordinateTypeEnum.Waymark:
Waymark wm = p.GetWaymarkByName(name);
if (wm != null && wm.Active == true)
{
cp = p.TranslateToScreen(
wm.X_Float,
wm.Y_Float,
wm.Z_Float
);
}
else
{
cp = new Vector3();
}
break;
}
}

internal void Initialize(Dictionary<string, object> d)
{
{
string coords = (d.ContainsKey("coords") == true) ? d["coords"].ToString() : "screen";
switch (coords)
{
Expand All @@ -146,6 +212,12 @@ internal void Initialize(Dictionary<string, object> d)
case "entity":
ct = CoordinateTypeEnum.Entity;
break;
case "doodle":
ct = CoordinateTypeEnum.Doodle;
break;
case "waymark":
ct = CoordinateTypeEnum.Waymark;
break;
default:
ct = CoordinateTypeEnum.Screen;
break;
Expand Down Expand Up @@ -191,6 +263,8 @@ internal enum ExpiryTypeEnum
internal string B { get; set; }
internal string A { get; set; }

abstract internal Coordinate GetCoordinateByName(string id);

internal virtual void Initialize(Dictionary<string, object> d)
{
Name = d["name"].ToString();
Expand Down Expand Up @@ -247,6 +321,9 @@ internal static Doodle Deserialize(Dictionary<string, object> d)
case "arrow":
doo = new Doodles.Arrow();
break;
case "beam":
doo = new Doodles.Beam();
break;
}
if (doo != null)
{
Expand Down
17 changes: 12 additions & 5 deletions Telesto/Doodles/Arrow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ internal enum CoordSystemEnum
internal CoordSystemEnum csys { get; set; }
internal Coordinate from { get; set; }
internal Coordinate to { get; set; }
internal float radiuschonk { get; set; }
internal float linechonk { get; set; }
internal string Radius { get; set; }
internal string Thickness { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "from": return from;
case "to": return to;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Thickness = (d.ContainsKey("thickness") == true) ? d["thickness"].ToString() : "1";
Thickness = (d.ContainsKey("thickness") == true) ? d["thickness"].ToString() : "3";
from = new Coordinate();
if (d.ContainsKey("from") == true)
{
Expand Down Expand Up @@ -74,7 +82,6 @@ internal override void Draw()
Vector3 tf = from.UnadjustedPosition(p);
Vector3 tt = to.UnadjustedPosition(p);
float distance = Vector3.Distance(tf, tt);
double anglexy = Math.Atan2(tf.Y - tt.Y, tf.X - tt.X);
double anglexz = Math.Atan2(tf.Z - tt.Z, tf.X - tt.X);
float head = distance * 0.7f;
float width = distance / 20.0f;
Expand All @@ -99,7 +106,7 @@ internal override void Draw()
ImGui.GetWindowDrawList().PathStroke(
ImGui.GetColorU32(col),
ImDrawFlags.None,
3.0f
linechonk
);
}
}
Expand Down
121 changes: 121 additions & 0 deletions Telesto/Doodles/Beam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Vector2 = System.Numerics.Vector2;
using Vector3 = System.Numerics.Vector3;

namespace Telesto.Doodles
{

internal class Beam : Doodle
{

internal enum CoordSystemEnum
{
Screen,
World
}

internal CoordSystemEnum csys { get; set; }
internal Coordinate from { get; set; }
internal Coordinate at { get; set; }
internal float linechonk { get; set; }
internal string Thickness { get; set; }
internal float widthchonk { get; set; }
internal string Width { get; set; }
internal float lengthchonk { get; set; }
internal string Length { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "from": return from;
case "at": return at;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Thickness = (d.ContainsKey("thickness") == true) ? d["thickness"].ToString() : "3";
Width = (d.ContainsKey("width") == true) ? d["width"].ToString() : "1";
Length = (d.ContainsKey("length") == true) ? d["length"].ToString() : "1";
from = new Coordinate();
if (d.ContainsKey("from") == true)
{
from.Initialize((Dictionary<string, object>)d["from"]);
}
at = new Coordinate();
if (d.ContainsKey("at") == true)
{
at.Initialize((Dictionary<string, object>)d["at"]);
}
string csystem = (d.ContainsKey("system") == true) ? d["system"].ToString() : "screen";
switch (csystem.ToLower())
{
case "world":
csys = CoordSystemEnum.World;
break;
default:
csys = CoordSystemEnum.Screen;
break;
}
}

internal override bool Update()
{
if (base.Update() == false)
{
return false;
}
from.RefreshVector(p);
at.RefreshVector(p);
linechonk = (float)p.EvaluateNumericExpression(Thickness);
widthchonk = (float)p.EvaluateNumericExpression(Width);
lengthchonk = (float)p.EvaluateNumericExpression(Length);
return true;
}

internal override void Draw()
{
if (csys == CoordSystemEnum.Screen)
{
// ehh maybe some day
}
else
{
Vector3 tf = from.UnadjustedPosition(p);
Vector3 tt = at.UnadjustedPosition(p);
float distance = Vector3.Distance(tf, tt);
float length;
length = lengthchonk < 0.0 ? distance : lengthchonk;
double anglexz = Math.Atan2(tf.Z - tt.Z, tf.X - tt.X);
float mul = length / distance;
Vector3 tx;
List<Vector3> verts = new List<Vector3>();
verts.Add(tf);
verts.Add(tx = new Vector3(tf.X + (float)(Math.Cos(anglexz + (Math.PI / 2.0)) * widthchonk), tf.Y, tf.Z + (float)(Math.Sin(anglexz + (Math.PI / 2.0)) * widthchonk)));
verts.Add(tx = new Vector3(tx.X + (float)(Math.Cos(anglexz + Math.PI) * length), tx.Y + ((tt.Y - tf.Y) * mul), tx.Z + (float)(Math.Sin(anglexz + Math.PI) * length)));
verts.Add(tx = new Vector3(tx.X - (float)(Math.Cos(anglexz + (Math.PI / 2.0)) * widthchonk * 2), tx.Y, tx.Z - (float)(Math.Sin(anglexz + (Math.PI / 2.0)) * widthchonk * 2)));
tx = tf;
verts.Add(tx = new Vector3(tf.X - (float)(Math.Cos(anglexz + (Math.PI / 2.0)) * widthchonk), tf.Y, tf.Z - (float)(Math.Sin(anglexz + (Math.PI / 2.0)) * widthchonk)));
verts.Add(tf);
foreach (Vector3 v in verts)
{
Vector3 vx = p.TranslateToScreen(v.X, v.Y, v.Z);
ImGui.GetWindowDrawList().PathLineTo(new Vector2(vx.X, vx.Y));
}
ImGui.GetWindowDrawList().PathStroke(
ImGui.GetColorU32(col),
ImDrawFlags.None,
linechonk
);
}
}

}

}
9 changes: 9 additions & 0 deletions Telesto/Doodles/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ internal enum CoordSystemEnum
internal string Thickness { get; set; }
internal bool filled { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "position": return position;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Expand Down
10 changes: 10 additions & 0 deletions Telesto/Doodles/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ internal class Line : Doodle
internal float chonkiness { get; set; }
internal string Thickness { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "start": return start;
case "end": return end;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Expand Down
10 changes: 10 additions & 0 deletions Telesto/Doodles/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ internal enum CoordSystemEnum
internal string Thickness { get; set; }
internal bool filled { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "pos1": return pos1;
case "pos2": return pos2;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Expand Down
9 changes: 9 additions & 0 deletions Telesto/Doodles/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ internal class Text : Doodle
internal float chonkiness { get; set; }
internal string Size { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "position": return position;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Expand Down
9 changes: 9 additions & 0 deletions Telesto/Doodles/Waymark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ internal class Waymark : Doodle

internal Coordinate position { get; set; }

internal override Coordinate GetCoordinateByName(string id)
{
switch (id.ToLower())
{
default:
case "position": return position;
}
}

internal override void Initialize(Dictionary<string, object> d)
{
base.Initialize(d);
Expand Down
Loading

0 comments on commit e3291ca

Please sign in to comment.