-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.nut
83 lines (69 loc) · 2.25 KB
/
plugin.nut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
///////////////////////////////////////////////////
//
// Attract-Mode Frontend - LaunchDecorator plugin
//
///////////////////////////////////////////////////
class UserConfig </ help="Runs script before/after game" /> {
</ label="ScriptRoot", help="Root path for script files", order=1 />
scriptRoot = "";
</ label="ScriptExtensions", help="Comma separated script extensions", order=2 />
scriptExtensions = "";
}
enum COMMANDTYPES {
BEFORE="before",
AFTER="after"
};
class LaunchDecorator {
config = null;
command = null;
extensions = null;
constructor() {
config = fe.get_config();
fe.add_transition_callback(this, "onTransition" );
extensions = split(config["scriptExtensions"], ",");
}
function withApex(value){
return "\"" + value + "\"";
}
function findScriptExtension(scriptName) {
foreach (ext in extensions) {
local script = fe.path_expand(scriptName + ext);
if (fe.path_test(script, PathTest.IsFile)){
return script;
}
}
return null;
}
function findScript(type, emulator, romName) {
// try game specific -> scriptRoot/{emulator}/{type}.{game}
local script = findScriptExtension(config["scriptRoot"] + "/" + emulator + "/" + type + "." + romName);
if (script==null){
// try emulator specific -> scriptRoot/{emulator}/{type}
script = findScriptExtension(config["scriptRoot"] + "/" + emulator + "/" + type);
}
return script;
}
function executeScript(script){
command = withApex(script) +" "+ withApex(fe.game_info(Info.Name)) +" "+ withApex(fe.game_info(Info.Emulator));
print("execute -> " + command + "\n");
if ( OS == "Windows" ) system( "cmd /c " + withApex(command));
else system( "/bin/sh -c " + withApex(command));
}
function onTransition( ttype, var, ttime ) {
local script;
if ( ScreenSaverActive )
return false;
switch ( ttype ){
case Transition.ToGame:
script = findScript(COMMANDTYPES.BEFORE, fe.game_info(Info.Emulator), fe.game_info(Info.Name));
if (script!=null) executeScript(script);
break;
case Transition.FromGame:
script = findScript(COMMANDTYPES.AFTER, fe.game_info(Info.Emulator), fe.game_info(Info.Name));
if (script!=null) executeScript(script);
break;
}
return false; // must return false
}
}
fe.plugin["LaunchDecorator"] <- LaunchDecorator();