关于二次开发 BrowserQuest 中,对于地图修改的部分记录
在这里要感谢的是网友:神灯,land007
步骤:
1 通过地图编辑器tiled 修改 BrowserQuest-master\tools\maps\tmx 文件夹下的map.tmx
2 通过 地图编辑器 导出 map.json
3 通过命令nodejs脚本把map.json生成系统能够适别的json数据。
命令工具脚本:map.bat,exportmap.js 和 file.js (注:网友”神灯“提供)
1) map.bat:
@color 3F
@echo.
@echo 操作完成自动退出程序!
@echo.
node exportmap.js map.json direct
@echo.
@echo 操作完成按任意键退出程序!
@echo.
@pause >nul
exit
2) exportmap.js
#!/usr/bin/env node
var util = require('util'),
Log = require('log'),
path = require("path"),
fs = require("fs"),
file = require("../../shared/js/file"),
processMap = require('./processmap'),
log = new Log(Log.DEBUG);
// 此处用了nodejs的process进程处理,读取参数,即 map.bat 中 node exportmap.js map.json direct
// node 为参数0 process.argv[0] exportmap.js 为参数1 map.json 为参数3 依次类推...
var source = process.argv[2],
mode = process.argv[3],
destination = process.argv[4];
// source 代表的是map.json
if(!mode){
mode = "direct";
}
if(!source || (mode!="direct" && mode!="root" && mode!="both" && mode!="client" && mode!="server") || (mode!="root" && mode!="direct" && !destination)) {
util.puts("Usage : ./exportmap.js tiled_json_file [mode] [destination]");
util.puts("Optional parameters : mode & destination. Values:");
util.puts(" - \"direct\" (default) → updates current server and map files (WARNING: SHOULD ONLY BE CALLED FROM BrowserQuest/tools/maps !!!);");
util.puts(" - \"client destination_file\" → will generate destination_file.js and destination_file.json for client side map;");
util.puts(" - \"server destination_file.json\" → will generate destination_file.json for server side map;");
util.puts(" - \"both destination_directory\" → will generate world_client.js, world_client.json and world_server.json in directory.");
process.exit(0);
}
function main() {
getTiledJSONmap(source, callback_function);
}
function callback_function(json) {
switch(mode){
case "client":
processClient(json, destination);
break;
case "server":
processServer(json, destination);
break;
case "direct":
processClient(json, "../../client/maps/world_client");
processServer(json, "../../server/maps/world_server.json");
break;
case "both":
var directory=destination.replace(/\/+$/,'');//strip last path slashes
processClient(json, directory+"/world_client");
processServer(json, directory+"/world_server.json");
break;
case "root":
processClient(json, "client/maps/world_client");
processServer(json, "server/maps/world_server.json");
break;
default:
util.puts("Unrecognized mode, how on earth did you manage that ?");
}
}
function processClient(json, dest){
var jsonMap = JSON.stringify(processMap(json, {mode:"client"})); // Save the processed map object as JSON data
// map in a .json file for ajax loading
fs.writeFile(dest+".json", jsonMap, function(err, file) {
if(err){
log.error(JSON.stringify(err));
}
else{
log.info("Finished processing map file: "+ dest + ".json was saved.");
}
});
// map in a .js file for web worker loading
jsonMap = "var mapData = "+jsonMap;
fs.writeFile(dest+".js", jsonMap, function(err, file) {
if(err){
log.error(JSON.stringify(err));
}
else{
log.info("Finished processing map file: "+ dest + ".js was saved.");
}
});
}
function processServer(json, dest){
var jsonMap = JSON.stringify(processMap(json, {mode:"server"})); // Save the processed map object as JSON data
fs.writeFile(dest, jsonMap, function(err, file) {
if(err){
log.error(JSON.stringify(err));
}
else{
log.info("Finished processing map file: "+ dest + " was saved.");
}
});
}
function getTiledJSONmap(filename, callback) {
var self = this;
// 此处调用的file.js中的exists函数
file.exists(filename, function(exists) {
if(!exists) {
log.error(filename + " doesn't exist.")
return;
}
fs.readFile(filename, function(err, file) {
callback(JSON.parse(file.toString()));
});
});
}
main();
3) file.js
var exists, existsSync;
(function () {
var semver = require('semver');
var module = (semver.satisfies(process.version, '>=0.7.1') ? require('fs') : require('path'));
exists = module.exists;
existsSync = module.existsSync;
})();
if (!(typeof exports === 'undefined')) {
module.exports.exists = exists;
module.exports.existsSync = existsSync;
}
// 其中semver为node的一个模块,可以通过 npm install semver 安装模块 (前提是先弄清楚,安装node)
4 修改processmap.js
在官方提供的源码直接运行脚本,并不能完成功能,因为之前看过官方wiki,知道地图这一块有一个
https://github.com/browserquest/BrowserQuest/blob/master/tools/maps/processmap.js
把这个processmap.js 替换源码 BrowserQuest-master\tools\maps 下的processmap.js即可。
最后运行map.bat批处理文件,即可在对应目录生成json数据。。
然后你重启node server/js/main.js 重启服务器tomcat或apache,访问,可以看到,此时的地图为你修改后的地图。地图编辑算是成功了。
分享到:
相关推荐
H5游戏Browserquest端nodejs后台,非常有用的学习案例,
HTML+PHP开发的多人在线网页游戏
BrowserQuest改_客户+服务器V00.2.rar jbpm5的一个东西
dockerfile部署php项目,单纯Php环境下的cnetos,未使用其他容器,搭建BrowserQuest游戏私服
Mozilla的BrowserQuest的HTML5源代碼
BrowserQuest是一款HTML+PHP开发的多人在线网页游戏,代码仅供参考,提供开发人员,学习与研究,请勿用于商业用途。。。。。。
该游戏主要使用 HTML5 进行开发,在游戏中,玩家扮演一个年轻的战士,在危险的世界中展开冒险并寻找宝藏。该游戏使用了大量先进的技术,包括:WebSockets 技术:该技术主要用于在浏览器中实现和服务器端的双向通信。...
BrowserQuest源代码
顶级服务器 browserquest 服务器模拟器
H5 游戏 带Server端,全备
微信小游戏源码 BrowserQuest源代码(仅用于学习参考)微信小游戏源码 BrowserQuest源代码(仅用于学习参考)微信小游戏源码 BrowserQuest源代码(仅用于学习参考)微信小游戏源码 BrowserQuest源代码(仅用于学习...
描述此 BrowserQuest 已被修改为与 SOFTLAYER 一起使用。虚拟服务器运行环境该游戏设置为在以下环境中运行。 OS Ubuntu Linux 14.04 LTS Trusty Tahr - LAMP Install (64 bit)CPU 1コア, メモリ 1G, ディスク 25GB...
小游戏源码-BrowserQuest源代码.rar
文档位于客户端和服务器目录中。 执照 代码在MPL 2.0下获得许可。 内容根据CC-BY-SA 3.0许可。 有关详细信息,请参见LICENSE文件。 学分 由创建: 弗兰克·勒科林特(Franck Lecollinet)- Guillaume Lecollinet-
H5微信小游戏源码-BrowserQuest源代码.zip
游戏源码 欢迎下载
html5游戏源文件源码下载,游戏源文件源码html5,html5游戏源文件源码,游戏源文件html5源码下载,BrowserQuest 这款游戏基于HTML5的,所以可以在几乎所有的浏览器 - 包括iOS...目前Mozilla已经发布了BrowserQuest源代码。
修改 config.lua 中的 appRootPath 项的值为 BrowserQuestLua 中 server 文件夹所在的真实路径 修改 client/BrowserQuestLua/src/config.lua 中的 SERVER_ADDR 项为 GBC 服务器的 ip 地址 运行 ps. 因 ios模拟器 ...
Wanderlust 旨在成为您在浏览器中玩的开放世界冒险游戏。 基于风之城堡、ADarkRoom 和 Mozilla 的 BrowserQuest ( )。 所有图形都属于 Mozilla,我对它们没有任何要求。 这个项目是在不久前开始的,是为了向我为...