@rpgjs/client 4.0.2 → 4.0.4

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 (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/browser/React-ab9e74c2.js +127 -0
  3. package/browser/manifest.json +5 -0
  4. package/browser/rpg.client.js +435 -362
  5. package/browser/rpg.client.umd.cjs +573 -375
  6. package/lib/Components/Component.js +6 -0
  7. package/lib/Components/Component.js.map +1 -1
  8. package/lib/GameEngine.d.ts +1 -0
  9. package/lib/GameEngine.js +6 -2
  10. package/lib/GameEngine.js.map +1 -1
  11. package/lib/{RpgGui.d.ts → Gui/Gui.d.ts} +27 -20
  12. package/lib/Gui/Gui.js +497 -0
  13. package/lib/Gui/Gui.js.map +1 -0
  14. package/lib/Gui/React.d.ts +14 -0
  15. package/lib/Gui/React.js +89 -0
  16. package/lib/Gui/React.js.map +1 -0
  17. package/lib/Gui/Vue.d.ts +13 -0
  18. package/lib/{RpgGuiCompiled.js → Gui/Vue.js} +64 -11
  19. package/lib/Gui/Vue.js.map +1 -0
  20. package/lib/Renderer.js +6 -4
  21. package/lib/Renderer.js.map +1 -1
  22. package/lib/RpgClientEngine.js +1 -1
  23. package/lib/RpgClientEngine.js.map +1 -1
  24. package/lib/Scene/Scene.d.ts +26 -1
  25. package/lib/Scene/Scene.js +32 -3
  26. package/lib/Scene/Scene.js.map +1 -1
  27. package/lib/index.d.ts +2 -1
  28. package/lib/index.js +2 -1
  29. package/lib/index.js.map +1 -1
  30. package/package.json +21 -6
  31. package/rpg.toml +1 -1
  32. package/src/Components/Component.ts +6 -0
  33. package/src/GameEngine.ts +7 -3
  34. package/src/Gui/Gui.ts +556 -0
  35. package/src/Gui/React.ts +116 -0
  36. package/src/Gui/Vue.ts +137 -0
  37. package/src/Renderer.ts +8 -4
  38. package/src/RpgClientEngine.ts +1 -1
  39. package/src/Scene/Scene.ts +35 -4
  40. package/src/index.ts +2 -1
  41. package/lib/RpgGui.js +0 -499
  42. package/lib/RpgGui.js.map +0 -1
  43. package/lib/RpgGuiCompiled.d.ts +0 -3
  44. package/lib/RpgGuiCompiled.js.map +0 -1
  45. package/src/RpgGui.ts +0 -553
  46. package/src/RpgGuiCompiled.ts +0 -43
package/src/Gui/Vue.ts ADDED
@@ -0,0 +1,137 @@
1
+ import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, resolveDynamicComponent as _resolveDynamicComponent, normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, createBlock as _createBlock, mergeProps as _mergeProps, createCommentVNode as _createCommentVNode, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode } from "vue"
2
+ import { App, ComponentPublicInstance, createApp } from 'vue'
3
+ import { RpgCommonPlayer, Utils } from '@rpgjs/common'
4
+ import { RpgRenderer } from '../Renderer'
5
+ import { GameEngineClient } from '../GameEngine'
6
+ import { RpgClientEngine } from '../RpgClientEngine'
7
+ import type { Gui } from './Gui'
8
+ import { Scene } from '../Scene/Scene'
9
+
10
+ interface VueInstance extends ComponentPublicInstance {
11
+ gui: GuiList,
12
+ tooltips: RpgCommonPlayer[]
13
+ }
14
+
15
+ interface GuiOptions {
16
+ data: any,
17
+ attachToSprite: boolean
18
+ display: boolean,
19
+ name: string
20
+ }
21
+
22
+ interface GuiList {
23
+ [guiName: string]: GuiOptions
24
+ }
25
+
26
+ interface VueInstance extends ComponentPublicInstance {
27
+ gui: GuiList,
28
+ tooltips: RpgCommonPlayer[]
29
+ }
30
+
31
+ const _hoisted_1 = {
32
+ id: "tooltips",
33
+ style: { "position": "absolute", "top": "0", "left": "0" }
34
+ }
35
+ function render(_ctx, _cache) {
36
+ return (_openBlock(), _createElementBlock("div", {}, [
37
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.fixedGui, (ui) => {
38
+ return (_openBlock(), _createElementBlock(_Fragment, null, [
39
+ (ui.display)
40
+ ? (_openBlock(), _createBlock(_resolveDynamicComponent(ui.name), _normalizeProps(_mergeProps({ key: 0 }, ui.data)), null, 16 /* FULL_PROPS */))
41
+ : _createCommentVNode("v-if", true)
42
+ ], 64 /* STABLE_FRAGMENT */))
43
+ }), 256 /* UNKEYED_FRAGMENT */)),
44
+ _createElementVNode("div", _hoisted_1, [
45
+ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.attachedGui, (ui) => {
46
+ return (_openBlock(), _createElementBlock(_Fragment, null, [
47
+ (ui.display)
48
+ ? (_openBlock(true), _createElementBlock(_Fragment, { key: 0 }, _renderList(_ctx.tooltipFilter(_ctx.tooltips, ui), (tooltip) => {
49
+ return (_openBlock(), _createElementBlock("div", {
50
+ style: _normalizeStyle(_ctx.tooltipPosition(tooltip.position))
51
+ }, [
52
+ (_openBlock(), _createBlock(_resolveDynamicComponent(ui.name), _mergeProps({ ...ui.data, spriteData: tooltip }, {
53
+ ref_for: true,
54
+ ref: ui.name
55
+ }), null, 16 /* FULL_PROPS */))
56
+ ], 4 /* STYLE */))
57
+ }), 256 /* UNKEYED_FRAGMENT */))
58
+ : _createCommentVNode("v-if", true)
59
+ ], 64 /* STABLE_FRAGMENT */))
60
+ }), 256 /* UNKEYED_FRAGMENT */))
61
+ ])
62
+ ], 32 /* HYDRATE_EVENTS */))
63
+ }
64
+
65
+
66
+ export class VueGui {
67
+ private renderer: RpgRenderer
68
+ private gameEngine: GameEngineClient
69
+ private clientEngine: RpgClientEngine
70
+ private app: App
71
+ private vm: VueInstance
72
+ private socket
73
+
74
+ constructor(rootEl: HTMLDivElement, private parentGui: Gui) {
75
+ this.clientEngine = parentGui.clientEngine
76
+ this.renderer = this.clientEngine.renderer
77
+ this.gameEngine = this.clientEngine.gameEngine
78
+ const { gui } = parentGui
79
+ const self = this
80
+
81
+ const obj = {
82
+ render,
83
+ data() {
84
+ return {
85
+ gui: {},
86
+ tooltips: []
87
+ }
88
+ },
89
+ provide: () => {
90
+ return parentGui.getInjectObject()
91
+ },
92
+ computed: {
93
+ fixedGui() {
94
+ return Object.values(this.gui).filter((gui: any) => !gui.attachToSprite)
95
+ },
96
+ attachedGui() {
97
+ return Object.values(this.gui).filter((gui: any) => gui.attachToSprite)
98
+ }
99
+ },
100
+ methods: {
101
+ tooltipPosition: parentGui.tooltipPosition.bind(parentGui),
102
+ tooltipFilter: parentGui.tooltipFilter.bind(parentGui)
103
+ },
104
+ mounted() {
105
+
106
+ }
107
+ }
108
+
109
+ this.app = createApp(obj)
110
+
111
+ const guiVue = Object.values(gui).filter(ui => !Utils.isFunction(ui))
112
+
113
+ for (let ui of guiVue) {
114
+ this.app.component(ui.name, ui.gui)
115
+ }
116
+
117
+ this.vm = this.app.mount(rootEl) as VueInstance
118
+ this.renderer.app = this.app
119
+ this.renderer.vm = this.vm
120
+ }
121
+
122
+ _setSceneReady() {
123
+ this.parentGui.listenTooltipObjects.subscribe((tooltips) => {
124
+ this.vm.tooltips = [...tooltips]
125
+ })
126
+ this.parentGui.currentScene?.objectsMoving.next({})
127
+ }
128
+
129
+ set gui(val) {
130
+ for (let key in val) {
131
+ // ignore react component
132
+ if (val[key].isFunction) continue
133
+ this.vm.gui[key] = val[key]
134
+ }
135
+ this.vm.gui = Object.assign({}, this.vm.gui)
136
+ }
137
+ }
package/src/Renderer.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { RpgPlugin, HookClient } from '@rpgjs/common'
1
+ import { RpgPlugin, HookClient, Utils } from '@rpgjs/common'
2
2
  import { SceneMap } from './Scene/Map'
