mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 22:25:38 +00:00
Merge pull request #551 from jrassa/scripting
implement scripting support
This commit is contained in:
commit
91d0b6c918
|
@ -10,6 +10,7 @@
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "MameNames.h"
|
#include "MameNames.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "Scripting.h"
|
||||||
#include "SystemData.h"
|
#include "SystemData.h"
|
||||||
#include "VolumeControl.h"
|
#include "VolumeControl.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
@ -282,6 +283,8 @@ void FileData::launchGame(Window* window)
|
||||||
command = Utils::String::replace(command, "%BASENAME%", basename);
|
command = Utils::String::replace(command, "%BASENAME%", basename);
|
||||||
command = Utils::String::replace(command, "%ROM_RAW%", rom_raw);
|
command = Utils::String::replace(command, "%ROM_RAW%", rom_raw);
|
||||||
|
|
||||||
|
Scripting::fireEvent("game-start", rom, basename);
|
||||||
|
|
||||||
LOG(LogInfo) << " " << command;
|
LOG(LogInfo) << " " << command;
|
||||||
int exitCode = runSystemCommand(command);
|
int exitCode = runSystemCommand(command);
|
||||||
|
|
||||||
|
@ -290,6 +293,8 @@ void FileData::launchGame(Window* window)
|
||||||
LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!";
|
LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Scripting::fireEvent("game-end");
|
||||||
|
|
||||||
window->init();
|
window->init();
|
||||||
VolumeControl::getInstance()->init();
|
VolumeControl::getInstance()->init();
|
||||||
window->normalizeNextUpdate();
|
window->normalizeNextUpdate();
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "views/ViewController.h"
|
#include "views/ViewController.h"
|
||||||
#include "CollectionSystemManager.h"
|
#include "CollectionSystemManager.h"
|
||||||
#include "EmulationStation.h"
|
#include "EmulationStation.h"
|
||||||
|
#include "Scripting.h"
|
||||||
#include "SystemData.h"
|
#include "SystemData.h"
|
||||||
#include "VolumeControl.h"
|
#include "VolumeControl.h"
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
|
@ -296,13 +297,15 @@ void GuiMenu::openUISettings()
|
||||||
s->addSaveFunc([window, theme_set]
|
s->addSaveFunc([window, theme_set]
|
||||||
{
|
{
|
||||||
bool needReload = false;
|
bool needReload = false;
|
||||||
if(Settings::getInstance()->getString("ThemeSet") != theme_set->getSelected())
|
std::string oldTheme = Settings::getInstance()->getString("ThemeSet");
|
||||||
|
if(oldTheme != theme_set->getSelected())
|
||||||
needReload = true;
|
needReload = true;
|
||||||
|
|
||||||
Settings::getInstance()->setString("ThemeSet", theme_set->getSelected());
|
Settings::getInstance()->setString("ThemeSet", theme_set->getSelected());
|
||||||
|
|
||||||
if(needReload)
|
if(needReload)
|
||||||
{
|
{
|
||||||
|
Scripting::fireEvent("theme-changed", theme_set->getSelected(), oldTheme);
|
||||||
CollectionSystemManager::get()->updateSystemsList();
|
CollectionSystemManager::get()->updateSystemsList();
|
||||||
ViewController::get()->goToStart();
|
ViewController::get()->goToStart();
|
||||||
ViewController::get()->reloadAll(); // TODO - replace this with some sort of signal-based implementation
|
ViewController::get()->reloadAll(); // TODO - replace this with some sort of signal-based implementation
|
||||||
|
@ -472,6 +475,7 @@ void GuiMenu::openQuitMenu()
|
||||||
row.makeAcceptInputHandler([window] {
|
row.makeAcceptInputHandler([window] {
|
||||||
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
||||||
[] {
|
[] {
|
||||||
|
Scripting::fireEvent("quit");
|
||||||
if(quitES("/tmp/es-restart") != 0)
|
if(quitES("/tmp/es-restart") != 0)
|
||||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
|
@ -487,9 +491,8 @@ void GuiMenu::openQuitMenu()
|
||||||
row.makeAcceptInputHandler([window] {
|
row.makeAcceptInputHandler([window] {
|
||||||
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
|
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
|
||||||
[] {
|
[] {
|
||||||
SDL_Event ev;
|
Scripting::fireEvent("quit");
|
||||||
ev.type = SDL_QUIT;
|
quitES("");
|
||||||
SDL_PushEvent(&ev);
|
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
});
|
});
|
||||||
row.addElement(std::make_shared<TextComponent>(window, "QUIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
row.addElement(std::make_shared<TextComponent>(window, "QUIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
||||||
|
@ -500,6 +503,8 @@ void GuiMenu::openQuitMenu()
|
||||||
row.makeAcceptInputHandler([window] {
|
row.makeAcceptInputHandler([window] {
|
||||||
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
||||||
[] {
|
[] {
|
||||||
|
Scripting::fireEvent("quit", "reboot");
|
||||||
|
Scripting::fireEvent("reboot");
|
||||||
if (quitES("/tmp/es-sysrestart") != 0)
|
if (quitES("/tmp/es-sysrestart") != 0)
|
||||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
|
@ -511,6 +516,8 @@ void GuiMenu::openQuitMenu()
|
||||||
row.makeAcceptInputHandler([window] {
|
row.makeAcceptInputHandler([window] {
|
||||||
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
|
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
|
||||||
[] {
|
[] {
|
||||||
|
Scripting::fireEvent("quit", "shutdown");
|
||||||
|
Scripting::fireEvent("shutdown");
|
||||||
if (quitES("/tmp/es-shutdown") != 0)
|
if (quitES("/tmp/es-shutdown") != 0)
|
||||||
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
|
|
|
@ -92,6 +92,7 @@ set(CORE_SOURCES
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_init_sdlgl.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_init_sdlgl.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Scripting.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Settings.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Settings.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ThemeData.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ThemeData.cpp
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "CECInput.h"
|
#include "CECInput.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "Scripting.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include <pugixml/src/pugixml.hpp>
|
#include <pugixml/src/pugixml.hpp>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
@ -383,6 +384,9 @@ void InputManager::writeDeviceConfig(InputConfig* config)
|
||||||
config->writeToXML(root);
|
config->writeToXML(root);
|
||||||
doc.save_file(path.c_str());
|
doc.save_file(path.c_str());
|
||||||
|
|
||||||
|
Scripting::fireEvent("config-changed");
|
||||||
|
Scripting::fireEvent("controls-changed");
|
||||||
|
|
||||||
// execute any onFinish commands and re-load the config for changes
|
// execute any onFinish commands and re-load the config for changes
|
||||||
doOnFinish();
|
doOnFinish();
|
||||||
loadInputConfig(config);
|
loadInputConfig(config);
|
||||||
|
|
36
es-core/src/Scripting.cpp
Normal file
36
es-core/src/Scripting.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#include "Scripting.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "platform.h"
|
||||||
|
#include "utils/FileSystemUtil.h"
|
||||||
|
|
||||||
|
namespace Scripting
|
||||||
|
{
|
||||||
|
void fireEvent(const std::string& eventName, const std::string& arg1, const std::string& arg2)
|
||||||
|
{
|
||||||
|
LOG(LogDebug) << "fireEvent: " << eventName << " " << arg1 << " " << arg2;
|
||||||
|
|
||||||
|
std::list<std::string> scriptDirList;
|
||||||
|
std::string test;
|
||||||
|
|
||||||
|
// check in exepath
|
||||||
|
test = Utils::FileSystem::getExePath() + "/scripts/" + eventName;
|
||||||
|
if(Utils::FileSystem::exists(test))
|
||||||
|
scriptDirList.push_back(test);
|
||||||
|
|
||||||
|
// check in homepath
|
||||||
|
test = Utils::FileSystem::getHomePath() + "/.emulationstation/scripts/" + eventName;
|
||||||
|
if(Utils::FileSystem::exists(test))
|
||||||
|
scriptDirList.push_back(test);
|
||||||
|
|
||||||
|
for(std::list<std::string>::const_iterator dirIt = scriptDirList.cbegin(); dirIt != scriptDirList.cend(); ++dirIt) {
|
||||||
|
std::list<std::string> scripts = Utils::FileSystem::getDirContent(*dirIt);
|
||||||
|
for (std::list<std::string>::const_iterator it = scripts.cbegin(); it != scripts.cend(); ++it) {
|
||||||
|
// append folder to path
|
||||||
|
std::string script = *it + " \"" + arg1 + "\" \"" + arg2 + "\"";
|
||||||
|
LOG(LogDebug) << " executing: " << script;
|
||||||
|
runSystemCommand(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Scripting::
|
12
es-core/src/Scripting.h
Normal file
12
es-core/src/Scripting.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
#ifndef ES_CORE_SCRIPTING_H
|
||||||
|
#define ES_CORE_SCRIPTING_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Scripting
|
||||||
|
{
|
||||||
|
void fireEvent(const std::string& eventName, const std::string& arg1="", const std::string& arg2="");
|
||||||
|
} // Scripting::
|
||||||
|
|
||||||
|
#endif //ES_CORE_SCRIPTING_H
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "utils/FileSystemUtil.h"
|
#include "utils/FileSystemUtil.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Scripting.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <pugixml/src/pugixml.hpp>
|
#include <pugixml/src/pugixml.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -193,6 +194,9 @@ void Settings::saveFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.save_file(path.c_str());
|
doc.save_file(path.c_str());
|
||||||
|
|
||||||
|
Scripting::fireEvent("config-changed");
|
||||||
|
Scripting::fireEvent("settings-changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadFile()
|
void Settings::loadFile()
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "InputManager.h"
|
#include "InputManager.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include "Scripting.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
@ -277,11 +278,13 @@ void Window::render()
|
||||||
if (!isProcessing() && mAllowSleep && (!mScreenSaver || mScreenSaver->allowSleep()))
|
if (!isProcessing() && mAllowSleep && (!mScreenSaver || mScreenSaver->allowSleep()))
|
||||||
{
|
{
|
||||||
// go to sleep
|
// go to sleep
|
||||||
|
if (mSleeping == false) {
|
||||||
mSleeping = true;
|
mSleeping = true;
|
||||||
onSleep();
|
onSleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Window::normalizeNextUpdate()
|
void Window::normalizeNextUpdate()
|
||||||
{
|
{
|
||||||
|
@ -401,11 +404,12 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
|
||||||
|
|
||||||
void Window::onSleep()
|
void Window::onSleep()
|
||||||
{
|
{
|
||||||
|
Scripting::fireEvent("sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::onWake()
|
void Window::onWake()
|
||||||
{
|
{
|
||||||
|
Scripting::fireEvent("wake");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::isProcessing()
|
bool Window::isProcessing()
|
||||||
|
|
|
@ -42,6 +42,7 @@ int runSystemCommand(const std::string& cmd_utf8)
|
||||||
|
|
||||||
int quitES(const std::string& filename)
|
int quitES(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
if (!filename.empty())
|
||||||
touch(filename);
|
touch(filename);
|
||||||
SDL_Event* quit = new SDL_Event();
|
SDL_Event* quit = new SDL_Event();
|
||||||
quit->type = SDL_QUIT;
|
quit->type = SDL_QUIT;
|
||||||
|
|
Loading…
Reference in a new issue