@gg-web-engine/core 0.0.24 → 0.0.28

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 (47) hide show
  1. package/dist/2d/components/physics/i-rigid-body-2d.component.d.ts +1 -0
  2. package/dist/2d/gg-2d-world.d.ts +1 -2
  3. package/dist/2d/gg-2d-world.js +4 -5
  4. package/dist/3d/components/physics/i-raycast-vehicle.component.d.ts +3 -6
  5. package/dist/3d/components/physics/i-rigid-body-3d.component.d.ts +1 -0
  6. package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.d.ts +11 -13
  7. package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.js +29 -72
  8. package/dist/3d/entities/controllers/input/gg-car-keyboard-handling.controller.d.ts +18 -0
  9. package/dist/3d/entities/controllers/input/gg-car-keyboard-handling.controller.js +96 -0
  10. package/dist/3d/entities/gg-car/gg-car.entity.d.ts +79 -0
  11. package/dist/3d/entities/gg-car/gg-car.entity.js +228 -0
  12. package/dist/3d/entities/raycast-vehicle-3d.entity.d.ts +43 -76
  13. package/dist/3d/entities/raycast-vehicle-3d.entity.js +78 -299
  14. package/dist/3d/gg-3d-world.d.ts +1 -2
  15. package/dist/3d/gg-3d-world.js +4 -5
  16. package/dist/3d/index.d.ts +2 -0
  17. package/dist/3d/index.js +2 -0
  18. package/dist/base/components/physics/i-body.component.d.ts +14 -0
  19. package/dist/base/components/physics/i-body.component.js +1 -0
  20. package/dist/base/components/physics/i-rigid-body.component.d.ts +4 -11
  21. package/dist/base/components/physics/i-trigger.component.d.ts +3 -1
  22. package/dist/base/entities/i-entity.js +1 -1
  23. package/dist/base/gg-world.d.ts +8 -12
  24. package/dist/base/gg-world.js +32 -64
  25. package/dist/base/index.d.ts +2 -3
  26. package/dist/base/index.js +2 -3
  27. package/dist/base/math/point2.d.ts +4 -0
  28. package/dist/base/math/point2.js +8 -0
  29. package/dist/base/math/point3.d.ts +6 -0
  30. package/dist/base/math/point3.js +12 -0
  31. package/dist/base/math/splines.d.ts +1 -0
  32. package/dist/base/math/splines.js +7 -0
  33. package/dist/{base/ui → dev}/gg-console.ui.d.ts +1 -4
  34. package/dist/{base/ui → dev}/gg-console.ui.js +35 -17
  35. package/dist/dev/gg-debugger.ui.d.ts +11 -0
  36. package/dist/dev/gg-debugger.ui.js +111 -0
  37. package/dist/dev/gg-static.d.ts +32 -0
  38. package/dist/dev/gg-static.js +141 -0
  39. package/dist/dev/index.d.ts +3 -0
  40. package/dist/dev/index.js +3 -0
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.js +1 -0
  43. package/package.json +1 -1
  44. package/dist/base/gg-static.d.ts +0 -9
  45. package/dist/base/gg-static.js +0 -36
  46. package/dist/base/ui/gg-debugger.ui.d.ts +0 -10
  47. package/dist/base/ui/gg-debugger.ui.js +0 -61
