New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading local files like json #106

Closed
fraespre opened this Issue Mar 13, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@fraespre

fraespre commented Mar 13, 2014

Hi,

I think it's very important than we can load local resources like the json files. This is significant if you want make a local game to run in a mobile.

I don't know what is exactly the problem, I suspect this is a safety restriction. But another JS game engine (similar to quintus) can load this type of files:
https://github.com/Galloman/ss2d

I suggest than you can investigate how can resolve the problem watching the ss2d source code (ResourceManager.loadResources).

regards,

@fariazz

This comment has been minimized.

Show comment
Hide comment
@fariazz

fariazz Mar 13, 2014

Collaborator

if you are using Phonegap, it loads local files using it's own web server, so it should be able to load the files without problem. What are you using to wrap the game on mobile?

Collaborator

fariazz commented Mar 13, 2014

if you are using Phonegap, it loads local files using it's own web server, so it should be able to load the files without problem. What are you using to wrap the game on mobile?

@cykod

This comment has been minimized.

Show comment
Hide comment
@cykod

cykod Mar 13, 2014

Owner

You can't load JSON files via AJAX from a file:// URL... You can easily turn your json file into a .js file with a Quintus module.

Quintus.MyData = function(Q) {
Q.assets['asset_name'] = { ... }
}

Then include that module in your setup.

Owner

cykod commented Mar 13, 2014

You can't load JSON files via AJAX from a file:// URL... You can easily turn your json file into a .js file with a Quintus module.

Quintus.MyData = function(Q) {
Q.assets['asset_name'] = { ... }
}

Then include that module in your setup.

@cykod cykod closed this Mar 13, 2014

@fraespre

This comment has been minimized.

Show comment
Hide comment
@fraespre

fraespre Mar 30, 2014

Sorry Cykod, but this solution seemed unserious (to insert json data hardcoded in js file).

I have developed a little function to load local files. Now I can execute fine the samples using local assets. You could append a similar utility in the Quintus to facilitate the local games.

//Q.load("sprites.png, sprites.json, level.json, tiles.png, background-wall.png", function() {
Q.load("sprites.png, tiles.png, background-wall.png", function() {
Q.assets['sprites.json']= loadJson("./data/sprites.json");
Q.assets['level.json']= loadJson("./data/level.json");
...
function loadJson(filePath) {
var req, res;
req= new XMLHttpRequest();
req.open("GET", filePath, false);
req.onload= function(){ res= this.response; };
req.send(null);
res= ((res!=undefined)?JSON.parse(res):null);
return res;
}

fraespre commented Mar 30, 2014

Sorry Cykod, but this solution seemed unserious (to insert json data hardcoded in js file).

I have developed a little function to load local files. Now I can execute fine the samples using local assets. You could append a similar utility in the Quintus to facilitate the local games.

//Q.load("sprites.png, sprites.json, level.json, tiles.png, background-wall.png", function() {
Q.load("sprites.png, tiles.png, background-wall.png", function() {
Q.assets['sprites.json']= loadJson("./data/sprites.json");
Q.assets['level.json']= loadJson("./data/level.json");
...
function loadJson(filePath) {
var req, res;
req= new XMLHttpRequest();
req.open("GET", filePath, false);
req.onload= function(){ res= this.response; };
req.send(null);
res= ((res!=undefined)?JSON.parse(res):null);
return res;
}

@jerone

This comment has been minimized.

Show comment
Hide comment
@jerone

jerone Mar 30, 2014

This won't work for everyone and on every browser. For security reasons JavaScript's access to the file system on the client is restricted - consider whether you would want (somebody else's) JavaScript to read your sensitive documents. Someone can disable that "security feature" in his browser manually. For instance, for Google Chrome you have to startup the executable with --disabled-web-security as commandline argument. Firefox can disabled that within it's about:config.

jerone commented Mar 30, 2014

This won't work for everyone and on every browser. For security reasons JavaScript's access to the file system on the client is restricted - consider whether you would want (somebody else's) JavaScript to read your sensitive documents. Someone can disable that "security feature" in his browser manually. For instance, for Google Chrome you have to startup the executable with --disabled-web-security as commandline argument. Firefox can disabled that within it's about:config.

@cykod

This comment has been minimized.

Show comment
Hide comment
@cykod

cykod Mar 30, 2014

Owner

@fraespre - are you trolling? That's exactly what the current system does:
https://github.com/cykod/Quintus/blob/master/lib/quintus.js#L1695

See @jerone's comment about security.

Owner

cykod commented Mar 30, 2014

@fraespre - are you trolling? That's exactly what the current system does:
https://github.com/cykod/Quintus/blob/master/lib/quintus.js#L1695

See @jerone's comment about security.

@fraespre

This comment has been minimized.

Show comment
Hide comment
@fraespre

fraespre Mar 30, 2014

@cykod , I was interested and downloaded the latest version of Quintus to Local. I probed the different examples and I found most samples crashed when load json files. [ Win 7 &Firefox 28.0 ] > uncaught exception: Error Loading: sprites.json ...
I notify you with this issue. You say me than this is a normal comportament. I search alternative to resolve the problem than work fine (you can probe it).

Do you think this is the troll behaviour?

fraespre commented Mar 30, 2014

@cykod , I was interested and downloaded the latest version of Quintus to Local. I probed the different examples and I found most samples crashed when load json files. [ Win 7 &Firefox 28.0 ] > uncaught exception: Error Loading: sprites.json ...
I notify you with this issue. You say me than this is a normal comportament. I search alternative to resolve the problem than work fine (you can probe it).

Do you think this is the troll behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment