Closed hftf closed 10 years ago
I’m against pure JSON for those two reasons
Okay, let's see. We could borrow some ideas from JSONP, i.e. loading a script file which calls a function to serve the data. Something like:
loadGame({
game: 'x',
bounds: [0, 0, 319, 239],
coords: { ... }
})
loadGame
would be a function which stores the given data object (for caching, so we don't load data for the same game twice) and then proceeds with updating the GUI.
Alternatively, we represent the data by a JavaScript object literal and we eval
it after we load it through AJAX:
var data = eval('(' + req.responseText + ')');
games[data.game] = data;
loadUI();
This is similar to how we used to parse JSON before JSON.parse
became a standard. If you want a little bit more checking, you can use this instead:
var data = new Function('return ('+req.responseText+');')();
Tentatively fixed in 854ce17
If we want to do this, we'll probably have to revise the data layout for
data.js
. Ideally, we format those data files as proper JSON and use AJAX to load them into the tool. However, that means that we won't be able to use comments (e.g. // Triple battle
) and we'll need to get rid of trailing commas (acceptable in non-strict JS, but syntax errors in JSON).