Add ENABLE_SCRIPTING flag

This commit is contained in:
David Capello 2016-11-21 10:25:27 -03:00
parent 0b07602573
commit 128ba90394
12 changed files with 83 additions and 19 deletions

View File

@ -70,6 +70,7 @@ option(USE_SHARED_FREETYPE "Use shared FreeType library" off)
option(USE_SHARED_ALLEGRO4 "Use shared Allegro 4 library (without resize support)" off)
option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" off)
option(ENABLE_UPDATER "Enable automatic check for updates" on)
option(ENABLE_SCRIPTING "Compile with scripting support" on)
option(ENABLE_WEBSERVER "Enable support to run a webserver (for HTML5 gamedev)" off)
option(ENABLE_TESTS "Enable the unit tests" off)
option(ENABLE_TRIAL_MODE "Compile the trial version" off)

View File

@ -97,10 +97,13 @@ add_subdirectory(gfx)
add_subdirectory(net)
add_subdirectory(render)
add_subdirectory(docio)
add_subdirectory(script)
add_subdirectory(she)
add_subdirectory(ui)
if(ENABLE_SCRIPTING)
add_subdirectory(script)
endif()
if(ENABLE_UPDATER)
add_subdirectory(updater)
endif()

View File

@ -60,6 +60,10 @@ if(WITH_WEBP_SUPPORT)
add_definitions(-DASEPRITE_WITH_WEBP_SUPPORT)
endif()
if(ENABLE_SCRIPTING)
add_definitions(-DENABLE_SCRIPTING)
endif()
######################################################################
# app-lib target
@ -89,6 +93,23 @@ if(WITH_WEBP_SUPPORT)
list(APPEND file_formats file/webp_format.cpp)
endif()
set(scripting_files)
if(ENABLE_SCRIPTING)
set(scripting_files
commands/cmd_developer_console.cpp
commands/cmd_run_script.cpp
script/app_object.cpp
script/app_scripting.cpp
script/console_object.cpp
script/image_class.cpp
script/image_wrap.cpp
script/selection_class.cpp
script/sprite_class.cpp
script/sprite_wrap.cpp
shell.cpp
ui/devconsole_view.cpp)
endif()
add_library(app-lib
app.cpp
app_brushes.cpp
@ -185,7 +206,6 @@ add_library(app-lib
commands/cmd_crop.cpp
commands/cmd_cut.cpp
commands/cmd_deselect_mask.cpp
commands/cmd_developer_console.cpp
commands/cmd_discard_brush.cpp
commands/cmd_duplicate_layer.cpp
commands/cmd_duplicate_sprite.cpp
@ -325,17 +345,8 @@ add_library(app-lib
res/resources_loader.cpp
resource_finder.cpp
rw_lock.cpp
script/app_object.cpp
script/app_scripting.cpp
script/console_object.cpp
script/image_class.cpp
script/image_wrap.cpp
script/selection_class.cpp
script/sprite_class.cpp
script/sprite_wrap.cpp
send_crash.cpp
shade.cpp
shell.cpp
snap_to_grid.cpp
thumbnail_generator.cpp
tools/active_tool.cpp
@ -364,7 +375,6 @@ add_library(app-lib
ui/color_wheel.cpp
ui/configure_timeline_popup.cpp
ui/context_bar.cpp
ui/devconsole_view.cpp
ui/document_view.cpp
ui/drop_down_button.cpp
ui/editor/brush_preview.cpp
@ -445,6 +455,7 @@ add_library(app-lib
xml_document.cpp
xml_exception.cpp
${data_recovery_files}
${scripting_files}
${generated_files})
target_link_libraries(app-lib
@ -460,7 +471,6 @@ target_link_libraries(app-lib
gfx-lib
net-lib
render-lib
script-lib
she
ui-lib
undo
@ -472,6 +482,10 @@ target_link_libraries(app-lib
${ZLIB_LIBRARIES}
${FREETYPE_LIBRARIES})
if(ENABLE_SCRIPTING)
target_link_libraries(app-lib script-lib)
endif()
if(ENABLE_UPDATER)
target_link_libraries(app-lib updater-lib)
endif()

View File

@ -35,9 +35,7 @@
#include "app/pref/preferences.h"
#include "app/recent_files.h"
#include "app/resource_finder.h"
#include "app/script/app_scripting.h"
#include "app/send_crash.h"
#include "app/shell.h"
#include "app/tools/active_tool.h"
#include "app/tools/tool_box.h"
#include "app/ui/backup_indicator.h"
@ -69,7 +67,6 @@
#include "doc/site.h"
#include "doc/sprite.h"
#include "render/render.h"
#include "script/engine_delegate.h"
#include "she/display.h"
#include "she/error.h"
#include "she/system.h"
@ -78,6 +75,12 @@
#include <iostream>
#ifdef ENABLE_SCRIPTING
#include "app/script/app_scripting.h"
#include "app/shell.h"
#include "script/engine_delegate.h"
#endif
#ifdef ENABLE_STEAM
#include "steam/steam.h"
#endif
@ -135,12 +138,14 @@ public:
};
#ifdef ENABLE_SCRIPTING
class StdoutEngineDelegate : public script::EngineDelegate {
public:
void onConsolePrint(const char* text) override {
printf("%s\n", text);
}
};
#endif
App* App::m_instance = NULL;
@ -521,6 +526,7 @@ void App::initialize(const AppOptions& options)
}
}
}
#ifdef ENABLE_SCRIPTING
// --script <filename>
else if (opt == &options.script()) {
std::string script = value.value();
@ -529,6 +535,7 @@ void App::initialize(const AppOptions& options)
AppScripting engine(&delegate);
engine.evalFile(script);
}
#endif
// --list-layers
else if (opt == &options.listLayers()) {
listLayers = true;
@ -696,6 +703,7 @@ void App::run()
ui::Manager::getDefault()->run();
}
#ifdef ENABLE_SCRIPTING
// Start shell to execute scripts.
if (m_isShell) {
StdoutEngineDelegate delegate;
@ -704,6 +712,7 @@ void App::run()
Shell shell;
shell.run(engine);
}
#endif
// Destroy all documents in the UIContext.
const doc::Documents& docs = m_modules->m_ui_context.documents();

View File

@ -25,7 +25,9 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_startShell(false)
, m_verboseLevel(kNoVerbose)
, m_palette(m_po.add("palette").requiresValue("<filename>").description("Use a specific palette by default"))
#ifdef ENABLE_SCRIPTING
, m_shell(m_po.add("shell").description("Start an interactive console to execute scripts"))
#endif
, m_batch(m_po.add("batch").mnemonic('b').description("Do not start the UI"))
, m_saveAs(m_po.add("save-as").requiresValue("<filename>").description("Save the last given document with other format"))
, m_scale(m_po.add("scale").requiresValue("<factor>").description("Resize all previous opened documents"))
@ -49,7 +51,9 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_trim(m_po.add("trim").description("Trim all images before exporting"))
, m_crop(m_po.add("crop").requiresValue("x,y,width,height").description("Crop all the images to the given rectangle"))
, m_filenameFormat(m_po.add("filename-format").requiresValue("<fmt>").description("Special format to generate filenames"))
#ifdef ENABLE_SCRIPTING
, m_script(m_po.add("script").requiresValue("<filename>").description("Execute a specific script"))
#endif
, m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers in JSON data"))
, m_listTags(m_po.add("list-tags").description("List tags of the next given sprite sprite\nor include frame tags in JSON data"))
, m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done"))
@ -66,7 +70,9 @@ AppOptions::AppOptions(int argc, const char* argv[])
m_verboseLevel = kVerbose;
m_paletteFileName = m_po.value_of(m_palette);
#ifdef ENABLE_SCRIPTING
m_startShell = m_po.enabled(m_shell);
#endif
if (m_po.enabled(m_help)) {
showHelp();
@ -77,7 +83,11 @@ AppOptions::AppOptions(int argc, const char* argv[])
m_startUI = false;
}
if (m_po.enabled(m_shell) || m_po.enabled(m_batch)) {
if (
#ifdef ENABLE_SCRIPTING
m_po.enabled(m_shell) ||
#endif
m_po.enabled(m_batch)) {
m_startUI = false;
}
}

View File

@ -63,7 +63,9 @@ public:
const Option& trim() const { return m_trim; }
const Option& crop() const { return m_crop; }
const Option& filenameFormat() const { return m_filenameFormat; }
#ifdef ENABLE_SCRIPTING
const Option& script() const { return m_script; }
#endif
const Option& listLayers() const { return m_listLayers; }
const Option& listTags() const { return m_listTags; }
@ -81,7 +83,9 @@ private:
std::string m_paletteFileName;
Option& m_palette;
#ifdef ENABLE_SCRIPTING
Option& m_shell;
#endif
Option& m_batch;
Option& m_saveAs;
Option& m_scale;
@ -105,7 +109,9 @@ private:
Option& m_trim;
Option& m_crop;
Option& m_filenameFormat;
#ifdef ENABLE_SCRIPTING
Option& m_script;
#endif
Option& m_listLayers;
Option& m_listTags;

View File

@ -8,6 +8,10 @@
#include "config.h"
#endif
#ifndef ENABLE_SCRIPTING
#error ENABLE_SCRIPTING must be defined
#endif
#include "app/app.h"
#include "app/commands/command.h"
#include "app/ui/main_window.h"

View File

@ -8,6 +8,10 @@
#include "config.h"
#endif
#ifndef ENABLE_SCRIPTING
#error ENABLE_SCRIPTING must be defined
#endif
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/console.h"

View File

@ -29,7 +29,6 @@ FOR_EACH_COMMAND(CropSprite)
FOR_EACH_COMMAND(Cut)
FOR_EACH_COMMAND(DeselectMask)
FOR_EACH_COMMAND(Despeckle)
FOR_EACH_COMMAND(DeveloperConsole)
FOR_EACH_COMMAND(DiscardBrush)
FOR_EACH_COMMAND(DuplicateLayer)
FOR_EACH_COMMAND(DuplicateSprite)
@ -101,7 +100,6 @@ FOR_EACH_COMMAND(ReplaceColor)
FOR_EACH_COMMAND(ReselectMask)
FOR_EACH_COMMAND(ReverseFrames)
FOR_EACH_COMMAND(Rotate)
FOR_EACH_COMMAND(RunScript)
FOR_EACH_COMMAND(SaveFile)
FOR_EACH_COMMAND(SaveFileAs)
FOR_EACH_COMMAND(SaveFileCopyAs)
@ -136,3 +134,8 @@ FOR_EACH_COMMAND(Undo)
FOR_EACH_COMMAND(UndoHistory)
FOR_EACH_COMMAND(UnlinkCel)
FOR_EACH_COMMAND(Zoom)
#ifdef ENABLE_SCRIPTING
FOR_EACH_COMMAND(DeveloperConsole)
FOR_EACH_COMMAND(RunScript)
#endif

View File

@ -8,6 +8,10 @@
#include "config.h"
#endif
#ifndef ENABLE_SCRIPTING
#error ENABLE_SCRIPTING must be defined
#endif
#include "app/shell.h"
#include "script/engine.h"

View File

@ -8,6 +8,10 @@
#include "config.h"
#endif
#ifndef ENABLE_SCRIPTING
#error ENABLE_SCRIPTING must be defined
#endif
#include "app/ui/devconsole_view.h"
#include "app/app_menus.h"

View File

@ -241,6 +241,7 @@ bool MainWindow::isHomeSelected()
void MainWindow::showDevConsole()
{
#ifdef ENABLE_SCRIPTING
if (!m_devConsoleView)
m_devConsoleView = new DevConsoleView;
@ -248,6 +249,7 @@ void MainWindow::showDevConsole()
m_workspace->addView(m_devConsoleView);
m_tabsBar->selectTab(m_devConsoleView);
}
#endif
}
void MainWindow::setMode(Mode mode)