3
3
  import { Scene } from './Scene/Scene'
4
4
  import { Scene as PresetScene } from './Presets/Scene'
5
- import { RpgGui } from './RpgGui'
5
+ import { RpgGui } from './Gui/Gui'
6
6
  import { RpgClientEngine } from './RpgClientEngine'
7
7
  import type { App, ComponentPublicInstance } from 'vue'
8
8
  import { TransitionScene } from './Effects/TransitionScene'
@@ -11,6 +11,8 @@ import { GameEngineClient } from './GameEngine'
11
11
  import { SpinnerGraphic } from './Effects/Spinner'
12
12
  import { autoDetectRenderer, Container, Graphics, ICanvas, IRenderer } from 'pixi.js'
13
13
 
14
+ const { elementToPositionAbsolute } = Utils
15
+
14
16
  export enum TransitionMode {
15
17
  None,
16
18
  Fading
@@ -112,9 +114,11 @@ export class RpgRenderer {
112
114
 
113
115
  if (!this.guiEl) {
114
116
  this.guiEl = document.createElement('div')
115
- this.selector.appendChild(this.guiEl)
117
+ this.guiEl = this.selector.appendChild(this.guiEl)
116
118
  }
117
119
 
120
+ elementToPositionAbsolute(this.guiEl)
121
+
118
122
  if (!this.canvasEl) {
119
123
  this.selector.insertBefore(this.renderer.view as HTMLCanvasElement, this.selector.firstChild)
120
124
  const [canvas] = document.querySelector(this.options.selector).children
@@ -131,7 +135,7 @@ export class RpgRenderer {
131
135
  this.fadeContainer.visible = false
132
136
  this.fadeContainer.alpha = 0
133
137
 
134
- RpgGui._initalize(this.clientEngine)
138
+ RpgGui._initialize(this.clientEngine, this.guiEl)
135
139
 
136
140
  this.resize()
137
141
  }
@@ -5,7 +5,7 @@ import { _initSound, sounds } from './Sound/Sounds'
5
5
  import { World } from 'simple-room-client'
6
6
  import { BehaviorSubject, Observable, Subject, Subscription, lastValueFrom } from 'rxjs'
7
7
  import { ajax } from 'rxjs/ajax'
8
- import { RpgGui } from './RpgGui'
8
+ import { RpgGui } from './Gui/Gui'
9
9
  import {
10
10
  RpgCommonPlayer,
11
11
  PrebuiltGui,
@@ -2,12 +2,12 @@ import { RpgPlugin, HookClient, DefaultInput } from '@rpgjs/common'
2
2
  import { KeyboardControls } from '../KeyboardControls'
3
3
  import RpgSprite from '../Sprite/Character'
4
4
  import { Animation } from '../Effects/Animation'
5
- import { BehaviorSubject, Observable } from 'rxjs'
6
- import { RpgGui } from '../RpgGui'
5
+ import { BehaviorSubject, Observable, Subject } from 'rxjs'
7
6
  import { GameEngineClient } from '../GameEngine'
8
7
  import { RpgComponent } from '../Components/Component'
9
8
  import { Controls } from '@rpgjs/types'
10
9
  import { Container } from 'pixi.js'
10
+ import { RpgGui } from '../Gui/Gui'
11
11
 
12
12
  export type SceneObservableData = {
13
13
  data: {
@@ -37,6 +37,32 @@ export abstract class Scene {
37
37
  partial: {}
38
38
  })
39
39
 
40
+ /**
41
+ * Listen to the movement of objects on stage
42
+ *
43
+ * @prop {Observable<{ [key: string]: object }>} [objectsMoving]
44
+ * @readonly
45
+ * @memberof RpgScene
46
+ * @since v4.1.0
47
+ *
48
+ * In <module>/scene-map.ts
49
+ *
50
+ * ```ts
51
+ * import { RpgSceneMap } from '@rpgjs/client'
52
+ *
53
+ * export default {
54
+ * onAfterLoading(scene: RpgSceneMap) {
55
+ * scene.objectsMoving.subscribe((objects) => {
56
+ * console.log(objects)
57
+ * })
58
+ * }
59
+ * }
60
+ * ```
61
+ */
62
+ public readonly objectsMoving: Subject<{
63
+ [key: string]: any
64
+ }> = new Subject()
65
+
40
66
  constructor(public game: GameEngineClient) {
41
67
  const { globalConfig } = this.game.clientEngine
42
68
  this.controls = this.game.clientEngine.controls
@@ -45,6 +71,7 @@ export abstract class Scene {
45
71
  ...(globalConfig.inputs || {})
46
72
  }
47
73
  this.controls.setInputs(this.inputs || mergeInputs)
74
+ RpgGui._setSceneReady(this)
48
75
  }
49
76
 
50
77
  /**
@@ -106,8 +133,9 @@ export abstract class Scene {
106
133
  }
107
134
  const renderObjects = this.objects
108
135
  const sizeLogic = Object.values(logicObjects).length
136
+ const objectMoving = {}
109
137
  for (let key in logicObjects) {
110
- const val: SceneSpriteLogic = logicObjects[key].object
138
+ const val: any = logicObjects[key].object
111
139
  const valueChanged = logicObjects[key].paramsChanged
112
140
  if (!renderObjects.has(key)) {
113
141
  const sprite = this.addObject(val, key)
@@ -118,6 +146,7 @@ export abstract class Scene {
118
146
  if (!object?.update) return
119
147
  const ret = object.update(val, valueChanged, time, deltaRatio)
120
148
  this.triggerSpriteChanges(val, object, ret.moving)
149
+ if (ret.moving) objectMoving[val.id] = val
121
150
  }
122
151
  }
123
152
  if (sizeLogic < renderObjects.size) {
@@ -131,7 +160,9 @@ export abstract class Scene {
131
160
  animation.update(deltaRatio)
132
161
  }
133
162
  this.onDraw(time)
134
- RpgGui.update(logicObjects)
163
+ if (Object.values(objectMoving).length) {
164
+ this.objectsMoving.next(objectMoving)
165
+ }
135
166
  RpgPlugin.emit(HookClient.SceneDraw, this)
136
167
  }
137
168
 
package/src/index.ts CHANGED
@@ -13,9 +13,10 @@ export { Animation as AnimationClass } from './Effects/Animation'
13
13
  export type { ISpriteCharacter } from './Interfaces/Character'
14
14
  export { SceneData } from './Scene/SceneData'
15
15
  export { SceneMap as RpgSceneMap } from './Scene/Map'
16
- export { RpgGui } from './RpgGui';
16
+ export { RpgGui } from './Gui/Gui';
17
17
  export { Timeline, Ease } from './Effects/Timeline';
18
18
  export { RpgComponent, RpgComponent as RpgSprite } from './Components/Component'
19
+ export { World, room } from 'simple-room-client'
19
20
 
20
21
  import { spritesheets } from './Sprite/Spritesheets'
21
22
  import { sounds } from './Sound/Sounds'