forked from 2121578/gai-ca2
Initialized tileset
parent
6087332d5e
commit
220fa9bdcd
15
README.md
15
README.md
|
@ -1,10 +1,7 @@
|
||||||
# My first project
|
# GAI CA2 - Deserted Island Escape (2025 Edition)
|
||||||
|
|
||||||
helo this is mai first progaming project
|
This is the repo hosting the successor to the wildly popular and critically acclaimed Deserted Island Escape game.
|
||||||
```#include <stdio.h>
|
Details about the planning and other documents can be found in the `doc` folder.
|
||||||
int main()
|
|
||||||
{
|
- [planning.md](doc/planning.md)
|
||||||
printf("Hello, World!");
|
- [sprites.md](doc/sprites.md)
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
aseprite -b tilemaps.aseprite -script export.lua
|
|
@ -0,0 +1,302 @@
|
||||||
|
-- export.lua
|
||||||
|
-- Copyright (C) 2020 David Capello
|
||||||
|
--
|
||||||
|
-- This file is released under the terms of the MIT license.
|
||||||
|
|
||||||
|
local spr = app.sprite
|
||||||
|
if not spr then spr = app.activeSprite end -- just to support older versions of Aseprite
|
||||||
|
if not spr then return print "No active sprite" end
|
||||||
|
|
||||||
|
if ColorMode.TILEMAP == nil then ColorMode.TILEMAP = 4 end
|
||||||
|
assert(ColorMode.TILEMAP == 4)
|
||||||
|
|
||||||
|
local fs = app.fs
|
||||||
|
local pc = app.pixelColor
|
||||||
|
local output_folder = fs.joinPath(app.fs.filePath(spr.filename), fs.fileTitle(spr.filename))
|
||||||
|
local image_n = 0
|
||||||
|
local tileset_n = 0
|
||||||
|
|
||||||
|
local function write_json_data(filename, data)
|
||||||
|
local json = dofile('./json.lua')
|
||||||
|
local file = io.open(filename, "w")
|
||||||
|
file:write(json.encode(data))
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function fill_user_data(t, obj)
|
||||||
|
if obj.color.alpha > 0 then
|
||||||
|
if obj.color.alpha == 255 then
|
||||||
|
t.color = string.format("#%02x%02x%02x",
|
||||||
|
obj.color.red,
|
||||||
|
obj.color.green,
|
||||||
|
obj.color.blue)
|
||||||
|
else
|
||||||
|
t.color = string.format("#%02x%02x%02x%02x",
|
||||||
|
obj.color.red,
|
||||||
|
obj.color.green,
|
||||||
|
obj.color.blue,
|
||||||
|
obj.color.alpha)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if pcall(function() return obj.data end) then -- a tag doesn't have the data field pre-v1.3
|
||||||
|
if obj.data and obj.data ~= "" then
|
||||||
|
t.data = obj.data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_tileset(layer, tileset)
|
||||||
|
print("Exporting tileset for layer:", layer.name)
|
||||||
|
local t = {}
|
||||||
|
local grid = tileset.grid
|
||||||
|
local size = grid.tileSize
|
||||||
|
t.grid = { tileSize = { width = grid.tileSize.width, height = grid.tileSize.height } }
|
||||||
|
if #tileset > 0 then
|
||||||
|
print("Tileset contains", #tileset, "tiles")
|
||||||
|
local spec = spr.spec
|
||||||
|
spec.width = size.width
|
||||||
|
spec.height = size.height * #tileset
|
||||||
|
local image = Image(spec)
|
||||||
|
image:clear()
|
||||||
|
for i = 0, #tileset - 1 do
|
||||||
|
local tile = tileset:getTile(i)
|
||||||
|
image:drawImage(tile, 0, i * size.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
tileset_n = tileset_n + 1
|
||||||
|
local imageFn = fs.joinPath(output_folder, "tileset_" .. layer.name .. "_" .. tileset_n .. ".png")
|
||||||
|
image:saveAs(imageFn)
|
||||||
|
print("Saved tileset image to:", imageFn)
|
||||||
|
t.image = imageFn
|
||||||
|
else
|
||||||
|
print("Tileset is empty for layer:", layer.name)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_tilesets(tilesets)
|
||||||
|
print("Exporting", #tilesets, "tilesets")
|
||||||
|
local t = {}
|
||||||
|
for _,tileset in ipairs(tilesets) do
|
||||||
|
table.insert(t, export_tileset(tileset))
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_frames(frames)
|
||||||
|
local t = {}
|
||||||
|
for _,frame in ipairs(frames) do
|
||||||
|
table.insert(t, { duration=frame.duration })
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_cel(cel)
|
||||||
|
local t = {
|
||||||
|
frame=cel.frameNumber-1,
|
||||||
|
bounds={ x=cel.bounds.x,
|
||||||
|
y=cel.bounds.y,
|
||||||
|
width=cel.bounds.width,
|
||||||
|
height=cel.bounds.height }
|
||||||
|
}
|
||||||
|
|
||||||
|
if cel.image.colorMode == ColorMode.TILEMAP then
|
||||||
|
local tilemap = cel.image
|
||||||
|
-- save tilemap
|
||||||
|
t.tilemap = { width=tilemap.width,
|
||||||
|
height=tilemap.height,
|
||||||
|
tiles={} }
|
||||||
|
for it in tilemap:pixels() do
|
||||||
|
table.insert(t.tilemap.tiles, pc.tileI(it()))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- save regular cel
|
||||||
|
image_n = image_n + 1
|
||||||
|
local imageFn = fs.joinPath(output_folder, "image" .. image_n .. ".png")
|
||||||
|
cel.image:saveAs(imageFn)
|
||||||
|
t.image = imageFn
|
||||||
|
end
|
||||||
|
|
||||||
|
fill_user_data(t, cel)
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_cels(cels)
|
||||||
|
local t = {}
|
||||||
|
for _,cel in ipairs(cels) do
|
||||||
|
table.insert(t, export_cel(cel))
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_tileset_index(layer)
|
||||||
|
for i,tileset in ipairs(layer.sprite.tilesets) do
|
||||||
|
if layer.tileset == tileset then
|
||||||
|
return i-1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_tilemap(layer, cel)
|
||||||
|
print("Exporting tilemap for layer:", layer.name)
|
||||||
|
|
||||||
|
local tilemap = cel.image
|
||||||
|
if not tilemap then
|
||||||
|
print("Error: Tilemap image is nil for layer:", layer.name)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local grid = layer.tileset.grid
|
||||||
|
local tileWidth = grid.tileSize.width
|
||||||
|
local tileHeight = grid.tileSize.height
|
||||||
|
local mapWidth = tilemap.width
|
||||||
|
local mapHeight = tilemap.height
|
||||||
|
|
||||||
|
-- Create a new output image based on tilemap dimensions
|
||||||
|
local spec = ImageSpec{
|
||||||
|
width = mapWidth * tileWidth,
|
||||||
|
height = mapHeight * tileHeight,
|
||||||
|
colorMode = ColorMode.RGB
|
||||||
|
}
|
||||||
|
local outputImage = Image(spec)
|
||||||
|
outputImage:clear()
|
||||||
|
|
||||||
|
-- Iterate through tilemap pixels and render individual tiles
|
||||||
|
for it in tilemap:pixels() do
|
||||||
|
local tileIndex = app.pixelColor.tileI(it())
|
||||||
|
if tileIndex >= 0 then
|
||||||
|
local tileImage = layer.tileset:getTile(tileIndex)
|
||||||
|
if tileImage then
|
||||||
|
local destX = it.x * tileWidth
|
||||||
|
local destY = it.y * tileHeight
|
||||||
|
outputImage:drawImage(tileImage, destX, destY)
|
||||||
|
else
|
||||||
|
print(string.format("Warning: Tile index %d has no image in layer %s", tileIndex, layer.name))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Save the rendered image to a unique file
|
||||||
|
local imageFn = fs.joinPath(output_folder, "tilemap_" .. layer.name .. ".png")
|
||||||
|
outputImage:saveAs(imageFn)
|
||||||
|
print("Saved tilemap image to:", imageFn)
|
||||||
|
return imageFn
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_layer(layer, export_layers)
|
||||||
|
print("Exporting layer:", layer.name)
|
||||||
|
local t = { name = layer.name }
|
||||||
|
if layer.isImage then
|
||||||
|
if layer.opacity < 255 then
|
||||||
|
t.opacity = layer.opacity
|
||||||
|
end
|
||||||
|
if layer.blendMode ~= BlendMode.NORMAL then
|
||||||
|
t.blendMode = layer.blendMode
|
||||||
|
end
|
||||||
|
if #layer.cels >= 1 then
|
||||||
|
print("Layer has", #layer.cels, "cels")
|
||||||
|
t.cels = {}
|
||||||
|
for _, cel in ipairs(layer.cels) do
|
||||||
|
if layer.isTilemap and layer.tileset then
|
||||||
|
local tilemapImage = export_tilemap(layer, cel)
|
||||||
|
table.insert(t.cels, { frame = cel.frameNumber - 1, image = tilemapImage })
|
||||||
|
else
|
||||||
|
table.insert(t.cels, export_cel(cel))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif layer.isGroup then
|
||||||
|
print("Layer is a group with", #layer.layers, "sublayers")
|
||||||
|
t.layers = export_layers(layer.layers)
|
||||||
|
end
|
||||||
|
fill_user_data(t, layer)
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_layers(layers)
|
||||||
|
print("Exporting", #layers, "layers")
|
||||||
|
local t = {}
|
||||||
|
for _, layer in ipairs(layers) do
|
||||||
|
table.insert(t, export_layer(layer, export_layers))
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ani_dir(d)
|
||||||
|
local values = { "forward", "reverse", "pingpong" }
|
||||||
|
return values[d+1]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_tag(tag)
|
||||||
|
local t = {
|
||||||
|
name=tag.name,
|
||||||
|
from=tag.fromFrame.frameNumber-1,
|
||||||
|
to=tag.toFrame.frameNumber-1,
|
||||||
|
aniDir=ani_dir(tag.aniDir)
|
||||||
|
}
|
||||||
|
fill_user_data(t, tag)
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_tags(tags)
|
||||||
|
local t = {}
|
||||||
|
for _,tag in ipairs(tags) do
|
||||||
|
table.insert(t, export_tag(tag, export_tags))
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_slice(slice)
|
||||||
|
local t = {
|
||||||
|
name=slice.name,
|
||||||
|
bounds={ x=slice.bounds.x,
|
||||||
|
y=slice.bounds.y,
|
||||||
|
width=slice.bounds.width,
|
||||||
|
height=slice.bounds.height }
|
||||||
|
}
|
||||||
|
if slice.center then
|
||||||
|
t.center={ x=slice.center.x,
|
||||||
|
y=slice.center.y,
|
||||||
|
width=slice.center.width,
|
||||||
|
height=slice.center.height }
|
||||||
|
end
|
||||||
|
if slice.pivot then
|
||||||
|
t.pivot={ x=slice.pivot.x,
|
||||||
|
y=slice.pivot.y }
|
||||||
|
end
|
||||||
|
fill_user_data(t, slice)
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function export_slices(slices)
|
||||||
|
local t = {}
|
||||||
|
for _,slice in ipairs(slices) do
|
||||||
|
table.insert(t, export_slice(slice, export_slices))
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- Creates output folder
|
||||||
|
|
||||||
|
fs.makeDirectory(output_folder)
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- Write /sprite.json file in the output folder
|
||||||
|
|
||||||
|
local jsonFn = fs.joinPath(output_folder, "sprite.json")
|
||||||
|
local data = {
|
||||||
|
filename = spr.filename,
|
||||||
|
width = spr.width,
|
||||||
|
height = spr.height,
|
||||||
|
frames = export_frames(spr.frames),
|
||||||
|
layers = export_layers(spr.layers)
|
||||||
|
}
|
||||||
|
if #spr.tags > 0 then
|
||||||
|
data.tags = export_tags(spr.tags)
|
||||||
|
end
|
||||||
|
if #spr.slices > 0 then
|
||||||
|
data.slices = export_slices(spr.slices)
|
||||||
|
end
|
||||||
|
write_json_data(jsonFn, data)
|
|
@ -0,0 +1,388 @@
|
||||||
|
--
|
||||||
|
-- json.lua
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2020 rxi
|
||||||
|
--
|
||||||
|
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
-- this software and associated documentation files (the "Software"), to deal in
|
||||||
|
-- the Software without restriction, including without limitation the rights to
|
||||||
|
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
-- of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
-- so, subject to the following conditions:
|
||||||
|
--
|
||||||
|
-- The above copyright notice and this permission notice shall be included in all
|
||||||
|
-- copies or substantial portions of the Software.
|
||||||
|
--
|
||||||
|
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
-- SOFTWARE.
|
||||||
|
--
|
||||||
|
|
||||||
|
local json = { _version = "0.1.2" }
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- Encode
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local encode
|
||||||
|
|
||||||
|
local escape_char_map = {
|
||||||
|
[ "\\" ] = "\\",
|
||||||
|
[ "\"" ] = "\"",
|
||||||
|
[ "\b" ] = "b",
|
||||||
|
[ "\f" ] = "f",
|
||||||
|
[ "\n" ] = "n",
|
||||||
|
[ "\r" ] = "r",
|
||||||
|
[ "\t" ] = "t",
|
||||||
|
}
|
||||||
|
|
||||||
|
local escape_char_map_inv = { [ "/" ] = "/" }
|
||||||
|
for k, v in pairs(escape_char_map) do
|
||||||
|
escape_char_map_inv[v] = k
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function escape_char(c)
|
||||||
|
return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function encode_nil(val)
|
||||||
|
return "null"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function encode_table(val, stack)
|
||||||
|
local res = {}
|
||||||
|
stack = stack or {}
|
||||||
|
|
||||||
|
-- Circular reference?
|
||||||
|
if stack[val] then error("circular reference") end
|
||||||
|
|
||||||
|
stack[val] = true
|
||||||
|
|
||||||
|
if rawget(val, 1) ~= nil or next(val) == nil then
|
||||||
|
-- Treat as array -- check keys are valid and it is not sparse
|
||||||
|
local n = 0
|
||||||
|
for k in pairs(val) do
|
||||||
|
if type(k) ~= "number" then
|
||||||
|
error("invalid table: mixed or invalid key types")
|
||||||
|
end
|
||||||
|
n = n + 1
|
||||||
|
end
|
||||||
|
if n ~= #val then
|
||||||
|
error("invalid table: sparse array")
|
||||||
|
end
|
||||||
|
-- Encode
|
||||||
|
for i, v in ipairs(val) do
|
||||||
|
table.insert(res, encode(v, stack))
|
||||||
|
end
|
||||||
|
stack[val] = nil
|
||||||
|
return "[" .. table.concat(res, ",") .. "]"
|
||||||
|
|
||||||
|
else
|
||||||
|
-- Treat as an object
|
||||||
|
for k, v in pairs(val) do
|
||||||
|
if type(k) ~= "string" then
|
||||||
|
error("invalid table: mixed or invalid key types")
|
||||||
|
end
|
||||||
|
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
|
||||||
|
end
|
||||||
|
stack[val] = nil
|
||||||
|
return "{" .. table.concat(res, ",") .. "}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function encode_string(val)
|
||||||
|
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function encode_number(val)
|
||||||
|
-- Check for NaN, -inf and inf
|
||||||
|
if val ~= val or val <= -math.huge or val >= math.huge then
|
||||||
|
error("unexpected number value '" .. tostring(val) .. "'")
|
||||||
|
end
|
||||||
|
return string.format("%.14g", val)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local type_func_map = {
|
||||||
|
[ "nil" ] = encode_nil,
|
||||||
|
[ "table" ] = encode_table,
|
||||||
|
[ "string" ] = encode_string,
|
||||||
|
[ "number" ] = encode_number,
|
||||||
|
[ "boolean" ] = tostring,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
encode = function(val, stack)
|
||||||
|
local t = type(val)
|
||||||
|
local f = type_func_map[t]
|
||||||
|
if f then
|
||||||
|
return f(val, stack)
|
||||||
|
end
|
||||||
|
error("unexpected type '" .. t .. "'")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function json.encode(val)
|
||||||
|
return ( encode(val) )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- Decode
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local parse
|
||||||
|
|
||||||
|
local function create_set(...)
|
||||||
|
local res = {}
|
||||||
|
for i = 1, select("#", ...) do
|
||||||
|
res[ select(i, ...) ] = true
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
local space_chars = create_set(" ", "\t", "\r", "\n")
|
||||||
|
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
||||||
|
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
||||||
|
local literals = create_set("true", "false", "null")
|
||||||
|
|
||||||
|
local literal_map = {
|
||||||
|
[ "true" ] = true,
|
||||||
|
[ "false" ] = false,
|
||||||
|
[ "null" ] = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local function next_char(str, idx, set, negate)
|
||||||
|
for i = idx, #str do
|
||||||
|
if set[str:sub(i, i)] ~= negate then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return #str + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function decode_error(str, idx, msg)
|
||||||
|
local line_count = 1
|
||||||
|
local col_count = 1
|
||||||
|
for i = 1, idx - 1 do
|
||||||
|
col_count = col_count + 1
|
||||||
|
if str:sub(i, i) == "\n" then
|
||||||
|
line_count = line_count + 1
|
||||||
|
col_count = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error( string.format("%s at line %d col %d", msg, line_count, col_count) )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function codepoint_to_utf8(n)
|
||||||
|
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
||||||
|
local f = math.floor
|
||||||
|
if n <= 0x7f then
|
||||||
|
return string.char(n)
|
||||||
|
elseif n <= 0x7ff then
|
||||||
|
return string.char(f(n / 64) + 192, n % 64 + 128)
|
||||||
|
elseif n <= 0xffff then
|
||||||
|
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
|
||||||
|
elseif n <= 0x10ffff then
|
||||||
|
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
|
||||||
|
f(n % 4096 / 64) + 128, n % 64 + 128)
|
||||||
|
end
|
||||||
|
error( string.format("invalid unicode codepoint '%x'", n) )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function parse_unicode_escape(s)
|
||||||
|
local n1 = tonumber( s:sub(1, 4), 16 )
|
||||||
|
local n2 = tonumber( s:sub(7, 10), 16 )
|
||||||
|
-- Surrogate pair?
|
||||||
|
if n2 then
|
||||||
|
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
|
||||||
|
else
|
||||||
|
return codepoint_to_utf8(n1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function parse_string(str, i)
|
||||||
|
local res = ""
|
||||||
|
local j = i + 1
|
||||||
|
local k = j
|
||||||
|
|
||||||
|
while j <= #str do
|
||||||
|
local x = str:byte(j)
|
||||||
|
|
||||||
|
if x < 32 then
|
||||||
|
decode_error(str, j, "control character in string")
|
||||||
|
|
||||||
|
elseif x == 92 then -- `\`: Escape
|
||||||
|
res = res .. str:sub(k, j - 1)
|
||||||
|
j = j + 1
|
||||||
|
local c = str:sub(j, j)
|
||||||
|
if c == "u" then
|
||||||
|
local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1)
|
||||||
|
or str:match("^%x%x%x%x", j + 1)
|
||||||
|
or decode_error(str, j - 1, "invalid unicode escape in string")
|
||||||
|
res = res .. parse_unicode_escape(hex)
|
||||||
|
j = j + #hex
|
||||||
|
else
|
||||||
|
if not escape_chars[c] then
|
||||||
|
decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string")
|
||||||
|
end
|
||||||
|
res = res .. escape_char_map_inv[c]
|
||||||
|
end
|
||||||
|
k = j + 1
|
||||||
|
|
||||||
|
elseif x == 34 then -- `"`: End of string
|
||||||
|
res = res .. str:sub(k, j - 1)
|
||||||
|
return res, j + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
j = j + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
decode_error(str, i, "expected closing quote for string")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function parse_number(str, i)
|
||||||
|
local x = next_char(str, i, delim_chars)
|
||||||
|
local s = str:sub(i, x - 1)
|
||||||
|
local n = tonumber(s)
|
||||||
|
if not n then
|
||||||
|
decode_error(str, i, "invalid number '" .. s .. "'")
|
||||||
|
end
|
||||||
|
return n, x
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function parse_literal(str, i)
|
||||||
|
local x = next_char(str, i, delim_chars)
|
||||||
|
local word = str:sub(i, x - 1)
|
||||||
|
if not literals[word] then
|
||||||
|
decode_error(str, i, "invalid literal '" .. word .. "'")
|
||||||
|
end
|
||||||
|
return literal_map[word], x
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function parse_array(str, i)
|
||||||
|
local res = {}
|
||||||
|
local n = 1
|
||||||
|
i = i + 1
|
||||||
|
while 1 do
|
||||||
|
local x
|
||||||
|
i = next_char(str, i, space_chars, true)
|
||||||
|
-- Empty / end of array?
|
||||||
|
if str:sub(i, i) == "]" then
|
||||||
|
i = i + 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
-- Read token
|
||||||
|
x, i = parse(str, i)
|
||||||
|
res[n] = x
|
||||||
|
n = n + 1
|
||||||
|
-- Next token
|
||||||
|
i = next_char(str, i, space_chars, true)
|
||||||
|
local chr = str:sub(i, i)
|
||||||
|
i = i + 1
|
||||||
|
if chr == "]" then break end
|
||||||
|
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
|
||||||
|
end
|
||||||
|
return res, i
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function parse_object(str, i)
|
||||||
|
local res = {}
|
||||||
|
i = i + 1
|
||||||
|
while 1 do
|
||||||
|
local key, val
|
||||||
|
i = next_char(str, i, space_chars, true)
|
||||||
|
-- Empty / end of object?
|
||||||
|
if str:sub(i, i) == "}" then
|
||||||
|
i = i + 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
-- Read key
|
||||||
|
if str:sub(i, i) ~= '"' then
|
||||||
|
decode_error(str, i, "expected string for key")
|
||||||
|
end
|
||||||
|
key, i = parse(str, i)
|
||||||
|
-- Read ':' delimiter
|
||||||
|
i = next_char(str, i, space_chars, true)
|
||||||
|
if str:sub(i, i) ~= ":" then
|
||||||
|
decode_error(str, i, "expected ':' after key")
|
||||||
|
end
|
||||||
|
i = next_char(str, i + 1, space_chars, true)
|
||||||
|
-- Read value
|
||||||
|
val, i = parse(str, i)
|
||||||
|
-- Set
|
||||||
|
res[key] = val
|
||||||
|
-- Next token
|
||||||
|
i = next_char(str, i, space_chars, true)
|
||||||
|
local chr = str:sub(i, i)
|
||||||
|
i = i + 1
|
||||||
|
if chr == "}" then break end
|
||||||
|
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
|
||||||
|
end
|
||||||
|
return res, i
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local char_func_map = {
|
||||||
|
[ '"' ] = parse_string,
|
||||||
|
[ "0" ] = parse_number,
|
||||||
|
[ "1" ] = parse_number,
|
||||||
|
[ "2" ] = parse_number,
|
||||||
|
[ "3" ] = parse_number,
|
||||||
|
[ "4" ] = parse_number,
|
||||||
|
[ "5" ] = parse_number,
|
||||||
|
[ "6" ] = parse_number,
|
||||||
|
[ "7" ] = parse_number,
|
||||||
|
[ "8" ] = parse_number,
|
||||||
|
[ "9" ] = parse_number,
|
||||||
|
[ "-" ] = parse_number,
|
||||||
|
[ "t" ] = parse_literal,
|
||||||
|
[ "f" ] = parse_literal,
|
||||||
|
[ "n" ] = parse_literal,
|
||||||
|
[ "[" ] = parse_array,
|
||||||
|
[ "{" ] = parse_object,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
parse = function(str, idx)
|
||||||
|
local chr = str:sub(idx, idx)
|
||||||
|
local f = char_func_map[chr]
|
||||||
|
if f then
|
||||||
|
return f(str, idx)
|
||||||
|
end
|
||||||
|
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function json.decode(str)
|
||||||
|
if type(str) ~= "string" then
|
||||||
|
error("expected argument of type string, got " .. type(str))
|
||||||
|
end
|
||||||
|
local res, idx = parse(str, next_char(str, 1, space_chars, true))
|
||||||
|
idx = next_char(str, idx, space_chars, true)
|
||||||
|
if idx <= #str then
|
||||||
|
decode_error(str, idx, "trailing garbage")
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return json
|
Binary file not shown.
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"width": 320,
|
||||||
|
"frames": [
|
||||||
|
{
|
||||||
|
"duration": 0.1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"layers": [
|
||||||
|
{
|
||||||
|
"name": "ground",
|
||||||
|
"cels": [
|
||||||
|
{
|
||||||
|
"frame": 0,
|
||||||
|
"image": "tilemaps\\tilemap_ground.png"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "objects",
|
||||||
|
"cels": [
|
||||||
|
{
|
||||||
|
"frame": 0,
|
||||||
|
"image": "tilemaps\\tilemap_objects.png"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"height": 320,
|
||||||
|
"filename": "tilemaps.aseprite"
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 470 B |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dy0gpc2vgr3o5"
|
||||||
|
path="res://.godot/imported/tilemap_ground.png-cb404afe66e487b3999901e2d621baa7.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/tilemap/tilemaps/tilemap_ground.png"
|
||||||
|
dest_files=["res://.godot/imported/tilemap_ground.png-cb404afe66e487b3999901e2d621baa7.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
Binary file not shown.
After Width: | Height: | Size: 217 B |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cvb8hqljk0rv3"
|
||||||
|
path="res://.godot/imported/tilemap_objects.png-36dc04b2c5c4ea8db297745921fe10e8.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/tilemap/tilemaps/tilemap_objects.png"
|
||||||
|
dest_files=["res://.godot/imported/tilemap_objects.png-36dc04b2c5c4ea8db297745921fe10e8.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
|
@ -0,0 +1,19 @@
|
||||||
|
[gd_resource type="TileSet" load_steps=5 format=3 uid="uid://bi836ygcmyvhb"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dy0gpc2vgr3o5" path="res://assets/tilemap/tilemaps/tilemap_ground.png" id="1_ukrsa"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cvb8hqljk0rv3" path="res://assets/tilemap/tilemaps/tilemap_objects.png" id="2_o4fdg"]
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_114re"]
|
||||||
|
texture = ExtResource("1_ukrsa")
|
||||||
|
0:0/0 = 0
|
||||||
|
1:0/0 = 0
|
||||||
|
2:0/0 = 0
|
||||||
|
3:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_7jeam"]
|
||||||
|
texture = ExtResource("2_o4fdg")
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
sources/0 = SubResource("TileSetAtlasSource_114re")
|
||||||
|
sources/1 = SubResource("TileSetAtlasSource_7jeam")
|
File diff suppressed because one or more lines are too long
|
@ -11,6 +11,7 @@ config_version=5
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="gai-ca2"
|
config/name="gai-ca2"
|
||||||
|
run/main_scene="res://main-scenes/island.tscn"
|
||||||
config/features=PackedStringArray("4.3", "GL Compatibility")
|
config/features=PackedStringArray("4.3", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class_name World
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
Loading…
Reference in New Issue