Skip to content

Commit

Permalink
updated room loading + room configs
Browse files Browse the repository at this point in the history
  • Loading branch information
evolutionleo committed Aug 7, 2022
1 parent e2c5048 commit d95c91a
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 348 deletions.
19 changes: 13 additions & 6 deletions JavascriptServer/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const common_config = {
meta: {
game_name: 'OnlineGame',
version: 'v0.1',
framework_version: 'v4.3',
framework_version: 'v4.4',
server: 'unknown'
},

Expand All @@ -20,6 +20,17 @@ const common_config = {
closeOnLeave: false // close the lobby if a player leaves
},

room: {
// .yy room loading
rooms_path: '../Client/rooms',
warn_on_unknown_entity: true,

starting_room: 'Test Room',
rest_timeout: 5 // (seconds) - prevents rooms from processing entities
// when no players are present for a certain amount of time
// set to -1 to disable this feature
},

tps: 60,

// Disable some of the features that you don't need in your game
Expand All @@ -35,11 +46,7 @@ const common_config = {

necessary_login: false,

starting_room: 'Test Room',
ping_interval: 5 * 1000,
room_rest_timeout: 5 // (seconds) - prevents rooms from processing entities
// when no players are present for a certain amount of time
// set to -1 to disable this feature
ping_interval: 5 * 1000
};

const prod_config = {
Expand Down
2 changes: 1 addition & 1 deletion JavascriptServer/internal/concepts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class Client extends SendStuff {
if (!this.profile) {
if (!global.config.necessary_login) {
var room = this.lobby.rooms.find(room => {
return room.map.name === global.config.starting_room;
return room.map.name === global.config.room.starting_room;
});
}
else {
Expand Down
2 changes: 1 addition & 1 deletion JavascriptServer/internal/concepts/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class GameMap {
constructor(options) {
Object.assign(this, options);
if (global.config.rooms_enabled) {
Object.assign(this, LoadRoom('./rooms/' + this.room_name + '.yy'));
Object.assign(this, LoadRoom(this.room_name));
}

// trace(this.contents);
Expand Down
9 changes: 7 additions & 2 deletions JavascriptServer/internal/concepts/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class Room extends EventEmitter {

entities.forEach(entity => {
const etype = global.entityNames[entity.type];
if (etype.type == 'Unknown') { // entity type doesn't exist
trace(chalk.yellowBright('Warning: Entity of object type "' + entity.object_name + '" not found!'));
return;
}

const e = this.spawnEntity(etype, entity.x, entity.y);
e.xscale = entity.xscale;
e.yscale = entity.yscale;
Expand All @@ -119,8 +124,8 @@ class Room extends EventEmitter {
// don't process entities
if (this.players.length === 0) {
this.rest_timeout += 1 / this.tickrate;
if (global.config.room_rest_timeout > 0 // if this is enabled
&& this.rest_timeout > global.config.room_rest_timeout) {
if (global.config.room.rest_timeout >= 0 // if this is enabled
&& this.rest_timeout > global.config.room.rest_timeout) {
// do nothing - don't update the entities
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Entity from "#concepts/entity";
import trace from "#util/logging";

var WarpPortalType;
(function (WarpPortalType) {
Expand Down Expand Up @@ -63,7 +62,6 @@ export default class WarpPortal extends Entity {
}

// player.room should be the same as this.room
trace('room transition:', this.room.map.room_name + " -> " + this.Room_to.map.room_name);
this.room.movePlayer(player, this.Room_to);

player.entity.x = this.exit_portal.x;
Expand Down
2 changes: 1 addition & 1 deletion JavascriptServer/internal/schemas/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function freshProfile(account) {
name: account.username,

lobbyid: '-1',
room: global.config.starting_room,
room: global.config.room.starting_room,

x: 0,
y: 0
Expand Down
36 changes: 35 additions & 1 deletion JavascriptServer/internal/util/load_room.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
import UnknownEntity from '#entity/unknown';
import trace from '#util/logging';
import chalk from 'chalk';
import * as fs from 'fs';
import * as p from 'path';

export default function LoadRoom(path = './rooms/rTest.yy') {
// a couple utility functions
function isDir(path) {
return fs.existsSync(path) && fs.statSync(path).isDirectory();
}

function isFile(path) {
return fs.existsSync(path) && fs.statSync(path).isFile();
}

// the function
export default function LoadRoom(room_name) {
let rooms_path = p.resolve(global.config.room.rooms_path) + '/';

if (!isDir(rooms_path)) {
trace(chalk.redBright('ERROR: config.room.rooms_path is not a directory! - ', rooms_path));
return undefined;
}

let path = rooms_path + room_name;
if (isDir(path)) { // if it's a gm project's "rooms" folder then there's an additional layer
// check the uppercase variant, if it doesn't exist - use .toLowerCase()
let new_path = path + '/' + room_name + '.yy';
if (!fs.existsSync(new_path)) {
new_path = path + '/' + room_name.toLowerCase() + '.yy';
}

path = new_path;
}
else {
path += '.yy';
}

let json = fs.readFileSync(path).toString();
let regex = /\,(?=\s*?[\}\]])/g; // remove trailing commas
json = json.replace(regex, '');
Expand Down
Loading

0 comments on commit d95c91a

Please sign in to comment.