-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.nut
More file actions
64 lines (57 loc) · 1.97 KB
/
Copy pathplugin.nut
File metadata and controls
64 lines (57 loc) · 1.97 KB
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
/**
* Random Launch Plugin
*
* @summary Randomly select and launch an unplayed game.
* @version 0.0.1 2025-09-28
* @author Chadnaut
* @url https://github.com/Chadnaut/Attract-Mode-Experiments
*/
class UserConfig </ help="Description placeholder" /> {
</ label="Info", help="The game info to randomly choose", options="Unplayed,Favourite", order=0 /> info = "Unplayed"
</ label="Launch", help="Launch game after selection", options="Yes,No", order=1 /> launch = "Yes"
}
class RandomLaunch {
/** @type {UserConfig} */
config = null
constructor() {
config = fe.get_config()
fe.add_signal_handler(this, "on_signal")
}
// Find indexes of games with specific info
function get_indexes() {
local arr = []
local offset = -fe.list.index
for (local i = 0, n = fe.list.size; i < n; i++) {
switch (config.info) {
case "Unplayed":
if (fe.game_info(Info.PlayedCount, i + offset) == "0") arr.push(i)
break
case "Favourite":
if (fe.game_info(Info.Favourite, i + offset) == "1") arr.push(i)
break
}
}
// Prevent current index entering the list
local i = arr.find(fe.list.index)
if (i != null) arr.remove(i)
return arr
}
// Select a random game from get_indexes, or if there are none then just any random
function select_random() {
local indexes = get_indexes()
local len = indexes.len()
fe.list.index = len
? indexes[(len * rand()) / RAND_MAX]
: (fe.list.size * rand()) / RAND_MAX
}
// Capture the random_game signal and select our own
function on_signal(signal) {
if (signal == "random_game") {
select_random()
if (config.launch == "Yes") fe.signal("select")
return true
}
return false
}
}
fe.plugin["RandomLaunch"] <- RandomLaunch()