-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
30 changed files
with
2,615 additions
and
860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#! /usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { | ||
PlayersExperiencePerLevel, | ||
MonstersExperiencePerLevel, | ||
AttributesPerLevel | ||
} = require('@reldens/game-data-generator'); | ||
|
||
let args = process.argv; | ||
if(2 === args.length){ | ||
console.error('- Missing arguments.', args); | ||
return false; | ||
} | ||
|
||
let validCommands = { | ||
'players-experience-per-level': (commandParams) => { | ||
let playersExperiencePerLevel = new PlayersExperiencePerLevel(commandParams); | ||
playersExperiencePerLevel.generate(); | ||
}, | ||
'monsters-experience-per-level': (commandParams) => { | ||
let monstersExperiencePerLevel = new MonstersExperiencePerLevel(commandParams); | ||
monstersExperiencePerLevel.generate(); | ||
}, | ||
'attributes-per-level': (commandParams) => { | ||
let attributesPerLevel = new AttributesPerLevel(commandParams); | ||
attributesPerLevel.generate(); | ||
} | ||
}; | ||
|
||
function fetchFileContents(filePath) | ||
{ | ||
if (!filePath) { | ||
console.error('- Missing data file.', filePath); | ||
return false; | ||
} | ||
|
||
let relativePath = path.join(process.cwd(), filePath); | ||
if (!relativePath) { | ||
console.error('- Invalid data file path.', process.cwd(), filePath); | ||
return false; | ||
} | ||
|
||
let fileContent = fs.readFileSync(relativePath, {encoding: 'utf8', flag:'r'}); | ||
if (!fileContent) { | ||
console.error('- Can not read data file or file empty.', relativePath); | ||
return false; | ||
} | ||
|
||
let importedJson = JSON.parse(fileContent); | ||
if (!importedJson) { | ||
console.error('- Can not parse data file.'); | ||
return false; | ||
} | ||
|
||
return importedJson; | ||
} | ||
|
||
let extractedParams = args.slice(2); | ||
|
||
let command = extractedParams[0] || false; | ||
if (!command) { | ||
console.error('- Missing command.'); | ||
return false; | ||
} | ||
|
||
if (-1 === Object.keys(validCommands).indexOf(command)) { | ||
console.error('- Invalid command.', command); | ||
return false; | ||
} | ||
|
||
let importedJson = fetchFileContents(extractedParams[1] || ''); | ||
|
||
if ('monsters-experience-per-level' === command) { | ||
let importedPlayerLevelsJson = fetchFileContents(extractedParams[2] || ''); | ||
if (!importedPlayerLevelsJson) { | ||
console.error('- Can not parse data file for player levels.'); | ||
return false; | ||
} | ||
|
||
importedJson.levelsExperienceByKey = importedPlayerLevelsJson; | ||
} | ||
|
||
validCommands[command](importedJson); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#! /usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { ServerManager } = require('../server'); | ||
const { PlayersExperiencePerLevelImporter } = require('../lib/import/server/players-experience-per-level-importer'); | ||
const { AttributesPerLevelImporter } = require('../lib/import/server/attributes-per-level-importer'); | ||
const { ClassPathsImporter } = require('../lib/import/server/class-paths-importer'); | ||
const { MapsImporter } = require('../lib/import/server/maps-importer'); | ||
|
||
let args = process.argv; | ||
if(2 === args.length){ | ||
console.error('- Missing arguments.', args); | ||
return false; | ||
} | ||
|
||
let validCommands = { | ||
'players-experience-per-level': async (data, projectThemeName) => { | ||
let serverManager = await initializeServer(data, projectThemeName); | ||
if (!serverManager) { | ||
return false; | ||
} | ||
let importer = new PlayersExperiencePerLevelImporter(serverManager); | ||
await importer.import(data); | ||
}, | ||
'attributes-per-level': async (data, projectThemeName) => { | ||
let serverManager = await initializeServer(data, projectThemeName); | ||
if (!serverManager) { | ||
return false; | ||
} | ||
let importer = new AttributesPerLevelImporter(serverManager); | ||
await importer.import(data); | ||
}, | ||
'class-paths': async (data, projectThemeName) => { | ||
let serverManager = await initializeServer(data, projectThemeName); | ||
if (!serverManager) { | ||
return false; | ||
} | ||
let importer = new ClassPathsImporter(serverManager); | ||
await importer.import(data); | ||
}, | ||
'maps': async (data, projectThemeName) => { | ||
let serverManager = await initializeServer(data, projectThemeName); | ||
if (!serverManager) { | ||
return false; | ||
} | ||
let importer = new MapsImporter(serverManager); | ||
await importer.import(data); | ||
} | ||
}; | ||
|
||
async function initializeServer(data, projectThemeName) | ||
{ | ||
if (!data) { | ||
console.error('- Missing data.', data); | ||
return false; | ||
} | ||
let appServer = new ServerManager({ | ||
projectRoot: process.cwd(), | ||
projectThemeName | ||
}); | ||
await appServer.initializeStorage(appServer.rawConfig, appServer.dataServerDriver); | ||
return appServer; | ||
} | ||
|
||
function fetchFileContents(filePath) | ||
{ | ||
if (!filePath) { | ||
console.error('- Missing data file.', filePath); | ||
return false; | ||
} | ||
|
||
let relativePath = path.join(process.cwd(), filePath); | ||
if (!relativePath) { | ||
console.error('- Invalid data file path.', process.cwd(), filePath); | ||
return false; | ||
} | ||
|
||
let fileContent = fs.readFileSync(relativePath, {encoding: 'utf8', flag:'r'}); | ||
if (!fileContent) { | ||
console.error('- Can not read data file or file empty.', relativePath); | ||
return false; | ||
} | ||
|
||
let importedJson = JSON.parse(fileContent); | ||
if (!importedJson) { | ||
console.error('- Can not parse data file.'); | ||
return false; | ||
} | ||
|
||
return importedJson; | ||
} | ||
|
||
let extractedParams = args.slice(2); | ||
|
||
let command = extractedParams[0] || false; | ||
if (!command) { | ||
console.error('- Missing command.'); | ||
return false; | ||
} | ||
|
||
let themeName = extractedParams[1] || ''; | ||
if (!themeName) { | ||
console.error('- Missing active theme name.'); | ||
return false; | ||
} | ||
|
||
if (-1 === Object.keys(validCommands).indexOf(command)) { | ||
console.error('- Invalid command.', command); | ||
return false; | ||
} | ||
|
||
validCommands[command](fetchFileContents(extractedParams[2] || ''), themeName).then(() => { | ||
console.log('Done.'); | ||
process.exit(); | ||
}).catch((error) => { | ||
console.error(error); | ||
process.exit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#! /usr/bin/env node | ||
|
||
/** | ||
* | ||
* Reldens - Install Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#! /usr/bin/env node | ||
|
||
/** | ||
* | ||
* Reldens - Commands | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* | ||
* Reldens - ClassPathsImporter | ||
* | ||
*/ | ||
|
||
class ClassPathKeyFactory | ||
{ | ||
|
||
static fromLabel(label) | ||
{ | ||
return label.toLowerCase().replace(/ /g, '-').replace('---', '-'); | ||
} | ||
|
||
} | ||
|
||
module.exports.ClassPathKeyFactory = ClassPathKeyFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* | ||
* Reldens - GameDom | ||
* | ||
*/ | ||
|
||
class FPSCounter | ||
{ | ||
|
||
constructor(gameDom) | ||
{ | ||
this.lastFrameTime = performance.now(); | ||
this.frameCount = 0; | ||
this.fpsDisplay = gameDom.createElementWithStyles('div', 'fps-counter', { | ||
padding: '0 20px', | ||
background: '#000', | ||
color: '#00ff00' | ||
}); | ||
gameDom.getElement('.header').appendChild(this.fpsDisplay); | ||
} | ||
|
||
updateFPS() | ||
{ | ||
let currentTime = performance.now(); | ||
let deltaTime = currentTime - this.lastFrameTime; | ||
this.lastFrameTime = currentTime; | ||
const fps = Math.round(1000 / deltaTime); | ||
this.frameCount++; | ||
if (this.frameCount % 60 === 0) { | ||
this.fpsDisplay.textContent = 'FPS: ' + fps; | ||
} | ||
requestAnimationFrame(this.updateFPS.bind(this)); | ||
} | ||
|
||
start() | ||
{ | ||
this.updateFPS(); | ||
} | ||
|
||
} | ||
|
||
module.exports.FPSCounter = FPSCounter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.