Skip to content

Commit e926e92

Browse files
committed
[CX-2314] Add sparks to pantograph
1 parent 3ded65c commit e926e92

File tree

17 files changed

+179
-33
lines changed

17 files changed

+179
-33
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,11 @@ slt --speed 5
5252
```
5353

5454
https://user-images.githubusercontent.com/10553406/173188082-302cf14e-e49f-414a-adaf-af715fa9128c.mov
55+
56+
57+
A complete list of supported options can be displayed by passing the `--help`
58+
option:
59+
60+
```
61+
slt --help
62+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bbb b
2+
b bbb
3+
b
4+
b bbb
5+
bbbbb
6+
bbbb
7+
bbbbbb
8+
bbbbbb
9+
bbb
10+
bbb bbb
11+
b bbbbb
12+
bbb
13+
bbb b
14+
b bbb
15+
b

Slt/Art/Etc/Outline/Sparks.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-*- ,
2+
' -*-
3+
'
4+
* .!,
5+
-=*=-
6+
'|`*
7+
-*-.!,
8+
'-=*=-
9+
'|`
10+
-*- .!,
11+
' -=*=-
12+
'|`
13+
-*- .
14+
' -*-
15+
'

Slt/Art/Etc/Sparks.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Slt.Ascii;
2+
using Slt.Cli.Consoles;
3+
using Slt.Util;
4+
5+
namespace Slt.Art.Etc;
6+
7+
public class Sparks : IAnimation
8+
{
9+
private readonly Figure _figure;
10+
private int _frame;
11+
12+
public Sparks(bool useColors = false)
13+
{
14+
_figure = new Figure(
15+
EmbeddedResource.ReadAllText("Slt.Art.Etc.Outline.Sparks.txt"),
16+
useColors ? EmbeddedResource.ReadAllText("Slt.Art.Etc.Outline.Colors.Sparks.txt") : ""
17+
);
18+
}
19+
20+
public Figure GetFrame(IConsole console)
21+
{
22+
return _figure.Crop(9, 3, 0, _frame * 3);
23+
}
24+
25+
public void SetFrame(int frame)
26+
{
27+
_frame = frame % 5 + 5;
28+
}
29+
30+
public void Advance()
31+
{
32+
_frame = ++_frame % 5;
33+
}
34+
35+
public bool HasFinished()
36+
{
37+
return false;
38+
}
39+
}

