lua: Fix app.useTool() tests when we run in batch/non-UI mode

* Tools must use the default configuration when we run in -batch mode
* Fixed app_get_current_pixel_format() when ENABLE_UI is disabled so
  the color= parameter of app.useTool{} depends on the activeSprite
  color mode
This commit is contained in:
David Capello 2019-04-24 18:31:43 -03:00
parent e8a057a334
commit 5cf762c9cf
10 changed files with 65 additions and 19 deletions

View File

@ -450,6 +450,14 @@ App::~App()
delete m_legacy;
delete m_modules;
// Save preferences only if we are running in GUI mode. when we
// run in batch mode we might want to reset some preferences so
// the scripts have a reproducible behavior. Those reset
// preferences must not be saved.
if (isGui())
m_coreModules->m_preferences.save();
delete m_coreModules;
#ifdef ENABLE_UI
@ -639,18 +647,14 @@ void app_rebuild_documents_tabs()
PixelFormat app_get_current_pixel_format()
{
#ifdef ENABLE_UI
Context* context = UIContext::instance();
ASSERT(context != NULL);
Context* ctx = App::instance()->context();
ASSERT(ctx);
Doc* document = context->activeDocument();
if (document != NULL)
return document->sprite()->pixelFormat();
Doc* doc = ctx->activeDocument();
if (doc)
return doc->sprite()->pixelFormat();
else
return IMAGE_RGB;
#else // ENABLE_UI
return IMAGE_RGB;
#endif
}
void app_default_statusbar_message()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -274,6 +274,11 @@ void del_config_value(const char* section, const char* name)
g_configs.back()->deleteValue(section, name);
}
void del_config_section(const char* section)
{
g_configs.back()->deleteSection(section);
}
base::paths enum_config_keys(const char* section)
{
base::paths keys;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -58,6 +58,7 @@ namespace app {
void set_config_color(const char* section, const char* name, const app::Color& value);
void del_config_value(const char* section, const char* name);
void del_config_section(const char* section);
base::paths enum_config_keys(const char* section);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -57,7 +57,9 @@ Preferences::Preferences()
Preferences::~Preferences()
{
save();
// Don't save preferences, this must be done by the client of the
// Preferences instance (the App class).
//save();
for (auto& pair : m_tools)
delete pair.second;
@ -148,6 +150,16 @@ DocumentPreferences& Preferences::document(const Doc* doc)
}
}
void Preferences::resetToolPreferences(tools::Tool* tool)
{
auto it = m_tools.find(tool->getId());
if (it != m_tools.end())
m_tools.erase(it);
std::string section = std::string("tool.") + tool->getId();
del_config_section(section.c_str());
}
void Preferences::removeDocument(Doc* doc)
{
ASSERT(doc);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -64,6 +64,11 @@ namespace app {
ToolPreferences& tool(tools::Tool* tool);
DocumentPreferences& document(const Doc* doc);
// Used to reset the tool preferences in scripting mode when the
// UI is not available (so scripts have a common default
// preferences and a reproducible behavior for automation).
void resetToolPreferences(tools::Tool* tool);
// Remove one document explicitly (this can be used if the
// document used in Preferences::document() function wasn't member
// of UIContext.

View File

@ -337,7 +337,6 @@ public:
#endif
}
};
//////////////////////////////////////////////////////////////////////
@ -534,6 +533,8 @@ public:
#ifdef ENABLE_UI
if (redraw)
update_screen_for_document(m_document);
#else
(void)redraw; // To avoid warning about unused variable
#endif
}
@ -700,6 +701,12 @@ tools::ToolLoop* create_tool_loop_for_script(
const tools::ToolLoop::Button toolLoopButton = tools::ToolLoop::Left;
tools::Controller* controller = tool->getController(toolLoopButton);
// If we don't have the UI available, we reset the tools
// preferences, so scripts that are executed in batch mode have a
// reproducible behavior.
if (!context->isUIAvailable())
Preferences::instance().resetToolPreferences(tool);
return new ToolLoopImpl(
nullptr, site, context,
tool, ink, controller, brush,

View File

@ -1,4 +1,5 @@
Copyright (c) 2014 David Capello
Copyright (C) 2019 Igara Studio S.A.
Copyright (C) 2014-2017 David Capello
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -1,4 +1,3 @@
# Aseprite Config Library
*Copyright (C) 2014 David Capello*
> Distributed under [MIT license](LICENSE.txt)

View File

@ -1,5 +1,6 @@
// Aseprite Config Library
// Copyright (c) 2014-2017 David Capello
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2014-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -83,6 +84,10 @@ public:
m_ini.Delete(section, name, true);
}
void deleteSection(const char* section) {
m_ini.Delete(section, nullptr, true);
}
void load(const std::string& filename) {
m_filename = filename;
@ -181,6 +186,11 @@ void CfgFile::deleteValue(const char* section, const char* name)
m_impl->deleteValue(section, name);
}
void CfgFile::deleteSection(const char* section)
{
m_impl->deleteSection(section);
}
void CfgFile::load(const std::string& filename)
{
m_impl->load(filename);

View File

@ -1,5 +1,6 @@
// Aseprite Config Library
// Copyright (c) 2014-2016 David Capello
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2014-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -34,6 +35,7 @@ namespace cfg {
void setDoubleValue(const char* section, const char* name, double value);
void deleteValue(const char* section, const char* name);
void deleteSection(const char* section);
void load(const std::string& filename);
void save();