1// Aseprite
2// Copyright (C) 2022 Igara Studio S.A.
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "app/commands/cmd_export_sprite_sheet.h"
12#include "app/commands/command_ids.h"
13#include "app/context.h"
14#include "app/site.h"
15#include "app/ui/layer_frame_comboboxes.h"
16#include "doc/layer.h"
17
18namespace app {
19
20class ExportTilesetCommand : public ExportSpriteSheetCommand {
21public:
22 ExportTilesetCommand();
23protected:
24 void onResetValues() override;
25 bool onEnabled(Context* context) override;
26 void onExecute(Context* context) override;
27};
28
29ExportTilesetCommand::ExportTilesetCommand()
30 : ExportSpriteSheetCommand(CommandId::ExportTileset())
31{
32}
33
34void ExportTilesetCommand::onResetValues()
35{
36 ExportSpriteSheetCommand::onResetValues();
37
38 // Default values for Export Tileset
39 params().fromTilesets(true);
40 params().layer(kSelectedLayers);
41 params().dataFormat(SpriteSheetDataFormat::JsonArray);
42}
43
44bool ExportTilesetCommand::onEnabled(Context* ctx)
45{
46 if (ExportSpriteSheetCommand::onEnabled(ctx) &&
47 ctx->checkFlags(ContextFlags::HasActiveLayer)) {
48 Site site = ctx->activeSite();
49 if (site.layer() && site.layer()->isTilemap())
50 return true;
51 }
52 return false;
53}
54
55void ExportTilesetCommand::onExecute(Context* ctx)
56{
57 ExportSpriteSheetCommand::onExecute(ctx);
58}
59
60Command* CommandFactory::createExportTilesetCommand()
61{
62 return new ExportTilesetCommand;
63}
64
65} // namespace app
66