@@ -0,0 +1,141 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { GgWorld } from '../base';
11
+ import { GgConsoleUI } from './gg-console.ui';
12
+ import { GgDebuggerUI } from './gg-debugger.ui';
13
+ export class GgStatic {
14
+ constructor() {
15
+ this.debuggerUI = new GgDebuggerUI();
16
+ this.consoleUI = new GgConsoleUI();
17
+ this._devConsoleEnabled = false;
18
+ this.consoleKeyPressEventListener = (event) => {
19
+ if (event.code === 'Backquote') {
20
+ event.preventDefault();
21
+ if (this.consoleUI.isUIShown) {
22
+ this.consoleUI.destroyUI();
23
+ }
24
+ else {
25
+ this.consoleUI.createUI();
26
+ }
27
+ }
28
+ };
29
+ this._selectedWorld = null;
30
+ this.consoleCommands = new Map();
31
+ this.registerConsoleCommand(null, 'ls_commands', () => __awaiter(this, void 0, void 0, function* () {
32
+ return this.availableCommands
33
+ .map(([key, value]) => `<span style="color:yellow">${key}</span>${value.doc ? '\t<span style="color:#aaa">// ' + value.doc + '</span>' : ''}`)
34
+ .sort()
35
+ .join('\n\n');
36
+ }), 'no args; print all available commands');
37
+ this.registerConsoleCommand(null, 'ls_worlds', () => __awaiter(this, void 0, void 0, function* () {
38
+ return GgWorld.documentWorlds
39
+ .map(w => (w === this.selectedWorld ? `<span style="color:green;">* ${w.name}</span>` : ` ${w.name}`))
40
+ .join('\n');
41
+ }), 'no args; print all available worlds');
42
+ this.registerConsoleCommand(null, 'select_world', (...args) => __awaiter(this, void 0, void 0, function* () {
43
+ var _a;
44
+ for (const w of GgWorld.documentWorlds) {
45
+ if (w.name === args[0]) {
46
+ this._selectedWorld = w;
47
+ break;
48
+ }
49
+ }
50
+ return ((_a = this.selectedWorld) === null || _a === void 0 ? void 0 : _a.name) || 'null';
51
+ }), 'args: [string]; select world by name');
52
+ }
53
+ static get instance() {
54
+ if (!GgStatic._instance) {
55
+ GgStatic._instance = new GgStatic();
56
+ }
57
+ return GgStatic._instance;
58
+ }
59
+ get devConsoleEnabled() {
60
+ return this._devConsoleEnabled;
61
+ }
62
+ set devConsoleEnabled(value) {
63
+ if (this._devConsoleEnabled === value) {
64
+ return;
65
+ }
66
+ this._devConsoleEnabled = value;
67
+ if (value) {
68
+ addEventListener('keypress', this.consoleKeyPressEventListener);
69
+ }
70
+ else {
71
+ removeEventListener('keypress', this.consoleKeyPressEventListener);
72
+ if (this.consoleUI.isUIShown) {
73
+ this.consoleUI.destroyUI();
74
+ }
75
+ }
76
+ }
77
+ get showStats() {
78
+ return this.debuggerUI.showStats;
79
+ }
80
+ set showStats(value) {
81
+ this.debuggerUI.setShowStats(this.selectedWorld, value);
82
+ }
83
+ get showDebugControls() {
84
+ return this.debuggerUI.showDebugControls;
85
+ }
86
+ set showDebugControls(value) {
87
+ this.debuggerUI.setShowDebugControls(this.selectedWorld, value);
88
+ }
89
+ get selectedWorld() {
90
+ return this._selectedWorld || GgWorld.documentWorlds[0] || null;
91
+ }
92
+ get availableCommands() {
93
+ let commands = this.consoleCommands.get(null) || {};
94
+ if (this.selectedWorld) {
95
+ commands = Object.assign(Object.assign({}, (this.consoleCommands.get(this.selectedWorld) || {})), commands);
96
+ }
97
+ return Object.entries(commands);
98
+ }
99
+ registerConsoleCommand(world, command, handler, doc) {
100
+ let commands = {};
101
+ if (!this.consoleCommands.has(world)) {
102
+ this.consoleCommands.set(world, commands);
103
+ }
104
+ else {
105
+ commands = this.consoleCommands.get(world);
106
+ }
107
+ commands[command] = { handler, doc };
108
+ }
109
+ deregisterWorldCommands(world) {
110
+ this.consoleCommands.delete(world);
111
+ }
112
+ console(input) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const commands = input.split('\n');
115
+ let output = [];
116
+ for (const command of commands) {
117
+ const parts = command.split(' ');
118
+ output.push(yield this.runConsoleCommand(parts.splice(0, 1)[0], parts));
119
+ }
120
+ return output.join('\n');
121
+ });
122
+ }
123
+ runConsoleCommand(command, args) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ let action = (this.consoleCommands.get(null) || {})[command];
126
+ if (!action) {
127
+ action = (this.consoleCommands.get(this.selectedWorld) || {})[command];
128
+ if (!action) {
129
+ return `<span style="color:red">Unrecognized command: ${command}</span>`;
130
+ }
131
+ }
132
+ try {
133
+ return yield action.handler(...args);
134
+ }
135
+ catch (err) {
136
+ return `<span style="color:red">${err}</span>`;
137
+ }
138
+ });
139
+ }
140
+ }
141
+ window.ggstatic = GgStatic.instance;
@@ -0,0 +1,3 @@
1
+ export * from './gg-console.ui';
2
+ export * from './gg-debugger.ui';
3
+ export * from './gg-static';
@@ -0,0 +1,3 @@
1
+ export * from './gg-console.ui';
2
+ export * from './gg-debugger.ui';
3
+ export * from './gg-static';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './base';
2
2
  export * from './2d';
3
3
  export * from './3d';
