Commit f4f6d16119a23f42e7351e3df1341c7d6e7f9dfa

Authored by DarkGod
1 parent 6f1baa90

load inline static map in tilemaps

... ... @@ -28,7 +28,7 @@ function _M:init(file, args)
28 28 Tilemap.init(self)
29 29
30 30 if file:find("%.tmx$") then self.data = self:tmxLoad(file)
31   - else self.data = self:mapLoad(file) end
  31 + else self.data = self:mapLoad(file, args and args.raw) end
32 32 self.data_h = #self.data
33 33 self.data_w = self.data[1] and #self.data[1] or 0
34 34 self.data_size = self:point(self.data_w, self.data_h)
... ...
... ... @@ -369,12 +369,17 @@ function _M:scale(sx, sy)
369 369 end
370 370
371 371 --- Used internally to load a tilemap from a lua map file
372   -function _M:mapLoad(file)
373   - local f, err = loadfile(file)
374   - if not f then error(err) end
375   - setfenv(f, {})
376   - local ok, raw = pcall(f)
377   - if not ok then error(raw) end
  372 +function _M:mapLoad(file, is_raw)
  373 + local raw
  374 + if not is_raw then
  375 + local f, err = loadfile(file)
  376 + if not f then error(err) end
  377 + setfenv(f, {})
  378 + local ok; ok, raw = pcall(f)
  379 + if not ok then error(raw) end
  380 + else
  381 + raw = file
  382 + end
378 383
379 384 raw = raw:split('\n')
380 385 local h = #raw
... ...