mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 21:33:12 +00:00
Add user data to tilesets (only logic side + scripting properties)
There is no UI yet to set Tileset user data (color and text).
This commit is contained in:
parent
4dfa3ca0eb
commit
bd674dcb31
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -11,6 +11,7 @@
|
||||
#include "app/script/docobj.h"
|
||||
#include "app/script/engine.h"
|
||||
#include "app/script/luacpp.h"
|
||||
#include "app/script/userdata.h"
|
||||
#include "doc/tileset.h"
|
||||
|
||||
namespace app {
|
||||
@ -97,6 +98,8 @@ const Property Tileset_properties[] = {
|
||||
{ "name", Tileset_get_name, Tileset_set_name },
|
||||
{ "grid", Tileset_get_grid, nullptr },
|
||||
{ "baseIndex", Tileset_get_baseIndex, Tileset_set_baseIndex },
|
||||
{ "color", UserData_get_color<Tileset>, UserData_set_color<Tileset> },
|
||||
{ "data", UserData_get_text<Tileset>, UserData_set_text<Tileset> },
|
||||
{ nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (c) 2019-2022 Igara Studio S.A.
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -23,7 +23,7 @@ namespace doc {
|
||||
Tileset::Tileset(Sprite* sprite,
|
||||
const Grid& grid,
|
||||
const tileset_index ntiles)
|
||||
: Object(ObjectType::Tileset)
|
||||
: WithUserData(ObjectType::Tileset)
|
||||
, m_sprite(sprite)
|
||||
, m_grid(grid)
|
||||
, m_tiles(ntiles)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (c) 2019-2022 Igara Studio S.A.
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -13,6 +13,7 @@
|
||||
#include "doc/object.h"
|
||||
#include "doc/tile.h"
|
||||
#include "doc/tileset_hash_table.h"
|
||||
#include "doc/with_user_data.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -22,7 +23,7 @@ namespace doc {
|
||||
class Remap;
|
||||
class Sprite;
|
||||
|
||||
class Tileset : public Object {
|
||||
class Tileset : public WithUserData {
|
||||
public:
|
||||
typedef std::vector<ImageRef> Tiles;
|
||||
typedef Tiles::iterator iterator;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -16,6 +16,7 @@
|
||||
#include "doc/image_io.h"
|
||||
#include "doc/subobjects_io.h"
|
||||
#include "doc/tileset.h"
|
||||
#include "doc/user_data_io.h"
|
||||
#include "doc/util.h"
|
||||
|
||||
#include <iostream>
|
||||
@ -24,6 +25,9 @@
|
||||
// field didn't exist in Aseprite v1.3-alpha3 (so read8() fails = 0)
|
||||
#define TILESET_VER1 1
|
||||
|
||||
// Tileset has UserData now
|
||||
#define TILESET_VER2 2
|
||||
|
||||
namespace doc {
|
||||
|
||||
using namespace base::serialization;
|
||||
@ -44,7 +48,8 @@ bool write_tileset(std::ostream& os,
|
||||
write_image(os, tileset->get(ti).get(), cancel);
|
||||
}
|
||||
|
||||
write8(os, TILESET_VER1);
|
||||
write8(os, TILESET_VER2);
|
||||
write_user_data(os, tileset->userData());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -67,11 +72,17 @@ Tileset* read_tileset(std::istream& is,
|
||||
|
||||
// Read extra version byte after tiles
|
||||
uint32_t ver = read8(is);
|
||||
if (ver == TILESET_VER1) {
|
||||
if (ver == TILESET_VER1 ||
|
||||
ver == TILESET_VER2) {
|
||||
if (isOldVersion)
|
||||
*isOldVersion = false;
|
||||
|
||||
tileset->setBaseIndex(1);
|
||||
|
||||
if (ver == TILESET_VER2) {
|
||||
UserData userData = read_user_data(is);
|
||||
tileset->setUserData(userData);
|
||||
}
|
||||
}
|
||||
// Old tileset used in internal versions (this was added to recover
|
||||
// old files, maybe in a future we could remove this code)
|
||||
|
36
tests/scripts/tileset.lua
Normal file
36
tests/scripts/tileset.lua
Normal file
@ -0,0 +1,36 @@
|
||||
-- Copyright (C) 2022 Igara Studio S.A.
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
dofile('./test_utils.lua')
|
||||
|
||||
do
|
||||
local spr = Sprite(4, 4, ColorMode.INDEXED)
|
||||
|
||||
app.command.NewLayer{ tilemap=true }
|
||||
local tilemap = spr.layers[2]
|
||||
|
||||
local tileset = tilemap.tileset
|
||||
assert(#tileset == 1);
|
||||
|
||||
app.useTool{
|
||||
tool='pencil',
|
||||
color=1,
|
||||
layer=tilemap,
|
||||
tilesetMode=TilesetMode.STACK,
|
||||
points={ Point(0, 0) }}
|
||||
assert(#tileset == 2)
|
||||
|
||||
assert(tileset.name == "")
|
||||
tileset.name = "Default Land"
|
||||
assert(tileset.name == "Default Land")
|
||||
|
||||
assert(tileset.data == "")
|
||||
tileset.data = "land"
|
||||
assert(tileset.data == "land")
|
||||
|
||||
assert(tileset.color == Color())
|
||||
tileset.color = Color(255, 0, 0)
|
||||
assert(tileset.color == Color(255, 0, 0))
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user