Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ tmx.parseFile(filename, function(err, map) {

The second example in that list uses `tmx.readFile(filename, callback)`
and then calls `tmx.parse(...)` on the results.
So if you're in browserland, you can replace the `readFile` function
with your own asset loading function.

## Documentation

Expand Down Expand Up @@ -146,4 +144,4 @@ The `objects` array looks like this:
TileLayer objects have a `tileAt(x, y)` method.
Otherwise you can access `layer.tiles` in row-major order.

See the bottom of index.js for more information.
See the bottom of index.js for more information.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,18 @@ function parse(content, pathToFile, cb) {
}

function defaultReadFile(name, cb) {
fs.readFile(name, { encoding: 'utf8' }, cb);
var isBrowser = typeof window !== 'undefined';

if (isBrowser) {
fetch(name)
.then(response => response.text())
.then(data => {
cb(undefined, data);
})
.catch(e => cb(e));
} else {
fs.readFile(name, { encoding: 'utf8' }, cb);
}
}

function parseFile(name, cb) {
Expand Down