@rpgjs/client 3.3.2 → 4.0.0-beta.3

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 (164) hide show
  1. package/LICENSE +19 -0
  2. package/lib/Components/AbstractComponent.d.ts +3 -2
  3. package/lib/Components/AbstractComponent.js +17 -28
  4. package/lib/Components/AbstractComponent.js.map +1 -1
  5. package/lib/Components/BarComponent.d.ts +2 -1
  6. package/lib/Components/BarComponent.js +32 -33
  7. package/lib/Components/BarComponent.js.map +1 -1
  8. package/lib/Components/Component.d.ts +3 -3
  9. package/lib/Components/Component.js +84 -96
  10. package/lib/Components/Component.js.map +1 -1
  11. package/lib/Components/DebugComponent.d.ts +2 -1
  12. package/lib/Components/DebugComponent.js +9 -10
  13. package/lib/Components/DebugComponent.js.map +1 -1
  14. package/lib/Components/ImageComponent.d.ts +2 -1
  15. package/lib/Components/ImageComponent.js +5 -7
  16. package/lib/Components/ImageComponent.js.map +1 -1
  17. package/lib/Components/ShapeComponent.d.ts +2 -1
  18. package/lib/Components/ShapeComponent.js +14 -14
  19. package/lib/Components/ShapeComponent.js.map +1 -1
  20. package/lib/Components/TextComponent.d.ts +3 -2
  21. package/lib/Components/TextComponent.js +10 -9
  22. package/lib/Components/TextComponent.js.map +1 -1
  23. package/lib/Components/TileComponent.d.ts +2 -1
  24. package/lib/Components/TileComponent.js +12 -16
  25. package/lib/Components/TileComponent.js.map +1 -1
  26. package/lib/Effects/Animation.d.ts +10 -9
  27. package/lib/Effects/Animation.js +36 -36
  28. package/lib/Effects/Animation.js.map +1 -1
  29. package/lib/Effects/AnimationCharacter.js +2 -5
  30. package/lib/Effects/AnimationCharacter.js.map +1 -1
  31. package/lib/Effects/Spinner.d.ts +3 -2
  32. package/lib/Effects/Spinner.js +2 -5
  33. package/lib/Effects/Spinner.js.map +1 -1
  34. package/lib/Effects/Timeline.d.ts +1 -1
  35. package/lib/Effects/Timeline.js +6 -10
  36. package/lib/Effects/Timeline.js.map +1 -1
  37. package/lib/Effects/TransitionScene.d.ts +2 -1
  38. package/lib/Effects/TransitionScene.js +3 -7
  39. package/lib/Effects/TransitionScene.js.map +1 -1
  40. package/lib/GameEngine.js +51 -26
  41. package/lib/GameEngine.js.map +1 -1
  42. package/lib/Interfaces/Character.js +1 -2
  43. package/lib/Interfaces/Scene.js +1 -2
  44. package/lib/KeyboardControls.d.ts +2 -1
  45. package/lib/KeyboardControls.js +47 -45
  46. package/lib/KeyboardControls.js.map +1 -1
  47. package/lib/Logger.js +1 -5
  48. package/lib/Logger.js.map +1 -1
  49. package/lib/Presets/AnimationSpritesheet.js +9 -13
  50. package/lib/Presets/AnimationSpritesheet.js.map +1 -1
  51. package/lib/Presets/Scene.js +2 -5
  52. package/lib/Presets/Scene.js.map +1 -1
  53. package/lib/Renderer.d.ts +5 -3
  54. package/lib/Renderer.js +68 -60
  55. package/lib/Renderer.js.map +1 -1
  56. package/lib/Resources.js +1 -5
  57. package/lib/Resources.js.map +1 -1
  58. package/lib/RpgClient.d.ts +3 -2
  59. package/lib/RpgClient.js +1 -2
  60. package/lib/RpgClientEngine.d.ts +2 -1
  61. package/lib/RpgClientEngine.js +192 -176
  62. package/lib/RpgClientEngine.js.map +1 -1
  63. package/lib/RpgGui.js +40 -41
  64. package/lib/RpgGui.js.map +1 -1
  65. package/lib/Scene/EventLayer.d.ts +4 -0
  66. package/lib/Scene/EventLayer.js +8 -0
  67. package/lib/Scene/EventLayer.js.map +1 -0
  68. package/lib/Scene/Map.d.ts +17 -3
  69. package/lib/Scene/Map.js +157 -113
  70. package/lib/Scene/Map.js.map +1 -1
  71. package/lib/Scene/Scene.d.ts +3 -3
  72. package/lib/Scene/Scene.js +24 -20
  73. package/lib/Scene/Scene.js.map +1 -1
  74. package/lib/Scene/SceneData.js +1 -5
  75. package/lib/Scene/SceneData.js.map +1 -1
  76. package/lib/Sound/RpgSound.js +8 -11
  77. package/lib/Sound/RpgSound.js.map +1 -1
  78. package/lib/Sound/Sound.d.ts +2 -2
  79. package/lib/Sound/Sound.js +1 -5
  80. package/lib/Sound/Sound.js.map +1 -1
  81. package/lib/Sound/Sounds.js +4 -8
  82. package/lib/Sound/Sounds.js.map +1 -1
  83. package/lib/Sprite/Character.d.ts +3 -2
  84. package/lib/Sprite/Character.js +15 -16
  85. package/lib/Sprite/Character.js.map +1 -1
  86. package/lib/Sprite/Player.js +2 -9
  87. package/lib/Sprite/Player.js.map +1 -1
  88. package/lib/Sprite/Spritesheet.d.ts +4 -4
  89. package/lib/Sprite/Spritesheet.js +1 -5
  90. package/lib/Sprite/Spritesheet.js.map +1 -1
  91. package/lib/Sprite/Spritesheets.js +4 -8
  92. package/lib/Sprite/Spritesheets.js.map +1 -1
  93. package/lib/Tilemap/CommonLayer.d.ts +2 -1
  94. package/lib/Tilemap/CommonLayer.js +7 -11
  95. package/lib/Tilemap/CommonLayer.js.map +1 -1
  96. package/lib/Tilemap/ImageLayer.js +5 -7
  97. package/lib/Tilemap/ImageLayer.js.map +1 -1
  98. package/lib/Tilemap/Tile.d.ts +5 -5
  99. package/lib/Tilemap/Tile.js +19 -21
  100. package/lib/Tilemap/Tile.js.map +1 -1
  101. package/lib/Tilemap/TileLayer.d.ts +0 -7
  102. package/lib/Tilemap/TileLayer.js +27 -29
  103. package/lib/Tilemap/TileLayer.js.map +1 -1
  104. package/lib/Tilemap/TileSet.d.ts +2 -1
  105. package/lib/Tilemap/TileSet.js +9 -12
  106. package/lib/Tilemap/TileSet.js.map +1 -1
  107. package/lib/Tilemap/index.d.ts +3 -11
  108. package/lib/Tilemap/index.js +22 -61
  109. package/lib/Tilemap/index.js.map +1 -1
  110. package/lib/clientEntryPoint.js +26 -28
  111. package/lib/clientEntryPoint.js.map +1 -1
  112. package/lib/index.js +21 -75
  113. package/lib/index.js.map +1 -1
  114. package/package.json +19 -19
  115. package/src/Components/AbstractComponent.ts +120 -0
  116. package/src/Components/BarComponent.ts +179 -0
  117. package/src/Components/Component.ts +506 -0
  118. package/src/Components/DebugComponent.ts +36 -0
  119. package/src/Components/ImageComponent.ts +30 -0
  120. package/src/Components/ShapeComponent.ts +64 -0
  121. package/src/Components/TextComponent.ts +33 -0
  122. package/src/Components/TileComponent.ts +43 -0
  123. package/src/Effects/Animation.ts +297 -0
  124. package/src/Effects/AnimationCharacter.ts +7 -0
  125. package/src/Effects/Spinner.ts +19 -0
  126. package/src/Effects/Timeline.ts +294 -0
  127. package/src/Effects/TransitionScene.ts +57 -0
  128. package/src/GameEngine.ts +284 -0
  129. package/src/Interfaces/Character.ts +7 -0
  130. package/src/Interfaces/Scene.ts +9 -0
  131. package/src/KeyboardControls.ts +552 -0
  132. package/src/Logger.ts +3 -0
  133. package/src/Presets/AnimationSpritesheet.ts +36 -0
  134. package/src/Presets/Scene.ts +3 -0
  135. package/src/Renderer.ts +263 -0
  136. package/src/Resources.ts +40 -0
  137. package/src/RpgClient.ts +333 -0
  138. package/src/RpgClientEngine.ts +709 -0
  139. package/src/RpgGui.ts +553 -0
  140. package/src/RpgGuiCompiled.ts +43 -0
  141. package/src/Scene/EventLayer.ts +9 -0
  142. package/src/Scene/Map.ts +393 -0
  143. package/src/Scene/Scene.ts +270 -0
  144. package/src/Scene/SceneData.ts +13 -0
  145. package/src/Sound/RpgSound.ts +50 -0
  146. package/src/Sound/Sound.ts +91 -0
  147. package/src/Sound/Sounds.ts +7 -0
  148. package/src/Sprite/Character.ts +149 -0
  149. package/src/Sprite/Player.ts +3 -0
  150. package/src/Sprite/Spritesheet.ts +392 -0
  151. package/src/Sprite/Spritesheets.ts +8 -0
  152. package/src/Tilemap/CommonLayer.ts +20 -0
  153. package/src/Tilemap/ImageLayer.ts +20 -0
  154. package/src/Tilemap/Tile.ts +80 -0
  155. package/src/Tilemap/TileLayer.ts +142 -0
  156. package/src/Tilemap/TileSet.ts +40 -0
  157. package/src/Tilemap/index.ts +173 -0
  158. package/src/clientEntryPoint.ts +141 -0
  159. package/src/index.ts +25 -0
  160. package/src/types/howler.d.ts +73 -0
  161. package/tsconfig.json +30 -0
  162. package/lib/Components/ColorComponent.d.ts +0 -9
  163. package/lib/Components/ColorComponent.js +0 -18
  164. package/lib/Components/ColorComponent.js.map +0 -1
