-
Notifications
You must be signed in to change notification settings - Fork 14
/
Program.cs
1582 lines (1346 loc) · 50.1 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using Love;
using Love.Misc;
using System.Linq;
namespace LoveTest
{
abstract class Stage
{
virtual public void OnLoad() { }
virtual public void OnKeyPressed(KeyConstant key) { }
virtual public void OnUpdate(float dt) { }
virtual public void OnDraw() { }
virtual public void OnPause() { }
virtual public void OnReOpne() { }
virtual public void OnTextEditing(string text, int start, int end) { }
virtual public void OnTextInput(string text) { }
}
[StageName("Test SystemLove")]
class TestSystemLove : Stage
{
string url = "https://www.cnblogs.com";
string url2 = "C:/";
public override void OnUpdate(float dt)
{
if (Keyboard.IsDown(KeyConstant.LCtrl) && Keyboard.IsPressed(KeyConstant.C))
{
Special.SetClipboardText(text);
}
else if (Keyboard.IsDown(KeyConstant.LCtrl) && Keyboard.IsPressed(KeyConstant.V))
{
text = Special.GetClipboardText();
}
if (Keyboard.IsPressed(KeyConstant.U))
{
Special.OpenURL(url);
}
if (Keyboard.IsPressed(KeyConstant.L))
{
Special.OpenURL(url2);
}
}
string text = "init-test-text";
public override void OnDraw()
{
var sb = new List<string>();
Special.GetPowerInfo(out var state, out var percent, out var seconds);
sb.Add($"-------------------- stattus --------------------");
sb.Add($"OS name: {Special.GetOS()}");
if (Special.GetOS() == "Windows")
{
sb.Add($"GetWin32Handle: {Special.GetWin32Handle()}");
}
sb.Add($"Processor Count: {Special.GetProcessorCount()}");
sb.Add($"Power Info: {state}");
sb.Add($"Power Info percent: {percent}");
sb.Add($"Power Info seconds: {seconds}");
sb.Add($"-------------------- current clipboard text --------------------");
sb.Add($"{Special.GetClipboardText()}");
sb.Add($"-------------------- operator --------------------");
sb.Add($"[left-ctrl + c]: put text '{text}' to clipboard");
sb.Add($"[U]: open url {url}");
sb.Add($"[L]: open url {url2}");
Graphics.SetColor(0, 0, 0);
Graphics.Print(string.Join("\n", sb), 10, 10);
}
}
[StageName("test image data map")]
class TestImageDataMap : Stage
{
static int W = 202, H = 200;
ImageDataPixelFormat imageDataPixelFormat = ImageDataPixelFormat.RGBA8;
Image[] image;
private Color MapPixel_01(int x, int y, Color p)
{
var col = new Color(x / (float)W, y / (float)H, 1f, 1f);
return new Color(col.Rf, col.Gf, col.Bf, col.Af);
}
private Vector4 MapPixel_02(int x, int y, Vector4 p)
{
var col = new Color(x / (float)W, y / (float)H, 1f, 1f);
return new Vector4(col.Rf, col.Gf, col.Bf, col.Af);
}
public T[] GenData<T>(Func<int, int, T, T> func, T rawT)
{
T[] data = new T[W * H];
for (int y = 0; y < H; y++)
{
for (int x = 0; x < W; x++)
{
data[x + y * W] = func(x, y, rawT);
}
}
return data;
}
public override void OnLoad()
{
var imgd01 = Image.NewImageData(W, H, imageDataPixelFormat);
imgd01.MapPixel(MapPixel_01);
var imgd02 = Image.NewImageData(W, H, imageDataPixelFormat);
imgd02.MapPixel(MapPixel_02);
//var imgd03 = Image.NewImageData(W, H, imageDataPixelFormat);
//imgd03.MapPixel(MapPixel_03);
//var imgd04 = Image.NewImageData(W, H, imageDataPixelFormat);
//imgd04.SetPixel(GenData(MapPixel_01, Color.White));
var imgd04 = Image.NewImageData(W, H, imageDataPixelFormat);
{
for (int y = 0; y < H / 2; y++)
for (int x = 0; x < W / 2; x++)
imgd04.SetPixel(x, y, MapPixel_01(x, y, Color.White));
// get & set
var buffer = new Color[W, H];
for (int y = 0; y < H / 2; y++)
for (int x = 0; x < W / 2; x++)
{
buffer[x, y] = imgd04.GetPixel(x, y);
imgd04.SetPixel(W/2 + x, H/2 + y, buffer[x, y]);
}
}
image = new Image[]
{
Graphics.NewImage(imgd01),
Graphics.NewImage(imgd02),
// Graphics.NewImage(imgd03),
Graphics.NewImage(imgd04),
};
}
public override void OnUpdate(float dt)
{
}
public override void OnDraw()
{
Graphics.SetColor(1, 1, 1);
for (int i = 0; i < image.Length; i++)
{
Graphics.Draw(image[i], W * 0, H * i);
}
Graphics.SetColor(Color.Red);
Graphics.SetLineWidth(5);
for (int i = 0; i < image.Length; i++)
{
Graphics.Rectangle(DrawMode.Line, W * 0, H * i, W, H);
}
Graphics.SetLineWidth(1);
}
}
[StageName("test image data")]
class TestImageData : Stage
{
static int W = 1000, H = 1000;
ImageData imageData;
Image image;
void PrintExecTime(string name, Action action)
{
var start = DateTime.Now.Ticks;
action();
Console.WriteLine($"{name}, consume time: { (DateTime.Now.Ticks - start) / TimeSpan.TicksPerMillisecond }");
}
public override void OnLoad()
{
byte[] data = new byte[W * H * 4];
for (int x = 0; x < W; x++)
{
for (int y = 0; y < H; y++)
{
data[(x + y * W) * 4 + 0] = 255;
data[(x + y * W) * 4 + 1] = 0;
data[(x + y * W) * 4 + 2] = 0;
data[(x + y * W) * 4 + 3] = 255;
}
}
imageData = Image.NewImageData(W, H, ImageDataPixelFormat.RGBA8);
var format = imageData.GetFormat();
int w = imageData.GetWidth();
int h = imageData.GetHeight();
PrintExecTime("imageData.MapPixel((int x, int y, Float4 pixel, x, y, w, h ) ", () =>
{
imageData.MapPixel((int x, int y, Vector4 pixel) =>
{
pixel.r = 0;
pixel.g = 0;
pixel.b = 0.9f;
pixel.a = 1;
return pixel;
}, 0, 0, W, H);
});
PrintExecTime("imageData.MapPixel((int x, int y, Float4 pixel) ", () =>
{
imageData.MapPixel((int x, int y, Vector4 pixel) =>
{
pixel.r = 0;
pixel.g = 0;
pixel.b = 0.9f;
pixel.a = 1;
return pixel;
});
});
PrintExecTime("Float[] imageData.GetPixelsFloat() => ", () =>
{
var p = imageData.GetPixelsFloat();
});
PrintExecTime("imageData.SetPixelsFloat( Float4[] p) => ", () =>
{
Vector4[] pixelBuffer = new Vector4[w * h];
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
Vector4 pixel = new Vector4();
pixel.r = 0.5f;
pixel.g = 0.4f;
pixel.b = 0.1f;
pixel.a = 1;
pixelBuffer[y * w + x] = pixel;
}
}
imageData.SetPixelsFloat(pixelBuffer);
});
image = Graphics.NewImage(imageData);
}
public override void OnUpdate(float dt)
{
}
public override void OnDraw()
{
Graphics.SetColor(0, 0, 0);
Graphics.Print($"{image.GetWidth()} {image.GetHeight()} {imageData.GetFormat()} {imageData.GetSize()}", 0, 0);
Graphics.SetColor(1, 1, 1);
Graphics.Draw(image, 10, 10);
}
}
[StageName("test shader")]
class TestShader : Stage
{
Shader shader;
Image img;
public override void OnLoad()
{
//shader = new Shader();
}
public override void OnUpdate(float dt)
{
}
public override void OnDraw()
{
}
}
class Button
{
public void Update(float dt)
{
}
}
[AttributeUsage(AttributeTargets.Class)]
public class StageName : Attribute
{
public StageName(string name)
{
Name = name;
}
public readonly string Name;
}
[StageName("test key board")]
class TestKeyborad : Stage
{
public override void OnKeyPressed(KeyConstant key)
{
if (key == KeyConstant.R)
{
Keyboard.SetKeyRepeat(!Keyboard.HasKeyRepeat());
}
if (key == KeyConstant.T)
{
Keyboard.SetTextInput(!Keyboard.HasTextInput());
}
}
string keyPressedReleadedStr = "";
public override void OnDraw()
{
var sb = new List<string>();
sb.Add($"-------------------- status --------------------");
sb.Add($" whether key repeat is enabled : {Keyboard.HasKeyRepeat()}");
sb.Add($" whether text input events are enabled : {Keyboard.HasTextInput()}");
sb.Add($"-------------------- recursive enumerate files --------------------");
sb.Add($"[R]: toogle Key Repeat");
sb.Add($"[T]: toogle Text Input");
var keyThatWasDown = new List<KeyConstant>();
foreach(var key in (KeyConstant[])Enum.GetValues( typeof(KeyConstant)) )
{
if (Keyboard.IsDown(key))
{
keyThatWasDown.Add(key);
}
if (Keyboard.IsPressed(key))
{
keyPressedReleadedStr += key.ToString() + " is pressed \n";
}
if (Keyboard.IsReleased(key))
{
keyPressedReleadedStr += key.ToString() + " is released \n";
}
}
sb.Add($"key that down : {string.Join(",", keyThatWasDown)}");
var scancodeThatWasDown = new List<Scancode>();
foreach (var key in keyThatWasDown)
{
scancodeThatWasDown.Add(Keyboard.GetScancodeFromKey(key));
}
sb.Add($"scancode that down (convert from KeyConstant) : {string.Join(",", scancodeThatWasDown)}");
sb.Add($"{keyPressedReleadedStr}\n");
Graphics.SetColor(0, 0, 0);
Graphics.Print(string.Join("\n", sb), 10, 10);
}
}
[StageName("test mouse")]
class TestMouse : Stage
{
Cursor cursor;
public override void OnLoad()
{
// https://opengameart.org/content/bw-ornamental-cursor-19x19
cursor = Mouse.NewCursor("res/pointer.png", 0, 0);
Mouse.SetCursor(cursor);
}
public override void OnUpdate(float dt)
{
}
public override void OnReOpne()
{
Mouse.SetCursor(cursor);
}
public override void OnKeyPressed(KeyConstant key)
{
var dic = new Dictionary<KeyConstant, SystemCursor>();
dic.Add(KeyConstant.A, SystemCursor.Arrow);
dic.Add(KeyConstant.B, SystemCursor.Crosshair);
dic.Add(KeyConstant.C, SystemCursor.Hand);
dic.Add(KeyConstant.D, SystemCursor.Ibeam);
dic.Add(KeyConstant.E, SystemCursor.No);
dic.Add(KeyConstant.F, SystemCursor.SizeAll);
dic.Add(KeyConstant.G, SystemCursor.SizeNESW);
dic.Add(KeyConstant.H, SystemCursor.SizeNS);
dic.Add(KeyConstant.I, SystemCursor.SizeNWSE);
dic.Add(KeyConstant.J, SystemCursor.SizeWE);
dic.Add(KeyConstant.K, SystemCursor.Wait);
dic.Add(KeyConstant.L, SystemCursor.WaitArrow);
if (dic.ContainsKey(key))
{
Mouse.SetCursor(Mouse.GetSystemCursor(dic[key]));
}
if (key == KeyConstant.Number1)
{
Mouse.SetCursor(cursor);
}
if (key == KeyConstant.Number2)
{
Mouse.SetGrabbed(!Mouse.IsGrabbed());
}
if (key == KeyConstant.Number3)
{
Mouse.SetPosition(10, 20);
}
if (key == KeyConstant.Number4)
{
Mouse.SetVisible(!Mouse.IsVisible());
}
if (key == KeyConstant.Number5)
{
Mouse.SetRelativeMode(!Mouse.GetRelativeMode());
}
}
public override void OnDraw()
{
if (Mouse.IsPressed(0))
Console.WriteLine("Mouse.IsPressed(0)");
if (Mouse.IsReleased(0))
Console.WriteLine("Mouse.IsReleased(0)");
Graphics.SetColor(0, 0, 0);
bool hasPreviousPos = (Mouse.GetPreviousX() != Mouse.GetX() || Mouse.GetPreviousY() != Mouse.GetY());
Mouse.GetPreviousX();
string[] str =
{
"[A-L]: set cursor to different system curosr",
"[1]: set cursor custom curosr",
"[2]: toggle grabs the mouse and confines it to the window. ",
"[3]: change pos to (0,0). ",
"[4]: toggle visible / invisible. ",
"[5]: toggle relative mode. ",
"\n",
$"cursor cursor type: {Mouse.GetCursor().GetType()}",
$"Is Grabbed : {Mouse.IsGrabbed()}",
$"pos : {Mouse.GetPosition()}",
$"Get Relative Mode : {Mouse.GetRelativeMode()}",
$"Is Visible : {Mouse.IsVisible()}",
$"Is Cursor Supported : {Mouse.IsCursorSupported()}",
$"down Mouse.LeftButton: {Mouse.IsDown(Mouse.LeftButton)}",
$"down Mouse.RightButton: {Mouse.IsDown(Mouse.RightButton)}",
$"down Mouse.MiddleButton: {Mouse.IsDown(Mouse.MiddleButton)}",
$"down Mouse.ExtendedButton1: {Mouse.IsDown(Mouse.ExtendedButton1)}",
$"down Mouse.ExtendedButton2: {Mouse.IsDown(Mouse.ExtendedButton2)}",
$"down Mouse.ExtendedButton3: {Mouse.IsDown(Mouse.ExtendedButton3)}",
$"scrool X: {Mouse.GetScrollX()}",
$"scrool Y: {Mouse.GetScrollY()}",
$"has previous: " + (hasPreviousPos ? "true -> " + Mouse.GetPreviousX() + ", " + Mouse.GetPreviousY() : "false"),
"\n",
};
Graphics.Print(string.Join("\n", str), 10, 10);
//Graphics.Line(Mouse.GetPreviousX(), Mouse.GetPreviousY() ,Mouse.GetX(), Mouse.GetY());
}
}
[StageName("test file")]
class TestFile : Stage
{
static string TEST_FILE_PATH = "test.txt";
static string IDENTIFY_PATH = "test_for_my_work";
static string MOUNT_PATH = "E:\\Animate";
string recursiveEnumerateBuffer;
public override void OnKeyPressed(KeyConstant key)
{
if (key == KeyConstant.A)
{
FileSystem.Append(TEST_FILE_PATH, "You have to be happiness.\n");
}
if (key == KeyConstant.I)
{
FileSystem.SetIdentity(IDENTIFY_PATH);
}
if (key == KeyConstant.C)
{
FileSystem.Write(TEST_FILE_PATH, "new file .... \n");
}
if (key == KeyConstant.D)
{
var success = FileSystem.CreateDirectory("a_dir");
Console.WriteLine("CreateDirectory success : {0}", success);
}
if (key == KeyConstant.E)
{
var success = FileSystem.Remove(TEST_FILE_PATH);
Console.WriteLine("remove success : {0}", success);
}
if (key == KeyConstant.M)
{
var success = FileSystem.PhysicsFS.Mount(MOUNT_PATH, "win_boot_ressources");
Console.WriteLine("mount success : {0}", success);
}
if (key == KeyConstant.R)
{
Console.WriteLine(recursiveEnumerateBuffer);
recursiveEnumerateBuffer = recursiveEnumerate("", "", "");
}
if (key == KeyConstant.S)
{
throw new Exception("no support yet");
}
}
public override void OnLoad()
{
recursiveEnumerateBuffer = recursiveEnumerate("", "", "");
Console.WriteLine(recursiveEnumerateBuffer);
}
public override void OnUpdate(float dt)
{
}
public string recursiveEnumerate(string folder, string fileTree, string tab)
{
var list = FileSystem.PhysicsFS.GetDirectoryItems(folder);
foreach (var item in list)
{
var file = folder + "/" + item;
var info = FileSystem.PhysicsFS.GetInfo(file);
if (info != null)
{
if (info.Type == FileType.File)
{
fileTree = fileTree + "\n" + tab + file;
}
else if (info.Type == FileType.Directory)
{
fileTree = fileTree + "\n" + file + " (DIR)";
fileTree = recursiveEnumerate(file, fileTree, tab + " ");
}
}
}
return fileTree;
}
public override void OnDraw()
{
var info = FileSystem.GetInfo(TEST_FILE_PATH);
var sb = new List<string>();
sb.Add($"-------------------- {TEST_FILE_PATH} --------------------");
sb.Add($"exist : {info != null}");
if (info != null)
{
string content = System.Text.Encoding.UTF8
.GetString(FileSystem.Read(TEST_FILE_PATH))
.Replace(Convert.ToChar(0x0).ToString(), " ");
sb.Add($"info : {info}");
sb.Add($"realpath : {FileSystem.PhysicsFS.GetRealDirectory(TEST_FILE_PATH)}");
sb.Add($"text content : {content}");
}
sb.Add($"-------------------- Operate --------------------");
sb.Add($"[A]: Append to file '{TEST_FILE_PATH}' 'You have to be happiness.(LR)' ");
sb.Add($"[C]: (Re)create new file '{TEST_FILE_PATH}' with content 'new file ....(LR)' ");
sb.Add($"[E]: remove file '{TEST_FILE_PATH}' ");
sb.Add($"[I]: Set identify path to '{IDENTIFY_PATH}' ");
sb.Add($"[S]: toogle symbolic link switch ");
sb.Add($"-------------------- Status --------------------");
sb.Add($"whether the game is in fused mode or not: {FileSystem.PhysicsFS.IsFused()}");
sb.Add($"current working directory: {FileSystem.PhysicsFS.GetWorkingDirectory()}");
sb.Add($"whether love.filesystem follows symbolic links: {FileSystem.PhysicsFS.AreSymlinksEnabled()}");
sb.Add($"application data directory: {FileSystem.GetAppdataDirectory()}");
sb.Add($"the full path to the designated save directory: {FileSystem.GetSaveDirectory()}");
sb.Add($"the full path to the source or directory.: {FileSystem.GetSource()}");
sb.Add($"Require Path: {FileSystem.PhysicsFS._GetRequirePath()}");
sb.Add($"the full path to the directory containing the .love file.: {FileSystem.PhysicsFS._GetSourceBaseDirectory()}");
sb.Add($"the path of the user's directory: {FileSystem.GetUserDirectory()}");
sb.Add($"the write directory name for your game: {FileSystem.GetIdentity()}");
sb.Add($"-------------------- recursive enumerate files --------------------");
sb.Add($"[R]: refresh file list");
sb.Add($"{recursiveEnumerateBuffer}");
Graphics.SetColor(0, 0, 0);
Graphics.Print(string.Join("\n", sb), 10, 10);
}
}
[StageName("resource file")]
class TestResourceFile : Stage
{
static string TEST_FILE_PATH = "test.txt";
static string TEST_DIR_PATH = "a_dir";
string recursiveEnumerateBuffer;
public override void OnKeyPressed(KeyConstant key)
{
if (key == KeyConstant.A)
{
FileSystem.Append(TEST_FILE_PATH, "You have to be happiness.\n");
}
if (key == KeyConstant.C)
{
FileSystem.Write(TEST_FILE_PATH, "new file .... \n");
}
if (key == KeyConstant.D)
{
var success = FileSystem.CreateDirectory(TEST_DIR_PATH);
Console.WriteLine("CreateDirectory success : {0}", success);
}
if (key == KeyConstant.X)
{
Console.WriteLine("remove dir success : {0}", FileSystem.Remove(TEST_DIR_PATH));
}
if (key == KeyConstant.E)
{
var success = FileSystem.Remove(TEST_FILE_PATH);
Console.WriteLine("remove success : {0}", success);
}
if (key == KeyConstant.R)
{
recursiveEnumerateBuffer = recursiveEnumerate(".", "", "");
Console.WriteLine(recursiveEnumerateBuffer);
}
if (key == KeyConstant.S)
{
throw new Exception("no support yet");
}
}
public override void OnLoad()
{
recursiveEnumerateBuffer = recursiveEnumerate(".", "", "");
Console.WriteLine(recursiveEnumerateBuffer);
}
public override void OnUpdate(float dt)
{
if (Keyboard.IsPressed(KeyConstant.T) || Keyboard.IsReleased(KeyConstant.T))
{
FileSystem.Append(TEST_FILE_PATH, "You have to be happiness.\n");
}
}
public string recursiveEnumerate(string folder, string fileTree, string tab)
{
var list = FileSystem.GetDirectoryItems(folder);
foreach (var item in list)
{
var file = item;
var info = FileSystem.GetInfo(file);
if (info != null)
{
if (info.Type == FileType.File)
{
fileTree = fileTree + "\n" + tab + file;
}
else if (info.Type == FileType.Directory)
{
fileTree = fileTree + "\n" + file + " (DIR)";
fileTree = recursiveEnumerate(file, fileTree, tab + " ");
}
}
}
return fileTree;
}
public override void OnDraw()
{
var info = FileSystem.GetInfo(TEST_FILE_PATH);
var sb = new List<string>();
sb.Add($"-------------------- {TEST_FILE_PATH} --------------------");
sb.Add($"exist : {info != null}");
if (info != null)
{
string content = System.Text.Encoding.UTF8
.GetString(FileSystem.Read(TEST_FILE_PATH))
.Replace(Convert.ToChar(0x0).ToString(), " ");
sb.Add($"info : {(info == null ? "" : info.ToString())}");
sb.Add($"text content : {content}");
}
sb.Add($"-------------------- Operate --------------------");
sb.Add($"[T/T]: Append to file '{TEST_FILE_PATH}' 'You have to be happiness.(LR)' ");
sb.Add($"[A]: Append to file '{TEST_FILE_PATH}' 'You have to be happiness.(LR)' ");
sb.Add($"[C]: (Re)create new file '{TEST_FILE_PATH}' with content 'new file ....(LR)' ");
sb.Add($"[E]: remove file '{TEST_FILE_PATH}' ");
sb.Add($"[X]: remove dir '{TEST_DIR_PATH}' ");
sb.Add($"[D]: create dir {TEST_DIR_PATH} ");
sb.Add($"[S]: toogle symbolic link switch ");
sb.Add($"-------------------- Status --------------------");
sb.Add($"-------------------- recursive enumerate files --------------------");
sb.Add($"[R]: refresh file list");
sb.Add($"{recursiveEnumerateBuffer}");
Graphics.SetColor(0, 0, 0);
Graphics.Print(string.Join("\n", sb), 10, 10);
}
}
[StageName("test other")]
class TestOther : Stage
{
public override void OnLoad()
{
}
public override void OnUpdate(float dt)
{
}
public override void OnDraw()
{
Graphics.SetLineWidth(2);
Graphics.SetColor(1, 0, 0);
Graphics.Line(
10, 10,
20, 20, 200);
//Graphics.Line(
// 10, 10,
// 20, 10,
// 20, 20,
// 30, 20,
// 30, 30,
// 40, 30,
// 40, 40);
// Graphics.Rectangle(DrawMode.Fill, 10, 10, 200, 200);
Graphics.SetPointSize(5);
var cplist = new ColoredPoint[]
{
new ColoredPoint(new Vector2(200, 150), new Vector4(0.5f, 0, 0, 1)),
new ColoredPoint(new Vector2(200, 200), new Vector4(1, 0, 0, 1)),
new ColoredPoint(new Vector2(300, 300), new Vector4(0, 1, 0, 1)),
new ColoredPoint(new Vector2(400, 400), new Vector4(0, 0, 1, 1)),
};
Graphics.Points(cplist);
}
}
[StageName("Audio")]
class TestAudio : Stage
{
Source[] sourceList = new Source[3];
Dictionary<Source, string> dictionary = new Dictionary<Source, string>();
Source currentControl;
public override void OnLoad()
{
// https://opengameart.org/content/prepare-your-swords
sourceList[0] = Audio.NewSource("res/prepare_your_swords_mono.mp3", SourceType.Stream);
dictionary.Add(sourceList[0], "res/prepare_your_swords_mono.mp3");
// https://opengameart.org/content/prepare-your-swords
sourceList[1] = Audio.NewSource("res/prepare_your_swords.ogg", SourceType.Stream);
dictionary.Add(sourceList[1], "res/prepare_your_swords.ogg");
// https://opengameart.org/content/gui-sound-effects
sourceList[2] = Audio.NewSource("res/negative.mp3", SourceType.Static);
dictionary.Add(sourceList[2], "res/negative.mp3");
// set to 0
currentControl = sourceList[0];
}
public override void OnPause()
{
Audio.Pause();
}
public override void OnKeyPressed(KeyConstant key)
{
if (key == KeyConstant.Number1)
{
currentControl = sourceList[0];
}
if (key == KeyConstant.Number2)
{
currentControl = sourceList[1];
}
if (key == KeyConstant.Number3)
{
currentControl = sourceList[2];
}
if (key == KeyConstant.P)
{
if (currentControl.IsPlaying() == false)
{
currentControl.Play();
}
else
{
currentControl.Pause();
}
}
if (key == KeyConstant.S)
{
currentControl.Seek(0, TimeUnit.Seconds);
}
if (key == KeyConstant.R)
{
currentControl.SetRelative(!currentControl.IsRelative());
}
if (key == KeyConstant.Left)
{
var pos = currentControl.GetPosition();
currentControl.SetPosition(pos.X - 1, pos.Y, pos.Z);
}
if (key == KeyConstant.Right)
{
var pos = currentControl.GetPosition();
currentControl.SetPosition(pos.X + 1, pos.Y, pos.Z);
}
if (key == KeyConstant.Down)
{
var pos = currentControl.GetPosition();
currentControl.SetPosition(pos.X, pos.Y - 1, pos.Z);
}
if (key == KeyConstant.Up)
{
var pos = currentControl.GetPosition();
currentControl.SetPosition(pos.X, pos.Y + 1, pos.Z);
}
}
public override void OnDraw()
{
var sb = new List<string>();
sb.Add($"audio active source count : {Audio.GetActiveSourceCount()}");
sb.Add($"audio distance modle : {Audio.GetDistanceModel()}");
sb.Add($"audio Doppler Scale : {Audio.GetDopplerScale()}");
sb.Add($"audio Orientation : {Audio.GetOrientation()}");
sb.Add($"audio Velocity : {Audio.GetVelocity()}");
sb.Add($"--------------------------------------------------");
sb.Add($"current source controled : { dictionary[currentControl] }");
sb.Add($"[1-3] : switch control source index");
foreach (var s in sourceList)
{
sb.Add((currentControl == s ? "* ": " ")
+ "playing : " + (s.IsPlaying()) + " "
+ dictionary[s]);
}
sb.Add("\n");
sb.Add($"playing : {currentControl.IsPlaying()}");
sb.Add($"tell : {currentControl.Tell(TimeUnit.Seconds)}");
sb.Add($"channel count : {currentControl.GetChannelCount()}");
sb.Add("\n------------------------------------------------");
sb.Add("[P] : pause / play");
sb.Add("[S] : seek to 0");
if (currentControl.GetChannelCount() == 1)
{
sb.Add("\n");
sb.Add($"pos : {currentControl.GetPosition()}");
sb.Add("[R] : toggle Relative");
sb.Add("[Left] : set pos x - 1");
sb.Add("[Right] :set pos x + 1");
sb.Add("[Down] : set pos y - 1");
sb.Add("[Up] : set pos y + 1");
}
else
{
}
Graphics.SetColor(0, 0, 0);
Graphics.Print(string.Join("\n", sb), 10, 100);
}
}
[StageName("test video")]
class TestVideo : Stage
{
Video video;
public override void OnReOpne()
{
if (video != null)
{
video.Rewind();
video.Play();
}
}
public override void OnPause()
{
if (video != null)
{
video.Pause();
}
}
public override void OnLoad()
{
var vstream = Video.NewVideoStream("res/small.ogv");
video = Graphics.NewVideo(vstream);
video.Play();
}
public override void OnDraw()
{
Graphics.Draw(video, 10, 50);
string[] str =
{
"[R]: seek(0)",
$"name:{video.GetStream().GetFilename()}",
$"playing:{video.IsPlaying()}",
$"tell:{video.Tell()}",
};
Graphics.Print(string.Join(" ", str), 10, 5);
}
public override void OnUpdate(float dt)
{
video.SetSource(video.GetSource());
}
public override void OnKeyPressed(KeyConstant key)
{
if (key == KeyConstant.R)
{
video.Seek(0);
}
}
}
[StageName("test Text")]
class TestText : Stage
{
float x = 0, y = 0;
Text text;
string textInputStr = "on-text-input\n";
public override void OnTextEditing(string text, int start, int end)
{
Console.WriteLine($"OnTextEditing from {start} to {end}:" + text);
}
public override void OnTextInput(string text)
{
textInputStr += text + "\n";
}
public override void OnLoad()
{
text = Graphics.NewText(Graphics.GetFont(), "hello LÖVE-2d-CS ?");
}
public override void OnUpdate(float dt)
{
x = (x + 0.1f) % 400f;
y = (y + 0.1f) % 300f;