tscratch 0.8.6 → 0.9.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.
@@ -68,6 +68,7 @@ declare abstract class Sprite {
68
68
  changeSize(dS: number): void;
69
69
  goToLayer(layer: number): void;
70
70
  changeLayer(dL: number): void;
71
+ static getSpriteByTagName(tag: string): Sprite[];
71
72
  protected getDrawOffset(): [number, number];
72
73
  }
73
74
 
@@ -89,13 +90,15 @@ declare class Engine {
89
90
  mouseX: number;
90
91
  mouseY: number;
91
92
  mouseDown: boolean;
92
- mouseClicked: boolean;
93
+ private primaryPointerId;
94
+ private activeJoystick;
93
95
  private keysPressed;
94
- private currentScene;
96
+ currentScene: string;
95
97
  sceneMap: SceneMap;
96
98
  private variableMap;
97
99
  static init(): Engine;
98
100
  private constructor();
101
+ private updateJoysticks;
99
102
  setScene(scene: string): void;
100
103
  setLoop(scene: string, loop: GameLoop): void;
101
104
  pauseLoop(): void;
@@ -195,12 +198,28 @@ declare class InverseKinematics {
195
198
  getPoints(): Vec2[];
196
199
  private static dot;
197
200
  computeApproximateAngles(iterations: number, error: number, adjustmentRate?: number): void;
198
- forwardKinematicsPass(): Vec2;
199
- computeError(): Vec2;
201
+ private forwardKinematicsPass;
202
+ private computeError;
200
203
  private computeJacobian;
201
204
  private computePseudoinverse;
202
205
  private computeJointUpdate;
203
- updateAngles(adjustmentRate: number): void;
206
+ private updateAngles;
207
+ }
208
+
209
+ declare class PathFinder {
210
+ private obstacles;
211
+ private target;
212
+ private tileSize;
213
+ private checking;
214
+ private maxNodes;
215
+ search(startX: number, startY: number): Vec2[] | null;
216
+ private buildPath;
217
+ private isInBounds;
218
+ private isColliding;
219
+ setTileSize(tileSize: number): void;
220
+ setObstacles(obstacles: Sprite[]): void;
221
+ setTarget(target: Sprite): void;
222
+ constructor(target: Sprite, obstacles?: Sprite[]);
204
223
  }
205
224
 
206
225
  declare class Multiplayer {
@@ -213,6 +232,33 @@ declare class Multiplayer {
213
232
  on<T = unknown>(eventName: string, callback: (data: T) => void): void;
214
233
  }
215
234
 
235
+ interface LineOptions extends SpriteOptions {
236
+ color?: string;
237
+ length?: number;
238
+ width?: number;
239
+ }
240
+ declare class Line extends Sprite {
241
+ discriminant: string;
242
+ tags: Set<string>;
243
+ color: string;
244
+ length: number;
245
+ width: number;
246
+ getBoundingBox(): {
247
+ x: number;
248
+ y: number;
249
+ width: number;
250
+ height: number;
251
+ };
252
+ getPath(): Path2D;
253
+ draw(stamping?: true): void;
254
+ create(options?: LineOptions): this;
255
+ protected getCreateOptions(): LineOptions;
256
+ setColor(color: string): void;
257
+ setLength(length: number): void;
258
+ setWidth(width: number): void;
259
+ constructor(options?: LineOptions);
260
+ }
261
+
216
262
  interface RectangleOptions extends SpriteOptions {
217
263
  width?: number;
218
264
  height?: number;
@@ -232,21 +278,7 @@ declare class Rectangle extends Sprite {
232
278
  getPath(): Path2D;
233
279
  draw(stamping?: true): void;
234
280
  create(options?: RectangleOptions): this;
235
- protected getCreateOptions(): {
236
- width: number;
237
- height: number;
238
- color: string;
239
- outlineColor: string;
240
- outlineWidth: number;
241
- x?: number;
242
- y?: number;
243
- dir?: number;
244
- size?: number;
245
- pivot?: Vec2;
246
- scene?: string;
247
- hidden?: boolean;
248
- layer?: number;
249
- };
281
+ protected getCreateOptions(): RectangleOptions;
250
282
  setWidth(width: number): void;
251
283
  setHeight(height: number): void;
252
284
  setColor(color: string): void;
@@ -542,7 +574,6 @@ declare class Text extends Sprite {
542
574
  fontSize: number;
543
575
  align: CanvasTextAlign;
544
576
  baseline: CanvasTextBaseline;
545
- private font;
546
577
  getBoundingBox(): BoundingBox;
547
578
  getPath(): Path2D;
548
579
  draw(stamping?: true): void;
@@ -704,6 +735,36 @@ declare class RigidRectangle extends Rectangle implements RigidBodyOptions {
704
735
  constructor(options?: RigidRectangleOptions);
705
736
  }
706
737
 
738
+ interface JoystickOptions extends SpriteOptions {
739
+ radius: number;
740
+ }
741
+ declare class Joystick extends Sprite {
742
+ tags: Set<string>;
743
+ discriminant: string;
744
+ radius: number;
745
+ private thumbRadius;
746
+ private sizeRatio;
747
+ joyX: number;
748
+ joyY: number;
749
+ getBoundingBox(): BoundingBox;
750
+ getPath(): Path2D;
751
+ draw(stamping?: true): void;
752
+ protected create(options?: JoystickOptions): this;
753
+ protected getCreateOptions(): {
754
+ radius: number;
755
+ x?: number;
756
+ y?: number;
757
+ dir?: number;
758
+ size?: number;
759
+ pivot?: Vec2;
760
+ scene?: string;
761
+ hidden?: boolean;
762
+ layer?: number;
763
+ };
764
+ setRadius(radius: number): void;
765
+ constructor(options?: JoystickOptions);
766
+ }
767
+
707
768
  interface Camera3DOptions {
708
769
  x: number;
709
770
  y: number;
@@ -894,7 +955,9 @@ declare const TScratch: {
894
955
  Perlin1D: typeof Perlin1D;
895
956
  Perlin2D: typeof Perlin2D;
896
957
  InverseKinematics: typeof InverseKinematics;
958
+ PathFinder: typeof PathFinder;
897
959
  Multiplayer: typeof Multiplayer;
960
+ Line: typeof Line;
898
961
  Rectangle: typeof Rectangle;
899
962
  Square: typeof Square;
900
963
  Oval: typeof Oval;
@@ -908,6 +971,7 @@ declare const TScratch: {
908
971
  Watermark: typeof Watermark;
909
972
  ImageSprite: typeof ImageSprite;
910
973
  RigidRectangle: typeof RigidRectangle;
974
+ Joystick: typeof Joystick;
911
975
  Camera3D: typeof Camera3D;
912
976
  Renderer3D: typeof Renderer3D;
913
977
  WireframeRenderer3D: typeof WireframeRenderer3D;
@@ -928,4 +992,4 @@ declare const TScratch: {
928
992
  ctx: CanvasRenderingContext2D;
929
993
  };
930
994
 
931
- export { Arc, type ArcOptions, Button, type ButtonOptions, Camera3D, type Camera3DOptions, Circle, type CircleOptions, Cube, Cuboid, type CuboidOptions, CustomPolygon, type CustomPolygonOptions, Engine, Icosahedron, Icosphere, ImageSprite, type ImageSpriteOptions, InverseKinematics, type Mat2, type Mat3, type Mat4, Monkey, Multiplayer, Object3D, type Object3DOptions, Octahedron, Oval, type OvalOptions, Pen, type PenOptions, Perlin1D, Perlin2D, Rectangle, type RectangleOptions, RegularPolygon, type RegularPolygonOptions, Renderer3D, type Renderer3DOptions, type RigidBody, type RigidBodyOptions, RigidRectangle, type RigidRectangleOptions, SolidRenderer3D, Sprite, type SpriteOptions, Square, type SquareOptions, TSCMath, Tetrahedron, Text, type TextOptions, type Vec2, type Vec3, type Vec4, Watermark, type TextOptions as WatermarkOptions, WireframeRenderer3D, aspectRatio, canvas, ctx, TScratch as default, scale, setAspectRatio, setScale };
995
+ export { Arc, type ArcOptions, Button, type ButtonOptions, Camera3D, type Camera3DOptions, Circle, type CircleOptions, Cube, Cuboid, type CuboidOptions, CustomPolygon, type CustomPolygonOptions, Engine, Icosahedron, Icosphere, ImageSprite, type ImageSpriteOptions, InverseKinematics, Joystick, type JoystickOptions, Line, type LineOptions, type Mat2, type Mat3, type Mat4, Monkey, Multiplayer, Object3D, type Object3DOptions, Octahedron, Oval, type OvalOptions, PathFinder, Pen, type PenOptions, Perlin1D, Perlin2D, Rectangle, type RectangleOptions, RegularPolygon, type RegularPolygonOptions, Renderer3D, type Renderer3DOptions, type RigidBody, type RigidBodyOptions, RigidRectangle, type RigidRectangleOptions, SolidRenderer3D, Sprite, type SpriteOptions, Square, type SquareOptions, TSCMath, Tetrahedron, Text, type TextOptions, type Vec2, type Vec3, type Vec4, Watermark, type TextOptions as WatermarkOptions, WireframeRenderer3D, aspectRatio, canvas, ctx, TScratch as default, scale, setAspectRatio, setScale };
@@ -68,6 +68,7 @@ declare abstract class Sprite {
68
68
  changeSize(dS: number): void;
69
69
  goToLayer(layer: number): void;
70
70
  changeLayer(dL: number): void;
71
+ static getSpriteByTagName(tag: string): Sprite[];
71
72
  protected getDrawOffset(): [number, number];
72
73
  }
73
74
 
@@ -89,13 +90,15 @@ declare class Engine {
89
90
  mouseX: number;
90
91
  mouseY: number;
91
92
  mouseDown: boolean;
92
- mouseClicked: boolean;
93
+ private primaryPointerId;
94
+ private activeJoystick;
93
95
  private keysPressed;
94
- private currentScene;
96
+ currentScene: string;
95
97
  sceneMap: SceneMap;
96
98
  private variableMap;
97
99
  static init(): Engine;
98
100
  private constructor();
101
+ private updateJoysticks;
99
102
  setScene(scene: string): void;
100
103
  setLoop(scene: string, loop: GameLoop): void;
101
104
  pauseLoop(): void;
@@ -195,12 +198,28 @@ declare class InverseKinematics {
195
198
  getPoints(): Vec2[];
196
199
  private static dot;
197
200
  computeApproximateAngles(iterations: number, error: number, adjustmentRate?: number): void;
198
- forwardKinematicsPass(): Vec2;
199
- computeError(): Vec2;
201
+ private forwardKinematicsPass;
202
+ private computeError;
200
203
  private computeJacobian;
201
204
  private computePseudoinverse;
202
205
  private computeJointUpdate;
203
- updateAngles(adjustmentRate: number): void;
206
+ private updateAngles;
207
+ }
208
+
209
+ declare class PathFinder {
210
+ private obstacles;
211
+ private target;
212
+ private tileSize;
213
+ private checking;
214
+ private maxNodes;
215
+ search(startX: number, startY: number): Vec2[] | null;
216
+ private buildPath;
217
+ private isInBounds;
218
+ private isColliding;
219
+ setTileSize(tileSize: number): void;
220
+ setObstacles(obstacles: Sprite[]): void;
221
+ setTarget(target: Sprite): void;
222
+ constructor(target: Sprite, obstacles?: Sprite[]);
204
223
  }
205
224
 
206
225
  declare class Multiplayer {
@@ -213,6 +232,33 @@ declare class Multiplayer {
213
232
  on<T = unknown>(eventName: string, callback: (data: T) => void): void;
214
233
  }
215
234
 
235
+ interface LineOptions extends SpriteOptions {
236
+ color?: string;
237
+ length?: number;
238
+ width?: number;
239
+ }
240
+ declare class Line extends Sprite {
241
+ discriminant: string;
242
+ tags: Set<string>;
243
+ color: string;
244
+ length: number;
245
+ width: number;
246
+ getBoundingBox(): {
247
+ x: number;
248
+ y: number;
249
+ width: number;
250
+ height: number;
251
+ };
252
+ getPath(): Path2D;
253
+ draw(stamping?: true): void;
254
+ create(options?: LineOptions): this;
255
+ protected getCreateOptions(): LineOptions;
256
+ setColor(color: string): void;
257
+ setLength(length: number): void;
258
+ setWidth(width: number): void;
259
+ constructor(options?: LineOptions);
260
+ }
261
+
216
262
  interface RectangleOptions extends SpriteOptions {
217
263
  width?: number;
218
264
  height?: number;
@@ -232,21 +278,7 @@ declare class Rectangle extends Sprite {
232
278
  getPath(): Path2D;
233
279
  draw(stamping?: true): void;
234
280
  create(options?: RectangleOptions): this;
235
- protected getCreateOptions(): {
236
- width: number;
237
- height: number;
238
- color: string;
239
- outlineColor: string;
240
- outlineWidth: number;
241
- x?: number;
242
- y?: number;
243
- dir?: number;
244
- size?: number;
245
- pivot?: Vec2;
246
- scene?: string;
247
- hidden?: boolean;
248
- layer?: number;
249
- };
281
+ protected getCreateOptions(): RectangleOptions;
250
282
  setWidth(width: number): void;
251
283
  setHeight(height: number): void;
252
284
  setColor(color: string): void;
@@ -542,7 +574,6 @@ declare class Text extends Sprite {
542
574
  fontSize: number;
543
575
  align: CanvasTextAlign;
544
576
  baseline: CanvasTextBaseline;
545
- private font;
546
577
  getBoundingBox(): BoundingBox;
547
578
  getPath(): Path2D;
548
579
  draw(stamping?: true): void;
@@ -704,6 +735,36 @@ declare class RigidRectangle extends Rectangle implements RigidBodyOptions {
704
735
  constructor(options?: RigidRectangleOptions);
705
736
  }
706
737
 
738
+ interface JoystickOptions extends SpriteOptions {
739
+ radius: number;
740
+ }
741
+ declare class Joystick extends Sprite {
742
+ tags: Set<string>;
743
+ discriminant: string;
744
+ radius: number;
745
+ private thumbRadius;
746
+ private sizeRatio;
747
+ joyX: number;
748
+ joyY: number;
749
+ getBoundingBox(): BoundingBox;
750
+ getPath(): Path2D;
751
+ draw(stamping?: true): void;
752
+ protected create(options?: JoystickOptions): this;
753
+ protected getCreateOptions(): {
754
+ radius: number;
755
+ x?: number;
756
+ y?: number;
757
+ dir?: number;
758
+ size?: number;
759
+ pivot?: Vec2;
760
+ scene?: string;
761
+ hidden?: boolean;
762
+ layer?: number;
763
+ };
764
+ setRadius(radius: number): void;
765
+ constructor(options?: JoystickOptions);
766
+ }
767
+
707
768
  interface Camera3DOptions {
708
769
  x: number;
709
770
  y: number;
@@ -894,7 +955,9 @@ declare const TScratch: {
894
955
  Perlin1D: typeof Perlin1D;
895
956
  Perlin2D: typeof Perlin2D;
896
957
  InverseKinematics: typeof InverseKinematics;
958
+ PathFinder: typeof PathFinder;
897
959
  Multiplayer: typeof Multiplayer;
960
+ Line: typeof Line;
898
961
  Rectangle: typeof Rectangle;
899
962
  Square: typeof Square;
900
963
  Oval: typeof Oval;
@@ -908,6 +971,7 @@ declare const TScratch: {
908
971
  Watermark: typeof Watermark;
909
972
  ImageSprite: typeof ImageSprite;
910
973
  RigidRectangle: typeof RigidRectangle;
974
+ Joystick: typeof Joystick;
911
975
  Camera3D: typeof Camera3D;
912
976
  Renderer3D: typeof Renderer3D;
913
977
  WireframeRenderer3D: typeof WireframeRenderer3D;
@@ -928,4 +992,4 @@ declare const TScratch: {
928
992
  ctx: CanvasRenderingContext2D;
929
993
  };
930
994
 
931
- export { Arc, type ArcOptions, Button, type ButtonOptions, Camera3D, type Camera3DOptions, Circle, type CircleOptions, Cube, Cuboid, type CuboidOptions, CustomPolygon, type CustomPolygonOptions, Engine, Icosahedron, Icosphere, ImageSprite, type ImageSpriteOptions, InverseKinematics, type Mat2, type Mat3, type Mat4, Monkey, Multiplayer, Object3D, type Object3DOptions, Octahedron, Oval, type OvalOptions, Pen, type PenOptions, Perlin1D, Perlin2D, Rectangle, type RectangleOptions, RegularPolygon, type RegularPolygonOptions, Renderer3D, type Renderer3DOptions, type RigidBody, type RigidBodyOptions, RigidRectangle, type RigidRectangleOptions, SolidRenderer3D, Sprite, type SpriteOptions, Square, type SquareOptions, TSCMath, Tetrahedron, Text, type TextOptions, type Vec2, type Vec3, type Vec4, Watermark, type TextOptions as WatermarkOptions, WireframeRenderer3D, aspectRatio, canvas, ctx, TScratch as default, scale, setAspectRatio, setScale };
995
+ export { Arc, type ArcOptions, Button, type ButtonOptions, Camera3D, type Camera3DOptions, Circle, type CircleOptions, Cube, Cuboid, type CuboidOptions, CustomPolygon, type CustomPolygonOptions, Engine, Icosahedron, Icosphere, ImageSprite, type ImageSpriteOptions, InverseKinematics, Joystick, type JoystickOptions, Line, type LineOptions, type Mat2, type Mat3, type Mat4, Monkey, Multiplayer, Object3D, type Object3DOptions, Octahedron, Oval, type OvalOptions, PathFinder, Pen, type PenOptions, Perlin1D, Perlin2D, Rectangle, type RectangleOptions, RegularPolygon, type RegularPolygonOptions, Renderer3D, type Renderer3DOptions, type RigidBody, type RigidBodyOptions, RigidRectangle, type RigidRectangleOptions, SolidRenderer3D, Sprite, type SpriteOptions, Square, type SquareOptions, TSCMath, Tetrahedron, Text, type TextOptions, type Vec2, type Vec3, type Vec4, Watermark, type TextOptions as WatermarkOptions, WireframeRenderer3D, aspectRatio, canvas, ctx, TScratch as default, scale, setAspectRatio, setScale };