webglmusti 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/.gitattributes +2 -0
  2. package/idea_list.txt +13 -0
  3. package/index.html +17 -0
  4. package/package.json +20 -0
  5. package/public/apple.png +0 -0
  6. package/public/base.png +0 -0
  7. package/public/car.png +0 -0
  8. package/public/drop.png +0 -0
  9. package/public/font16-Sheet.png +0 -0
  10. package/public/font16-Sheet.txt +52 -0
  11. package/public/letters-Sheet.png +0 -0
  12. package/public/letters-Sheet.txt +27 -0
  13. package/public/letters_Sheet.png +0 -0
  14. package/public/letters_Sheet.txt +4 -0
  15. package/public/vite.svg +1 -0
  16. package/src/App/ResourceSim/car.ts +172 -0
  17. package/src/App/ResourceSim/grid.ts +993 -0
  18. package/src/App/ResourceSim/grid_app.ts +1326 -0
  19. package/src/App/ResourceSim/grid_test.test.ts +18 -0
  20. package/src/App/ResourceSim/node_graph.ts +293 -0
  21. package/src/App/ResourceSim/nodes.ts +151 -0
  22. package/src/App/ResourceSim/resource.ts +8 -0
  23. package/src/App/ResourceSim/texts.ts +6 -0
  24. package/src/App/card/card.test.ts +22 -0
  25. package/src/App/card/card.ts +763 -0
  26. package/src/App/puzzle_box/app.ts +10 -0
  27. package/src/App/puzzle_box/engine.ts +374 -0
  28. package/src/App/puzzle_box/renderer.ts +102 -0
  29. package/src/App/puzzle_box/test.test.ts +49 -0
  30. package/src/App/water/water.ts +206 -0
  31. package/src/Interface/button.ts +345 -0
  32. package/src/Interface/interface_element.ts +30 -0
  33. package/src/Interface/internal_window.ts +100 -0
  34. package/src/Interface/options.ts +332 -0
  35. package/src/Interface/text_input.ts +183 -0
  36. package/src/WebGL/Matrix/matrix.test.ts +30 -0
  37. package/src/WebGL/Matrix/matrix.ts +293 -0
  38. package/src/WebGL/Shaders/Fragment/Program/circle.ts +49 -0
  39. package/src/WebGL/Shaders/Fragment/Program/circle_only.ts +47 -0
  40. package/src/WebGL/Shaders/Fragment/Program/circle_outline.ts +54 -0
  41. package/src/WebGL/Shaders/Fragment/Program/colour.ts +39 -0
  42. package/src/WebGL/Shaders/Fragment/Program/colour_alpha.ts +37 -0
  43. package/src/WebGL/Shaders/Fragment/Program/line.ts +39 -0
  44. package/src/WebGL/Shaders/Fragment/Program/multi_colour_centre_circle_path.ts +69 -0
  45. package/src/WebGL/Shaders/Fragment/Program/multi_colour_path.ts +69 -0
  46. package/src/WebGL/Shaders/Fragment/Program/path_centre_circle.ts +69 -0
  47. package/src/WebGL/Shaders/Fragment/Program/rect_outline.ts +39 -0
  48. package/src/WebGL/Shaders/Fragment/Program/solid_path.ts +64 -0
  49. package/src/WebGL/Shaders/Fragment/Program/sprite_sheet.ts +54 -0
  50. package/src/WebGL/Shaders/Fragment/Program/sprite_sheet_colour.ts +62 -0
  51. package/src/WebGL/Shaders/Fragment/Program/texture.ts +34 -0
  52. package/src/WebGL/Shaders/Fragment/Source/circle.frag +19 -0
  53. package/src/WebGL/Shaders/Fragment/Source/circle_only.frag +15 -0
  54. package/src/WebGL/Shaders/Fragment/Source/circle_outline.frag +23 -0
  55. package/src/WebGL/Shaders/Fragment/Source/colour.frag +9 -0
  56. package/src/WebGL/Shaders/Fragment/Source/colour_alpha.frag +7 -0
  57. package/src/WebGL/Shaders/Fragment/Source/fragment.frag +5 -0
  58. package/src/WebGL/Shaders/Fragment/Source/fragment_source.ts +15 -0
  59. package/src/WebGL/Shaders/Fragment/Source/line.frag +12 -0
  60. package/src/WebGL/Shaders/Fragment/Source/multi_colour_centre_circle_path.frag +36 -0
  61. package/src/WebGL/Shaders/Fragment/Source/multi_colour_path.frag +34 -0
  62. package/src/WebGL/Shaders/Fragment/Source/path_centre_circle.frag +29 -0
  63. package/src/WebGL/Shaders/Fragment/Source/rect_outline.frag +20 -0
  64. package/src/WebGL/Shaders/Fragment/Source/solid_path.frag +24 -0
  65. package/src/WebGL/Shaders/Fragment/Source/sprite_sheet.frag +17 -0
  66. package/src/WebGL/Shaders/Fragment/Source/sprite_sheet_colour.frag +19 -0
  67. package/src/WebGL/Shaders/Fragment/Source/texture.frag +11 -0
  68. package/src/WebGL/Shaders/Fragment/fragment.ts +43 -0
  69. package/src/WebGL/Shaders/Fragment/fragment_old.ts +261 -0
  70. package/src/WebGL/Shaders/Vertex/Program/mvp2d.ts +41 -0
  71. package/src/WebGL/Shaders/Vertex/Program/transform2d.ts +39 -0
  72. package/src/WebGL/Shaders/Vertex/Source/mvp2d.vert +17 -0
  73. package/src/WebGL/Shaders/Vertex/Source/mvp_i_2d.vert +18 -0
  74. package/src/WebGL/Shaders/Vertex/Source/simple.vert +9 -0
  75. package/src/WebGL/Shaders/Vertex/Source/transform2d.vert +13 -0
  76. package/src/WebGL/Shaders/Vertex/Source/transform2d_rel.vert +16 -0
  77. package/src/WebGL/Shaders/Vertex/Source/translate2d.vert +7 -0
  78. package/src/WebGL/Shaders/Vertex/Source/vertex_source.ts +13 -0
  79. package/src/WebGL/Shaders/Vertex/vertex.ts +10 -0
  80. package/src/WebGL/Shaders/Vertex/vertex_old.ts +289 -0
  81. package/src/WebGL/Shaders/custom.ts +129 -0
  82. package/src/WebGL/Shaders/shader.ts +197 -0
  83. package/src/WebGL/Shapes/Line.ts +29 -0
  84. package/src/WebGL/Shapes/Shapes.ts +189 -0
  85. package/src/WebGL/Texture/texture.ts +214 -0
  86. package/src/WebGL/Util/file.ts +24 -0
  87. package/src/WebGL/app.ts +150 -0
  88. package/src/WebGL/colour.ts +71 -0
  89. package/src/WebGL/globals.ts +353 -0
  90. package/src/WebGL/index.ts +3 -0
  91. package/src/WebGL/mixin.ts +2 -0
  92. package/src/global.d.ts +13 -0
  93. package/src/index.ts +4 -0
  94. package/src/main.ts +139 -0
  95. package/src/utils/array.ts +154 -0
  96. package/src/utils/assert.ts +8 -0
  97. package/src/utils/file.ts +0 -0
  98. package/src/utils/mixin.ts +22 -0
  99. package/src/utils/numbers.ts +11 -0
  100. package/src/utils/utils.test.ts +23 -0
  101. package/src/vite-env.d.ts +1 -0
  102. package/tsconfig.json +25 -0
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/idea_list.txt ADDED
@@ -0,0 +1,13 @@
1
+ fix resizing - fixed by adding gl viewport in initialise ( can change )
2
+ use new app.ts in webgl - done
3
+
4
+ colour themes - Todo
5
+
6
+ finish dropdown select - TODO
7
+ add visual indicator (border) to text input when selected and sizing - TODO
8
+ draggable window inside canvas - mostly finished
9
+ car move to destination - TODO
10
+ save grid configurations - TODO
11
+ car traffic - TODO
12
+
13
+ implement puzzle grid - TODO
package/index.html ADDED
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>WebGl</title>
8
+ </head>
9
+ <body style="margin: 0px; overflow: hidden;">
10
+ <canvas id="app"></canvas>
11
+ <div id="overlay"></div>
12
+ <div id="coords"></div>
13
+ <script id="vert" type="notjs" src="/src/shaders/vertex.vert"></script>
14
+ <script id="frag" type="notjs" src="/src/shaders/fragment.frag"></script>
15
+ <script type="module" src="/src/main.ts"></script>
16
+ </body>
17
+ </html>
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "webglmusti",
3
+ "private": false,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview",
10
+ "test": "vitest"
11
+ },
12
+ "devDependencies": {
13
+ "typescript": "~5.8.3",
14
+ "vite": "^7.3.1",
15
+ "vitest": "^3.2.4"
16
+ },
17
+ "dependencies": {
18
+ "@datastructures-js/priority-queue": "^6.3.5"
19
+ }
20
+ }
Binary file
Binary file
package/public/car.png ADDED
Binary file
Binary file
Binary file
@@ -0,0 +1,52 @@
1
+ 51 1
2
+ aA
3
+ bB
4
+ cC
5
+ dD
6
+ eE
7
+ fF
8
+ gG
9
+ hH
10
+ iI
11
+ jJ
12
+ kK
13
+ lL
14
+ mM
15
+ nN
16
+ oO
17
+ pP
18
+ qQ
19
+ rR
20
+ sS
21
+ tT
22
+ uU
23
+ vV
24
+ wW
25
+ xX
26
+ yY
27
+ zZ
28
+ 1
29
+ 2
30
+ 3
31
+ 4
32
+ 5
33
+ 6
34
+ 7
35
+ 8
36
+ 9
37
+ 0
38
+ .
39
+ ,
40
+ /
41
+ :
42
+ +
43
+ -
44
+ ?
45
+ ;
46
+ !
47
+ =
48
+ '
49
+ "
50
+ <
51
+ >
52
+ _
Binary file
@@ -0,0 +1,27 @@
1
+ 26 1
2
+ aA
3
+ bB
4
+ cC
5
+ dD
6
+ eE
7
+ fF
8
+ gG
9
+ hH
10
+ iI
11
+ jJ
12
+ kK
13
+ lL
14
+ mM
15
+ nN
16
+ oO
17
+ pP
18
+ qQ
19
+ rR
20
+ sS
21
+ tT
22
+ uU
23
+ vV
24
+ wW
25
+ xX
26
+ yY
27
+ zZ
Binary file
@@ -0,0 +1,4 @@
1
+ 3 1
2
+ aA
3
+ bB
4
+ cC
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
@@ -0,0 +1,172 @@
1
+ import * as Grid from './grid';
2
+ import * as Node from './nodes';
3
+ import * as Resource from './resource';
4
+
5
+ type Int32 = number;
6
+ type Float = number;
7
+
8
+ type TrackPosition = {
9
+ distance_covered: Float,
10
+ move_index: Int32
11
+ }
12
+
13
+ export class Car{
14
+ //coordinates are from top-left corner
15
+ id: Int32;
16
+ x: Float; // center point
17
+ y: Float;
18
+ size: Float;
19
+ plan: Grid.Track | undefined;
20
+ plan_position: TrackPosition;
21
+ plan_index: Int32;
22
+ turn_speed: Float; // per second?
23
+ speed: Float; // per second
24
+ rotation: Float; // in radians
25
+ last_key: Grid.GridPosition | undefined;
26
+ //inventory: Resource | undefined;
27
+ constructor(id: Int32){
28
+ this.id = id;
29
+ this.x = 0;
30
+ this.y = 0;
31
+ this.size = 0.2;
32
+ this.plan = undefined;
33
+ this.plan_position = {distance_covered: 0, move_index: 0};
34
+ this.plan_index = 0;
35
+ this.speed = 0.01;
36
+ this.turn_speed = 0.05;
37
+ this.rotation = 0;
38
+ this.last_key = undefined;
39
+ }
40
+
41
+ setPlan(plan: Grid.Track){
42
+ //console.log(plan);
43
+ this.plan = plan;
44
+ this.x = plan.starting_location.x+0.5;
45
+ this.y = plan.starting_location.y+0.5;
46
+ this.last_key = plan.starting_location;
47
+ //this.rotation = Grid.DirectionUtil.turnDirectionToRadians(plan.part.getMoves()[0].direction);
48
+ this.plan_position = {distance_covered: 0, move_index: 0};
49
+ //console.log(this.plan.part.getMoves().at(0)?.direction);
50
+ }
51
+ update(t:Float){
52
+ if(this.plan){
53
+ const moves = this.plan.part.getMoves();
54
+ const dir = moves[this.plan_position.move_index].direction;
55
+ const dir_movement = Grid.DirectionUtil.directions[dir];
56
+ const target_rotation = Grid.DirectionUtil.turnDirectionToRadians(dir);
57
+ const turn = Grid.DirectionUtil.getTurnDirection(dir, this.rotation);
58
+ if(turn === Grid.TurnDirectionEnum.Clockwise){
59
+ if(this.rotation + this.turn_speed > target_rotation && this.rotation < target_rotation){
60
+ this.rotation = target_rotation;
61
+ //console.log("stop rot clock");
62
+ }else{
63
+ this.rotation += this.turn_speed;
64
+ this.rotation %= (Math.PI*2);
65
+ }
66
+ }else if(turn === Grid.TurnDirectionEnum.AntiClockwise){
67
+ if(this.rotation - this.turn_speed < target_rotation && this.rotation > target_rotation){
68
+ this.rotation = target_rotation;
69
+ //console.log("stop rot anti");
70
+ }else{
71
+ this.rotation -= this.turn_speed;
72
+ if(this.rotation < 0){
73
+ this.rotation += Math.PI*2;
74
+ }
75
+ }
76
+ }
77
+ else if(this.plan_position.distance_covered+this.speed >= moves[this.plan_position.move_index].distance){
78
+ const remaining = moves[this.plan_position.move_index].distance-this.plan_position.distance_covered;
79
+ this.x += dir_movement.x*remaining;
80
+ this.y -= dir_movement.y*remaining;
81
+ if(this.plan_position.move_index+1 >= moves.length){
82
+ this.plan_position = {distance_covered: 0, move_index: 0};
83
+ this.last_key = this.plan.endPoint();
84
+ this.plan = undefined;
85
+ }else{
86
+ this.plan_position = {distance_covered: 0, move_index: this.plan_position.move_index+1};
87
+ }
88
+ }else{
89
+ this.x += dir_movement.x*this.speed;
90
+ this.y -= dir_movement.y*this.speed;
91
+ this.plan_position.distance_covered += this.speed;
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ const CarStateEnum = {
98
+ Waiting: 0,
99
+ MovingToNode: 1,
100
+ Extracting: 2,
101
+
102
+ } as const;
103
+
104
+ type CarState = (typeof CarStateEnum)[keyof typeof CarStateEnum];
105
+
106
+ export class ResourceCar extends Car{
107
+ capacity: Int32;
108
+ inventory: Map<Resource.Resource, Int32>;
109
+ current_capacity: Int32;
110
+
111
+ car_state: CarState;
112
+
113
+ starting_node: Node.KeyNode;
114
+ target_node: Node.KeyNode | undefined;
115
+ is_selected: boolean;
116
+
117
+ constructor(id: Int32, starting_node: Node.KeyNode){
118
+ super(id);
119
+ this.capacity = 1;
120
+ this.inventory = new Map();
121
+ this.current_capacity = 0;
122
+ this.car_state = CarStateEnum.Waiting;
123
+ this.starting_node = starting_node;
124
+ this.is_selected = false;
125
+ this.centerCarOnNode(this.starting_node);
126
+ }
127
+ isReadyToGo(): boolean{
128
+ return this.car_state == CarStateEnum.Waiting;
129
+ }
130
+ centerCarOnNode(node: Node.KeyNode){
131
+ this.x = node.x+0.5;
132
+ this.y = node.y+0.5;
133
+ }
134
+ //findClosestResourceNode(engine: WallEngine){
135
+
136
+ ///}
137
+ }
138
+
139
+
140
+ export class CarCollection{
141
+ cars: Map<Int32, ResourceCar>;
142
+ private current_id: Int32;
143
+ constructor(){
144
+ this.cars = new Map();
145
+ this.current_id = 0;
146
+ }
147
+ addCarOnNode(node: Node.KeyNode){
148
+ this.cars.set(this.current_id, new ResourceCar(this.current_id, node));
149
+ this.current_id++;
150
+ }
151
+ get(i: Int32): ResourceCar | undefined{
152
+ return this.cars.get(i);
153
+ }
154
+ select(id: Int32){
155
+ const car = this.get(id);
156
+ if(car != undefined){
157
+ car.is_selected = true;
158
+ }
159
+ }
160
+ update(t: Float){
161
+ for(const [id, car] of this.cars){
162
+ car.update(t);
163
+ }
164
+ }
165
+ clear(){
166
+ this.cars.clear();
167
+ this.current_id = 0;
168
+ }
169
+ delete(id: Int32){
170
+ this.cars.delete(id);
171
+ }
172
+ }