Slt/Art/Slt/AbstractSlt.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ namespace Slt.Art.Slt;
77
public abstract class AbstractSlt : IAnimation
88
{
99
private readonly Figure _result;
10+
private readonly IAnimation? _sparks;
1011
private int _frame;
1112

1213
protected AbstractSlt(
1314
Figure drivingCar,
1415
Figure trailerCar,
1516
Figure collectorRoof,
1617
Figure fullLengthRoof,
17-
Figure connection)
18+
Figure connection,
19+
IAnimation? sparks)
1820
{
1921
_result = new Figure()
2022
.AddAt(drivingCar, new Point(0, 3))
@@ -26,16 +28,26 @@ protected AbstractSlt(
2628
.AddAt(fullLengthRoof, new Point(254, 3))
2729
.AddAt(connection, new Point(348, 5))
2830
.AddAt(Mirror.Reflect(drivingCar), new Point(368, 3));
31+
_sparks = sparks;
2932
}
3033

31-
public string GetFrame(IConsole console)
34+
public Figure GetFrame(IConsole console)
3235
{
33-
return _result.Crop(
36+
var train = (Figure)_result.Clone();
37+
38+
if (_sparks != null)
39+
{
40+
train = train.AddAt(_sparks.GetFrame(console), new Point(147, 0));
41+
_sparks.Advance();
42+
train = train.AddAt(_sparks.GetFrame(console), new Point(152, 0));
43+
}
44+
45+
return train.Crop(
3446
console.GetSize().Width,
3547
console.GetSize().Height,
3648
_frame,
3749
0
38-
).Draw();
50+
);
3951
}
4052

4153
public void SetFrame(int frame)

Slt/Art/Slt/OutlineSlt.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
using Slt.Art.Etc;
12
using Slt.Ascii;
3+
using Slt.Cli;
24
using Slt.Util;
35

46
namespace Slt.Art.Slt;
57

68
public class OutlineSlt : AbstractSlt
79
{
8-
public OutlineSlt() : base(
10+
public OutlineSlt(AnimationConfiguration config) : base(
911
new Figure(
1012
EmbeddedResource.ReadAllText("Slt.Art.Slt.Outline.DrivingCar.txt")
1113
),
@@ -20,7 +22,8 @@ public OutlineSlt() : base(
2022
),
2123
new Figure(
2224
EmbeddedResource.ReadAllText("Slt.Art.Slt.Outline.Connection.txt")
23-
)
25+
),
26+
config.ShowSparks ? new Sparks() : null
2427
)
2528
{
2629
}

Slt/Art/Slt/SolidSlt.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1+
using Slt.Art.Etc;
12
using Slt.Ascii;
3+
using Slt.Cli;
24
using Slt.Util;
35

46
namespace Slt.Art.Slt;
57

68
public class SolidSlt : AbstractSlt
79
{
8-
public SolidSlt(bool useColors = false) : base(
10+
public SolidSlt(AnimationConfiguration config) : base(
911
new Figure(
1012
EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.DrivingCar.txt"),
11-
useColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.DrivingCar.txt") : ""
13+
config.UseColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.DrivingCar.txt") : ""
1214
),
1315
new Figure(
1416
EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.TrailerCar.txt"),
15-
useColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.TrailerCar.txt") : ""
17+
config.UseColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.TrailerCar.txt") : ""
1618
),
1719
new Figure(
1820
EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.CollectorRoof.txt"),
19-
useColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.CollectorRoof.txt") : ""
21+
config.UseColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.CollectorRoof.txt") : ""
2022
),
2123
new Figure(
2224
EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.FullLengthRoof.txt"),
23-
useColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.FullLengthRoof.txt") : ""
25+
config.UseColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.FullLengthRoof.txt") : ""
2426
),
2527
new Figure(
2628
EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Connection.txt"),
27-
useColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.Connection.txt") : ""
28-
)
29+
config.UseColors ? EmbeddedResource.ReadAllText("Slt.Art.Slt.Solid.Colors.Connection.txt") : ""
30+
),
31+
config.ShowSparks ? new Sparks(config.UseColors) : null
2932
)
3033
{
3134
}

Slt/Ascii/Colors.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private static Color ConvertCodeToColor(char code)
8080
return code switch
8181
{
8282
'B' => Color.MediumBlue,
83+
'b' => Color.LightSkyBlue,
8384
'D' => Color.DimGray,
8485
'G' => Color.Gray,
8586
'L' => Color.LightGray,

Slt/Ascii/Figure.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Slt.Ascii;
66
/// A Figure is an ASCII art drawing that can be arbitarily cropped and combined
77
/// with other Figures.
88
/// </summary>
9-
public readonly struct Figure
9+
public readonly struct Figure : ICloneable
1010
{
1111
public readonly List<string> Lines;
1212
public readonly string ColorMap;
@@ -165,4 +165,9 @@ public override string ToString()
165165
{
166166
return string.Join("\n", Lines);
167167
}
168+
169+
public object Clone()
170+
{
171+
return new Figure(Lines, ColorMap);
172+
}
168173
}

Slt/Ascii/IAnimation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IAnimation
1212
/// </summary>
1313
/// <param name="console">Console where the frame will be displayed</param>
1414
/// <returns>The current frame of this animation</returns>
15-
public string GetFrame(IConsole console);
15+
public Figure GetFrame(IConsole console);
1616

1717
/// <summary>
1818
/// Set the animation to a specific frame

0 commit comments

Comments
 (0)