mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15: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 "MameNames.h"
|
||||
#include "platform.h"
|
||||
#include "Scripting.h"
|
||||
#include "SystemData.h"
|
||||
#include "VolumeControl.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, "%ROM_RAW%", rom_raw);
|
||||
|
||||
Scripting::fireEvent("game-start", rom, basename);
|
||||
|
||||
LOG(LogInfo) << " " << command;
|
||||
int exitCode = runSystemCommand(command);
|
||||
|
||||
|
@ -290,6 +293,8 @@ void FileData::launchGame(Window* window)
|
|||
LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!";
|
||||
}
|
||||
|
||||
Scripting::fireEvent("game-end");
|
||||
|
||||
window->init();
|
||||
VolumeControl::getInstance()->init();
|
||||
window->normalizeNextUpdate();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "views/ViewController.h"
|
||||
#include "CollectionSystemManager.h"
|
||||
#include "EmulationStation.h"
|
||||
#include "Scripting.h"
|
||||
#include "SystemData.h"
|
||||
#include "VolumeControl.h"
|
||||
#include <SDL_events.h>
|
||||
|
@ -296,13 +297,15 @@ void GuiMenu::openUISettings()
|
|||
s->addSaveFunc([window, theme_set]
|
||||
{
|
||||
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;
|
||||
|
||||
Settings::getInstance()->setString("ThemeSet", theme_set->getSelected());
|
||||
|
||||
if(needReload)
|
||||
{
|
||||
Scripting::fireEvent("theme-changed", theme_set->getSelected(), oldTheme);
|
||||
CollectionSystemManager::get()->updateSystemsList();
|
||||
ViewController::get()->goToStart();
|
||||
ViewController::get()->reloadAll(); // TODO - replace this with some sort of signal-based implementation
|
||||
|
@ -472,6 +475,7 @@ void GuiMenu::openQuitMenu()
|
|||
row.makeAcceptInputHandler([window] {
|
||||
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
||||
[] {
|
||||
Scripting::fireEvent("quit");
|
||||
if(quitES("/tmp/es-restart") != 0)
|
||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
||||
}, "NO", nullptr));
|
||||
|
@ -487,9 +491,8 @@ void GuiMenu::openQuitMenu()
|
|||
row.makeAcceptInputHandler([window] {
|
||||
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
|
||||
[] {
|
||||
SDL_Event ev;
|
||||
ev.type = SDL_QUIT;
|
||||
SDL_PushEvent(&ev);
|
||||
Scripting::fireEvent("quit");
|
||||
quitES("");
|
||||
}, "NO", nullptr));
|
||||
});
|
||||
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] {
|
||||
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
||||
[] {
|
||||
Scripting::fireEvent("quit", "reboot");
|
||||
Scripting::fireEvent("reboot");
|
||||
if (quitES("/tmp/es-sysrestart") != 0)
|
||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
||||
}, "NO", nullptr));
|
||||
|
@ -511,6 +516,8 @@ void GuiMenu::openQuitMenu()
|
|||
row.makeAcceptInputHandler([window] {
|
||||
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
|
||||
[] {
|
||||
Scripting::fireEvent("quit", "shutdown");
|
||||
Scripting::fireEvent("shutdown");
|
||||
if (quitES("/tmp/es-shutdown") != 0)
|
||||
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
||||
}, "NO", nullptr));
|
||||
|
|
|
@ -92,6 +92,7 @@ set(CORE_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.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/Sound.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ThemeData.cpp
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "CECInput.h"
|
||||
#include "Log.h"
|
||||
#include "platform.h"
|
||||
#include "Scripting.h"
|
||||
#include "Window.h"
|
||||
#include <pugixml/src/pugixml.hpp>
|
||||
#include <SDL.h>
|
||||
|
@ -382,6 +383,9 @@ void InputManager::writeDeviceConfig(InputConfig* config)
|
|||
|
||||
config->writeToXML(root);
|
||||
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
|
||||
doOnFinish();
|
||||
|
|
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 "Log.h"
|
||||
#include "Scripting.h"
|
||||
#include "platform.h"
|
||||
#include <pugixml/src/pugixml.hpp>
|
||||
#include <algorithm>
|
||||
|
@ -193,6 +194,9 @@ void Settings::saveFile()
|
|||
}
|
||||
|
||||
doc.save_file(path.c_str());
|
||||
|
||||
Scripting::fireEvent("config-changed");
|
||||
Scripting::fireEvent("settings-changed");
|
||||
}
|
||||
|
||||
void Settings::loadFile()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "InputManager.h"
|
||||
#include "Log.h"
|
||||
#include "Renderer.h"
|
||||
#include "Scripting.h"
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
|
@ -277,8 +278,10 @@ void Window::render()
|
|||
if (!isProcessing() && mAllowSleep && (!mScreenSaver || mScreenSaver->allowSleep()))
|
||||
{
|
||||
// go to sleep
|
||||
mSleeping = true;
|
||||
onSleep();
|
||||
if (mSleeping == false) {
|
||||
mSleeping = true;
|
||||
onSleep();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -401,11 +404,12 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
|
|||
|
||||
void Window::onSleep()
|
||||
{
|
||||
Scripting::fireEvent("sleep");
|
||||
}
|
||||
|
||||
void Window::onWake()
|
||||
{
|
||||
|
||||
Scripting::fireEvent("wake");
|
||||
}
|
||||
|
||||
bool Window::isProcessing()
|
||||
|
|
|
@ -42,7 +42,8 @@ int runSystemCommand(const std::string& cmd_utf8)
|
|||
|
||||
int quitES(const std::string& filename)
|
||||
{
|
||||
touch(filename);
|
||||
if (!filename.empty())
|
||||
touch(filename);
|
||||
SDL_Event* quit = new SDL_Event();
|
||||
quit->type = SDL_QUIT;
|
||||
SDL_PushEvent(quit);
|
||||
|
|
Loading…
Reference in a new issue