4
+ export * from './dev';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './base';
2
2
  export * from './2d';
3
3
  export * from './3d';
4
+ export * from './dev';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/core",
3
- "version": "0.0.24",
3
+ "version": "0.0.28",
4
4
  "description": "An attempt to create open source game engine for browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,9 +0,0 @@
1
- import { GgWorld } from './gg-world';
2
- export declare class GgStatic {
3
- private static _instance;
4
- static get instance(): GgStatic;
5
- private constructor();
6
- readonly worlds: GgWorld<any, any>[];
7
- selectedWorld: GgWorld<any, any> | null;
8
- console(input: string): Promise<string>;
9
- }
@@ -1,36 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export class GgStatic {
11
- constructor() {
12
- this.worlds = [];
13
- this.selectedWorld = null;
14
- window.gg = this;
15
- }
16
- static get instance() {
17
- if (!GgStatic._instance) {
18
- GgStatic._instance = new GgStatic();
19
- }
20
- return GgStatic._instance;
21
- }
22
- console(input) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if (!this.selectedWorld) {
25
- return 'World not selected';
26
- }
27
- const commands = input.split('\n');
28
- let output = [];
29
- for (const command of commands) {
30
- const parts = command.split(' ');
31
- output.push(yield this.selectedWorld.runConsoleCommand(parts.splice(0, 1)[0], parts));
32
- }
33
- return output.join('\n');
34
- });
35
- }
36
- }
@@ -1,10 +0,0 @@
1
- export declare class GgDebuggerUI {
2
- private static _instance;
3
- static get instance(): GgDebuggerUI;
4
- private ui;
5
- private removed$;
6
- private constructor();
7
- get isUIShown(): boolean;
8
- createUI(): void;
9
- destroyUI(): void;
10
- }
@@ -1,61 +0,0 @@
1
- import { GgStatic } from '../gg-static';
2
- import { createInlineTickController } from '../entities/controllers/inline-controller';
3
- import { fromEvent, Subject, takeUntil } from 'rxjs';
4
- import Stats from 'stats.js';
5
- export class GgDebuggerUI {
6
- constructor() {
7
- this.ui = null;
8
- this.removed$ = new Subject();
9
- }
10
- static get instance() {
11
- if (!this._instance) {
12
- this._instance = new GgDebuggerUI();
13
- }
14
- return this._instance;
15
- }
16
- get isUIShown() {
17
- return !!this.ui;
18
- }
19
- createUI() {
20
- var _a;
21
- const stats = new Stats();
22
- stats.dom.style.left = 'unset';
23
- stats.dom.style.right = '0';
24
- stats.showPanel(0); // 0: fps, 1: ms, 2: mb
25
- document.body.appendChild(stats.dom);
26
- createInlineTickController(GgStatic.instance.selectedWorld, -1)
27
- .pipe(takeUntil(this.removed$))
28
- .subscribe(() => {
29
- stats === null || stats === void 0 ? void 0 : stats.begin();
30
- });
31
- createInlineTickController(GgStatic.instance.selectedWorld, 10000)
32
- .pipe(takeUntil(this.removed$))
33
- .subscribe(() => {
34
- stats === null || stats === void 0 ? void 0 : stats.end();
35
- });
36
- const customContainer = document.createElement('div');
37
- customContainer.style.cssText =
38
- 'position:fixed;top:48px;right:0;opacity:0.9;z-index:9999;background-color:#333;color:white';
39
- customContainer.innerHTML = `<input type="checkbox" name="checkbox" id="physics_debugger_checkbox_id" value="1"${((_a = GgStatic.instance.selectedWorld) === null || _a === void 0 ? void 0 : _a.physicsWorld.physicsDebugViewActive) ? ' checked' : ''}>
40
- <label for="physics_debugger_checkbox_id" style="user-select: none;">Show physics bodies in scene</label>`;
41
- document.body.appendChild(customContainer);
42
- fromEvent(document.getElementById('physics_debugger_checkbox_id'), 'change')
43
- .pipe(takeUntil(this.removed$))
44
- .subscribe(e => {
45
- GgStatic.instance.console('dr_drawphysics ' + e.target.checked).then();
46
- });
47
- this.ui = {
48
- stats,
49
- customContainer,
50
- };
51
- }
52
- destroyUI() {
53
- if (this.ui) {
54
- document.body.removeChild(this.ui.stats.dom);
55
- document.body.removeChild(this.ui.customContainer);
56
- this.ui.stats.end();
57
- this.ui = null;
58
- }
59
- this.removed$.next();
60
- }
61
- }