@@ -0,0 +1,20 @@
1
+ import { Layer } from "@rpgjs/tiled"
2
+ import TileMap from './index'
3
+ import { Container } from "pixi.js"
4
+
5
+ export class CommonLayer extends Container {
6
+ z: number
7
+
8
+ constructor(protected layer: Layer, protected map: TileMap) {
9
+ super()
10
+ this.applyProperties()
11
+ }
12
+
13
+ applyProperties() {
14
+ this.alpha = this.layer.opacity ?? 1
15
+ this.visible = this.layer.visible ?? true
16
+ this.x = this.layer.offsetx ?? 0
17
+ this.y = this.layer.offsety ?? 0
18
+ this.z = this.layer.properties.z ?? 0
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import { CommonLayer } from './CommonLayer';
2
+ import { Texture, TilingSprite } from 'pixi.js';
3
+
4
+ export default class ImageLayer extends CommonLayer {
5
+ applyProperties() {
6
+ super.applyProperties()
7
+ const engine = this.map['renderer']['clientEngine']
8
+ if (this.layer.image && this.layer.image.source && engine) {
9
+ const { width, height, source } = this.layer.image
10
+ const data = this.map.getData()
11
+ const texture = Texture.from(engine.getResourceUrl(source))
12
+ const tilingSprite = new TilingSprite(
13
+ texture,
14
+ this.layer.repeatx ? data.width * data.tilewidth : width,
15
+ this.layer.repeaty ? data.height * data.tileheight : height
16
+ )
17
+ this.addChild(tilingSprite)
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,80 @@
1
+ import { Texture, AnimatedSprite, groupD8 } from "pixi.js";
2
+ import TileSet from "./TileSet";
3
+ import { Tile as TiledTileClass } from '@rpgjs/tiled'
4
+ import { CompositeTilemap } from "@pixi/tilemap";
5
+
6
+ export default class Tile extends AnimatedSprite {
7
+ static getTextures(tile: TiledTileClass, tileSet: TileSet) {
8
+ const textures: Texture[] = [];
9
+
10
+ if (tile.animations && tile.animations.length) {
11
+ tile.animations.forEach(frame => {
12
+ textures.push(tileSet.textures[frame.tileid].clone())
13
+ });
14
+ } else {
15
+ textures.push(tileSet.textures[tile.gid - tileSet.firstgid].clone())
16
+ }
17
+
18
+ return textures;
19
+ }
20
+
21
+ animations: { tileid: number, duration: number }[] = []
22
+ _x: number = 0
23
+ _y: number = 0
24
+ pointsBufIndex: number
25
+ properties: any = {}
26
+
27
+ constructor(
28
+ private tile: TiledTileClass,
29
+ private tileSet: TileSet
30
+ ) {
31
+ super(Tile.getTextures(tile, tileSet));
32
+ this.animations = tile.animations || []
33
+ this.properties = tile.properties
34
+ this.textures = Tile.getTextures(tile, tileSet)
35
+ this.texture = this.textures[0] as Texture
36
+ this.flip()
37
+ }
38
+
39
+ get gid() {
40
+ return this.tile.gid
41
+ }
42
+
43
+ setAnimation(frame: CompositeTilemap) {
44
+ const size = this.animations.length
45
+ if (size > 1) {
46
+ const offest = (this.animations[1].tileid - this.animations[0].tileid) * this.width
47
+ frame.tileAnimX(offest, size)
48
+ }
49
+ }
50
+
51
+ flip() {
52
+ let symmetry
53
+ let i=0
54
+ const add = (symmetrySecond) => {
55
+ i++
56
+ if (symmetry) symmetry = groupD8.add(symmetry, symmetrySecond)
57
+ else symmetry = symmetrySecond
58
+ }
59
+
60
+ if (this.tile.horizontalFlip) {
61
+ add(groupD8.MIRROR_HORIZONTAL)
62
+ }
63
+
64
+ if (this.tile.verticalFlip) {
65
+ add(groupD8.MIRROR_VERTICAL)
66
+ }
67
+
68
+ if (this.tile.diagonalFlip) {
69
+ if (i % 2 == 0) {
70
+ add(groupD8.MAIN_DIAGONAL)
71
+ }
72
+ else {
73
+ add(groupD8.REVERSE_DIAGONAL)
74
+ }
75
+ }
76
+
77
+ if (symmetry) this.texture.rotate = symmetry
78
+
79
+ }
80
+ }
@@ -0,0 +1,142 @@
1
+ import Tile from './Tile';
2
+ import { CompositeTilemap, settings, POINT_STRUCT_SIZE, Tilemap } from '@pixi/tilemap'
3
+ import { Layer, Tile as TileClass } from '@rpgjs/tiled';
4
+ import TileSet from './TileSet';
5
+ import TileMap from '.';
6
+ import { CommonLayer } from './CommonLayer';
7
+
8
+ settings.use32bitIndex = true
9
+
10
+ export default class TileLayer extends CommonLayer {
11
+ private tilemap: CompositeTilemap
12
+ private _tiles: any = {}
13
+ tiles: (TileClass | null)[]
14
+
15
+ static findTileSet(gid: number, tileSets: TileSet[]) {
16
+ let tileset: TileSet | undefined
17
+ for (let i = tileSets.length - 1; i >= 0; i--) {
18
+ tileset = tileSets[i]
19
+ if (tileset.firstgid && tileset.firstgid <= gid) {
20
+ break;
21
+ }
22
+ }
23
+ return tileset;
24
+ }
25
+
26
+ constructor(layer: Layer, private tileSets: TileSet[], map: TileMap) {
27
+ super(layer, map)
28
+ }
29
+
30
+ /** @internal */
31
+ createTile(x: number, y: number, options: any = {}): Tile | undefined {
32
+ const { real, filter } = options
33
+ const { width, tilewidth, tileheight } = this.map.getData()
34
+ if (real) {
35
+ x = Math.floor(x / tilewidth)
36
+ y = Math.floor(y / tileheight)
37
+ }
38
+ const i = x + y * width;
39
+ const tiledTile = this.layer.getTileByIndex(i)
40
+
41
+ if (!tiledTile || (tiledTile && tiledTile.gid == 0)) return
42
+
43
+ const tileset = TileLayer.findTileSet(
44
+ tiledTile.gid,
45
+ this.tileSets
46
+ )
47
+
48
+ if (!tileset) return
49
+
50
+ const tile = new Tile(
51
+ tiledTile,
52
+ tileset
53
+ )
54
+
55
+ tile.x = x * tilewidth;
56
+ tile.y =
57
+ y * tileheight +
58
+ (tileheight -
59
+ tile.texture.height);
60
+
61
+ tile._x = x;
62
+ tile._y = y;
63
+
64
+ if (tileset.tileoffset) {
65
+ tile.x += tileset.tileoffset.x ?? 0;
66
+ tile.y += tileset.tileoffset.y ?? 0;
67
+ }
68
+
69
+ if (filter) {
70
+ const ret = filter(tile)
71
+ if (!ret) return
72
+ }
73
+ return tile
74
+ }
75
+
76
+ /** @internal */
77
+ changeTile(x: number, y: number) {
78
+ const { tilewidth, tileheight } = this.map.getData()
79
+ x = Math.floor(x / tilewidth)
80
+ y = Math.floor(y / tileheight)
81
+ const oldTile: Tile = this._tiles[x + ';' + y]
82
+ const newTile = this.createTile(x, y)
83
+ if (!oldTile && newTile) {
84
+ this.addFrame(newTile, x, y)
85
+ }
86
+ else {
87
+ if (newTile) {
88
+ const bufComposite: CompositeTilemap = new CompositeTilemap()
89
+ const frame = bufComposite.tile(newTile.texture, newTile.x, newTile.y)
90
+ newTile.setAnimation(frame)
91
+ this._tiles[x + ';' + y] = newTile
92
+ // @ts-ignore
93
+ const pointsBufComposite = (bufComposite.children[0] as Tilemap).pointsBuf
94
+ // Change Texture (=0, 1 and 7, rotate (=4), animX (=5), animY (=6))
95
+ ;[0, 1, 4, 6, 7, 8].forEach((i) => {
96
+ if (this.pointsBuf) this.pointsBuf[oldTile.pointsBufIndex + i] = pointsBufComposite[i]
97
+ })
98
+ // @ts-ignore
99
+ this.tilemap.children[0].modificationMarker = 0
100
+ this.addFrame(newTile, x, y)
101
+ this['modificationMarker'] = 0
102
+ }
103
+ else {
104
+ delete this._tiles[x + ';' + y]
105
+ if (this.pointsBuf) this.pointsBuf.splice(oldTile.pointsBufIndex, POINT_STRUCT_SIZE)
106
+ }
107
+ }
108
+ }
109
+
110
+ /** @internal */
111
+ get pointsBuf(): number[] | null {
112
+ const child = this.tilemap.children[0] as Tilemap
113
+ if (!child) return null
114
+ return child['pointsBuf']
115
+ }
116
+
117
+ private addFrame(tile: Tile, x: number, y: number) {
118
+ const frame = this.tilemap.tile(tile.texture, tile.x, tile.y, {
119
+ rotate: tile.texture.rotate
120
+ })
121
+ const pb = this.pointsBuf
122
+ if (!pb) return null
123
+ tile.pointsBufIndex = pb.length - POINT_STRUCT_SIZE
124
+ tile.setAnimation(frame)
125
+ this._tiles[x + ';' + y] = tile
126
+ }
127
+
128
+ /** @internal */
129
+ create() {
130
+ this.tilemap = new CompositeTilemap()
131
+ const { width, height } = this.map.getData()
132
+ for (let y = 0; y < height; y++) {
133
+ for (let x = 0; x < width; x++) {
134
+ const tile = this.createTile(x, y)
135
+ if (tile) {
136
+ this.addFrame(tile, x, y)
137
+ }
138
+ }
139
+ }
140
+ this.addChild(this.tilemap as any)
141
+ }
142
+ }
@@ -0,0 +1,40 @@
1
+ import { spritesheets } from '../Sprite/Spritesheets'
2
+ import { TiledTileset, Tileset as TiledTilesetClass } from '@rpgjs/tiled'
3
+ import { log } from '../Logger'
4
+ import { Texture, BaseTexture, Rectangle } from 'pixi.js'
5
+
6
+ export default class TileSet extends TiledTilesetClass {
7
+ private baseTexture: BaseTexture
8
+ public textures: Texture[] = []
9
+
10
+ constructor(tileSet: TiledTileset) {
11
+ super(tileSet)
12
+ }
13
+
14
+ /** @internal */
15
+ load() {
16
+ const spritesheet = spritesheets.get(this.name)
17
+ if (!spritesheet) {
18
+ throw log(`Impossible to find ${this.name} tileset`)
19
+ }
20
+ this.baseTexture = spritesheet.resource
21
+ for (
22
+ let y = this.margin;
23
+ y < this.image.height;
24
+ y += this.tileheight + this.spacing
25
+ ) {
26
+ for (
27
+ let x = this.margin;
28
+ x < this.image.width;
29
+ x += this.tilewidth + this.spacing
30
+ ) {
31
+ this.textures.push(
32
+ new Texture(
33
+ this.baseTexture,
34
+ new Rectangle(+x, +y, +this.tilewidth, +this.tileheight)
35
+ )
36
+ )
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,173 @@
1
+ import { Utils } from '@rpgjs/common'
2
+ import ImageLayer from './ImageLayer'
3
+ import TileLayer from './TileLayer'
4
+ import TileSet from './TileSet'
5
+ import Tile from './Tile'
6
+ import { log } from '../Logger'
7
+ import { TiledMap, TiledLayerType, Layer } from '@rpgjs/tiled'
8
+ import { RpgRenderer } from '../Renderer'
9
+ import { Container, Graphics } from 'pixi.js'
10
+
11
+ const { intersection } = Utils
12
+
13
+ export interface MapInfo extends TiledMap {
14
+ layers: Layer[]
15
+ }
16
+
17
+ export default class TileMap extends Container {
18
+ background: Graphics = new Graphics()
19
+ tilewidth: number = 0
20
+ tileheight: number = 0
21
+ private frameRateAnimation: number = 10
22
+ tilesets: TileSet[] = []
23
+ layers: {
24
+ [layerName: string]: TileLayer | ImageLayer
25
+ } = {}
26
+ private tilesLayer: Container = new Container()
27
+ private frameTile: number = 0
28
+
29
+
30
+ constructor(private data: MapInfo, private renderer: RpgRenderer) {
31
+ super()
32
+ this.x = 0
33
+ this.y = 0
34
+ this.create(data)
35
+ }
36
+
37
+ /** @internal */
38
+ drawAnimateTile(frame: number) {
39
+ if (frame % this.frameRateAnimation == 0) {
40
+ this.renderer['renderer'].plugins.tilemap.tileAnim[0] = this.frameTile
41
+ this.frameTile++
42
+ }
43
+ }
44
+
45
+ getData(): MapInfo {
46
+ return this.data
47
+ }
48
+
49
+ setBackgroundColor(color: string) {
50
+ color = color.replace('#', '')
51
+ this.background.beginFill(parseInt(color, 16))
52
+ this.background.drawRect(
53
+ 0,
54
+ 0,
55
+ (this.width || 0) * (this.tilewidth || 0),
56
+ (this.height || 0) * (this.tileheight || 0)
57
+ );
58
+ this.background.endFill()
59
+ }
60
+
61
+ private create(data: MapInfo) {
62
+ this.data = data
63
+ Object.assign(this, data)
64
+ if (this.data.backgroundcolor) this.setBackgroundColor(this.data.backgroundcolor)
65
+ this.addChild(this.background);
66
+ this.tilesets = this.data.tilesets.map((tileSet) => {
67
+ return new TileSet(tileSet)
68
+ })
69
+ }
70
+
71
+ /** @internal */
72
+ createOverlayTiles(x: number, y: number, instance) {
73
+ const tilesLayer: any = []
74
+ this.data.layers.forEach((layerData) => {
75
+ switch (layerData.type) {
76
+ case TiledLayerType.Tile: {
77
+ const tileLayer = new TileLayer(layerData, this.tilesets, this)
78
+ const tile = tileLayer.createTile(x, y, {
79
+ real: true,
80
+ filter: (tile: Tile) => {
81
+ const { data, y: yObject, z: zObject } = instance
82
+ const { hHitbox, height } = data
83
+ const zLayer = tileLayer.z
84
+ const tileHasZ = tile.properties.z !== undefined
85
+ let { z } = tile.properties
86
+
87
+ if (zLayer !== undefined) {
88
+ z = zLayer + (z !== undefined ? z : 0)
89
+ }
90
+
91
+ if (z == undefined) return false
92
+
93
+ const realZ = z * tile.height
94
+
95
+ if (zObject + height < realZ) {
96
+ return true
97
+ }
98
+
99
+ // player is on a tile but the player has a high z
100
+ if (zObject > realZ + tile.height) {
101
+ return false
102
+ }
103
+
104
+ if (!tileHasZ) return false
105
+
106
+ // is front of tile
107
+ if (yObject + hHitbox > tile.y + tile.height) {
108
+ // if (yObject - tile.y >= height) {
109
+ // return false
110
+ // }
111
+ const zIntersection = intersection([zObject, zObject + height], [realZ, realZ + tile.height])
112
+ if (!zIntersection) {
113
+ return true
114
+ }
115
+ return false
116
+ }
117
+ return true
118
+ }
119
+ })
120
+ if (tile) {
121
+ tileLayer.addChild(tile)
122
+ const size = tile.animations.length
123
+ if (size > 0) {
124
+ const ms = 1000 / 60
125
+ tile.animationSpeed = ms / (ms * this.frameRateAnimation)
126
+ const frameIndex = (this.frameTile-1) - (size * Math.floor(this.frameTile / size))
127
+ tile.gotoAndPlay(frameIndex)
128
+ }
129
+ tilesLayer.push(tileLayer)
130
+ }
131
+ break;
132
+ }
133
+ }
134
+ })
135
+ return tilesLayer
136
+ }
137
+
138
+ /** @internal */
139
+ changeTile(x: number, y: number, layerName: string) {
140
+ const layer = this.layers[layerName]
141
+ if (!layer) throw log(`${layerName} not exists`)
142
+ if (layer instanceof TileLayer) {
143
+ layer.changeTile(x, y)
144
+ }
145
+ }
146
+
147
+ /** @internal */
148
+ load(options?: { drawTiles: boolean | undefined, isUpdate?: boolean }) {
149
+ this.tilesLayer.removeChildren()
150
+
151
+ this.tilesets.forEach(tileset => tileset.load())
152
+
153
+ this.data.layers.forEach((layerData) => {
154
+ switch (layerData.type) {
155
+ case TiledLayerType.Tile: {
156
+ const tileLayer = new TileLayer(layerData, this.tilesets, this)
157
+ if (options?.drawTiles) tileLayer.create()
158
+ this.layers[layerData.name] = tileLayer
159
+ this.tilesLayer.addChild(tileLayer)
160
+ break;
161
+ }
162
+ case TiledLayerType.Image: {
163
+ const imageLayer = new ImageLayer(layerData, this)
164
+ this.layers[layerData.name] = imageLayer
165
+ this.tilesLayer.addChild(imageLayer)
166
+ break;
167
+ }
168
+ }
169
+ })
170
+
171
+ this.addChild(this.tilesLayer)
172
+ }
173
+ }
@@ -0,0 +1,141 @@
1
+ import { HookClient, loadModules, ModuleType } from '@rpgjs/common'
2
+ import { GameEngineClient } from './GameEngine'
3
+ import { RpgClientEngine } from './RpgClientEngine'
4
+
5
+ interface RpgClientEntryPointOptions {
6
+ /**
7
+ * Represents socket io client but you can put something else (which is the same schema as socket io)
8
+ *
9
+ * @prop {SocketIO or other} io
10
+ * @memberof RpgClientEntryPoint
11
+ * */
12
+ io: any
13
+ /**
14
+ * Canvas Options
15
+ *
16
+ * * {boolean} [options.transparent=false] - If the render view is transparent, default false
17
+ * * {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
18
+ * resolutions other than 1
19
+ * * {boolean} [options.antialias=false] - sets antialias
20
+ * * {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer. The
21
+ * resolution of the renderer retina would be 2.
22
+ * * {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation,
23
+ * enable this if you need to call toDataUrl on the webgl context.
24
+ * * {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
25
+ * not before the new render pass.
26
+ * * {number} [options.backgroundColor=0x000000] - The background color of the rendered area
27
+ * (shown if not transparent).
28
+ *
29
+ * @prop {object} [canvas]
30
+ * @memberof RpgClientEntryPoint
31
+ * */
32
+ canvas?: {
33
+ transparent?: boolean,
34
+ autoDensity?: boolean,
35
+ antialias?: boolean,
36
+ resolution?: number
37
+ preserveDrawingBuffer?: boolean
38
+ backgroundColor?: number
39
+ }
40
+ /**
41
+ * The element selector that will display the canvas. By default, `#rpg`
42
+ *
43
+ * @prop {string} [selector]
44
+ * @memberof RpgClientEntryPoint
45
+ * */
46
+ selector?: string,
47
+
48
+ /**
49
+ * The selector that corresponds to the GUIs. By default, `#gui`
50
+ * If you didn't put a GUI element in the div, an element will be automatically created.
51
+ *
52
+ * @prop {string} [selectorGui]
53
+ * @memberof RpgClientEntryPoint
54
+ * */
55
+ selectorGui?: string
56
+
57
+ /**
58
+ * The selector that corresponds to the element contains canvas. By default, `#canvas`
59
+ * If you didn't put element in the main div, an element will be automatically created.
60
+ *
61
+ * @prop {string} [selectorCanvas]
62
+ * @memberof RpgClientEntryPoint
63
+ * */
64
+ selectorCanvas?: string
65
+
66
+ standalone?: boolean
67
+
68
+ /**
69
+ * The general configurations of the game. For example, default keyboard keys, cursor noise. This is information that external modules can reuse
70
+ *
71
+ * @prop {object} [globalConfig]
72
+ * @memberof RpgClientEntryPoint
73
+ * */
74
+ globalConfig?: any
75
+
76
+ drawMap?: boolean
77
+
78
+ /**
79
+ * The maximum number of fps for the rendering
80
+ *
81
+ * @prop {object} [maxFps]
82
+ * @since 3.0.2
83
+ * @memberof RpgClientEntryPoint
84
+ * */
85
+ maxFps?: number
86
+
87
+ /**
88
+ * Put the number of FPS that the server processes. It allows to synchronize the client rendering with the server. The default value is 60
89
+ *
90
+ * @prop {object} [serverFps]
91
+ * @since 3.0.2
92
+ * @memberof RpgClientEntryPoint
93
+ * */
94
+ serverFps?: number
95
+ }
96
+
97
+ export default (modules: ModuleType[], options: RpgClientEntryPointOptions): RpgClientEngine => {
98
+
99
+ if (!options.globalConfig) options.globalConfig = {}
100
+
101
+ const relations = {
102
+ onInit: HookClient.AddSprite,
103
+ onDestroy: HookClient.RemoveSprite,
104
+ onUpdate: HookClient.UpdateSprite,
105
+ onChanges: HookClient.ChangesSprite,
106
+ onMove: HookClient.SpriteMove
107
+ }
108
+
109
+ const relationsMap = {
110
+ onAddSprite: HookClient.SceneAddSprite,
111
+ onRemoveSprite: HookClient.SceneRemoveSprite,
112
+ onBeforeLoading: HookClient.BeforeSceneLoading,
113
+ onAfterLoading: HookClient.AfterSceneLoading,
114
+ onMapLoading: HookClient.SceneMapLoading,
115
+ onChanges: HookClient.SceneOnChanges,
116
+ onDraw: HookClient.SceneDraw
117
+ }
118
+
119
+ const relationsEngine = {
120
+ onStart: HookClient.Start,
121
+ onStep: HookClient.Step,
122
+ onConnected: HookClient.Connected,
123
+ onDisconnect: HookClient.Disconnect,
124
+ onConnectError: HookClient.ConnectedError,
125
+ onInput: HookClient.SendInput,
126
+ onWindowResize: HookClient.WindowResize
127
+ }
128
+
129
+ loadModules(modules, {
130
+ side: 'client',
131
+ relations: {
132
+ player: relations,
133
+ sceneMap: relationsMap,
134
+ engine: relationsEngine
135
+ }
136
+ })
137
+
138
+ const gameEngine = new GameEngineClient()
139
+ const clientEngine = new RpgClientEngine(gameEngine, options)
140
+ return clientEngine
141
+ }
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ export { Direction, Control, Input, PrebuiltGui, HookServer, HookClient, RpgPlugin, RpgModule, RpgCommonPlayer as RpgSpriteLogic } from '@rpgjs/common'
2
+ export { default as entryPoint } from './clientEntryPoint'
3
+ export { RpgClient, RpgSceneHooks, RpgSceneMapHooks, RpgSpriteHooks, RpgClientEngineHooks } from './RpgClient'
4
+ export { Scene as RpgScene } from './Scene/Scene'
5
+ export { RpgClientEngine } from './RpgClientEngine'
6
+ export { Spritesheet } from './Sprite/Spritesheet'
7
+ export { Sound } from './Sound/Sound'
8
+ export { Howler as RpgGlobalSound } from 'howler'
9
+ export { RpgSound } from './Sound/RpgSound'
10
+ export * as Presets from './Presets/AnimationSpritesheet'
11
+ export { Animation } from './Effects/AnimationCharacter'
12
+ export { Animation as AnimationClass } from './Effects/Animation'
13
+ export { ISpriteCharacter } from './Interfaces/Character'
14
+ export { SceneData } from './Scene/SceneData'
15
+ export { SceneMap as RpgSceneMap } from './Scene/Map'
16
+ export { RpgGui } from './RpgGui';
17
+ export { Timeline, Ease } from './Effects/Timeline';
18
+ export { RpgComponent, RpgComponent as RpgSprite } from './Components/Component'
19
+
20
+ import { spritesheets } from './Sprite/Spritesheets'
21
+ import { sounds } from './Sound/Sounds'
22
+ export const RpgResource = {
23
+ spritesheets,
24
+ sounds
25
+ }