Skip to content

Commit

Permalink
Merge pull request #279 from RSamaium/v4.2.1
Browse files Browse the repository at this point in the history
V4.2.1
  • Loading branch information
RSamaium authored Jan 12, 2024
2 parents afba659 + d057e17 commit 2e6e06f
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 56 deletions.
13 changes: 9 additions & 4 deletions packages/client/src/Presets/AnimationSpritesheet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Direction } from '@rpgjs/common'
import { Animation } from '../Effects/AnimationCharacter'

export const RMSpritesheet = (framesWidth, framesHeight, frameStand = 1) => {
export const RMSpritesheet = (framesWidth: number, framesHeight: number, frameStand: number = 1) => {

if (framesWidth <= frameStand) {
frameStand = framesWidth - 1
}

const frameY = direction => {
const gap = Math.max(4 - framesHeight, 0)
return {
[Direction.Down]: 0,
[Direction.Left]: 1,
[Direction.Right]: 2,
[Direction.Up]: 3
[Direction.Left]: Math.max(0, 1 - gap),
[Direction.Right]: Math.max(0, 2 - gap),
[Direction.Up]: Math.max(0, 3 - gap)
}[direction]
}

Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/Tilemap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export default class TileMap extends Container {
// if (yObject - tile.y >= height) {
// return false
// }
const zIntersection = intersection([zObject, zObject + height], [realZ, realZ + tile.height])
// Always get tile.height for height. TODO: Fix this the height of the character. To be seen according to future implementations...
// Discussion: https://community.rpgjs.dev/d/250-rpgjs-v420/6
const zIntersection = intersection([zObject, zObject + tile.height /** Old code: height */], [realZ, realZ + tile.height])
if (!zIntersection) {
return true
}
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class RpgCommonGame extends EventEmitter {
}

const routesMove: any = []

while (player.pendingMove.length > 0) {
const inputData = player.pendingMove.shift()

Expand Down Expand Up @@ -131,6 +131,7 @@ export class RpgCommonGame extends EventEmitter {
input == Direction.Up ||
input == Direction.Down
) {
player.moving = true
moving = true
const isMove = await player.moveByDirection(+input, deltaTimeInt || 1)
if (isMove) {
Expand All @@ -149,6 +150,7 @@ export class RpgCommonGame extends EventEmitter {
inputs.push(input)
}


return {
player,
inputs
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler/src/build/vite-plugin-config.toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export default function configTomlPlugin(options: ClientBuildConfigOptions = {},
else if (id.endsWith('virtual-server.ts')) {
const codeToTransform = dd`
import { expressServer } from '@rpgjs/server/express'
import { RpgWorld } from '@rpgjs/server'
import * as url from 'url'
import modules from './${MODULE_NAME}'
import globalConfig from './${GLOBAL_CONFIG_SERVER}'
Expand All @@ -524,6 +525,16 @@ export default function configTomlPlugin(options: ClientBuildConfigOptions = {},
globalConfig,
basePath: __dirname,
envs: ${envsString}
}).then(({ server, game }) => {
if (import.meta['hot']) {
import.meta['hot'].on("vite:beforeFullReload", () => {
server.close();
RpgWorld.getPlayers().forEach(player => {
player.gameReload();
});
game.stop();
});
}
})
`;
return codeToTransform
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler/src/jsonSchema/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ export default {
"vite": {
"type": "object",
"additionalProperties": true
},
"spritesheetDirectories": {
"type": "array",
"items": {
"type": "string"
}
}
}
9 changes: 0 additions & 9 deletions packages/sample2/main/events/npc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,5 @@ export default class CatEvent extends RpgEvent {
Components.text('{id}')
)
this.speed = Speed.Slow
this.attachShape({
height: 100,
width: 100,
positioning: ShapePositioning.Center
})
}

onDetect(player, shape) {
this.moveTo(player).subscribe()
}
}
6 changes: 3 additions & 3 deletions packages/sample2/main/worlds/maps/map.tmx

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion packages/sample2/rpg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ modules = [
# '@rpgjs/title-screen'
]

spritesheetDirectories = []

[start]
map = 'map'
graphic = 'male'
Expand All @@ -22,4 +24,6 @@ modules = [

[compilerOptions.build]
serverUrl = '$ENV:VITE_SERVER_URL'
pwaEnabled = false
pwaEnabled = false


50 changes: 25 additions & 25 deletions packages/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"pretty-error": "^4.0.0",
"rxjs": "7.8.0",
"sat": "^0.9.0",
"simple-room": "^3.1.1",
"simple-room": "^3.1.2",
"socket.io": "^4.6.1"
},
"gitHead": "5abe6ca78be96524d74a052a230f2315c900ddee",
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/Gui/Gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Gui extends EventEmitter {
blockPlayerInput = false
} = {}): Promise<any> {
return new Promise((resolve) => {
this.player.moving = false
this.player.emit('gui.open', {
guiId: this.id,
data
Expand Down
10 changes: 0 additions & 10 deletions packages/server/src/express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,5 @@ export function expressServer(modules: ModuleType[], options: ExpressServerOptio
process.on('unhandledRejection', function (reason: any) {
console.log(pe.render(reason))
})

if (import.meta['hot']) {
import.meta['hot'].on("vite:beforeFullReload", () => {
server.close()
Query.getPlayers().forEach(player => {
player.gameReload()
})
rpgGame.stop()
});
}
})
}
2 changes: 1 addition & 1 deletion packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class RpgServerEngine {
if (!playerInstance) continue
const player = playerInstance.otherPossessedPlayer ?? playerInstance
if (player.pendingMove.length > 0) {
player.moving = true

const lastFrame = player.pendingMove[player.pendingMove.length - 1]
if (this.inputOptions.workers) obj.push(player.toObject())
else {
Expand Down
3 changes: 3 additions & 0 deletions packages/tiled/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ export class TiledParser {
const setLayer = (type) => {
if (!type) return
TiledParser.toArray(type).forEach((val: any) => {
if (this.layers.has(+val._attributes.id)) {
throw new Error(`Tiled Parser Error: Layer with id ${val._attributes.id} already exists`)
}
this.layers.set(+val._attributes.id, val)
})
}
Expand Down

0 comments on commit 2e6e06f

Please sign in to comment.