This library provides functions to decode and encode Defold Data Format files (.collection, .sprite, .tilemap, etc.).
Use this library in your own project by adding it as a dependency using this URL:
This library also currently requires Defold-Protobuf:
https://github.com/Melsoft-Games/defold-protobuf/archive/master.zip
Lastly, add /ddf/proto to the "Custom Resources" field of your game.project file.
Add the ddf module to your script with:
local ddf = require("ddf.ddf")The module contains a decode and encode function for each supported type, e.g. decode_collection(), encode_collection(), decode_tilemap(), encode_tilemap(). The decode function takes the contents of a DDF file as a string and returns a table with the decoded contents. The encode function takes that table and returns the encoded string.
local ddf = require("ddf.ddf")
function init(self)
-- Load and decode tilemap
local file = io.open("main/level.tilemap", "r")
local map = ddf.decode_tilemap(file:read("*a"))
file:close()
-- Flip every tile in layer 1 horizontally
for i, cell in ipairs(map.layers[1].cell) do
cell.h_flip = 1
end
-- Encode and save tilemap
local file = io.open("main/level.tilemap", "w")
file:write(ddf.encode_tilemap(map))
file:close()
end