summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-19 00:07:33 -0800
committerVito Caputo <vcaputo@pengaru.com>2019-11-19 00:08:46 -0800
commit2ab8f3c6a74f308a0909ff2963fe4216832e2f32 (patch)
tree6ac7774f8faa1dfc0dde00d4e908206465f316f6 /src
parent01ab4fea185b451ed2d281a21ae62ba8c85e5237 (diff)
rtv: randomize module settings
This is just a quick stab at randomizing settings, only multiple choice setings are randomized currently. For modules with settings, a new Settings: field is added to the caption showing the settings as the arguments one would pass to rototiller's module argument.
Diffstat (limited to 'src')
-rw-r--r--src/modules/rtv/rtv.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c
index 7febc85..a9d0399 100644
--- a/src/modules/rtv/rtv.c
+++ b/src/modules/rtv/rtv.c
@@ -3,6 +3,7 @@
#include "fb.h"
#include "rototiller.h"
+#include "settings.h"
#include "txt/txt.h"
#include "util.h"
@@ -14,10 +15,8 @@
* module starts overlaying the name, author, license, etc.
*
* Some TODO items:
- * - show captions (need text rendering)
* - optionally persist module contexts so they resume rather than restart
* - runtime-configurable duration
- * - randomize runtime settings of shown modules
* - redo the next module selection from random to
* walking the list and randomizing the list every
* time it completes a cycle. The current dumb
@@ -60,6 +59,45 @@ rototiller_module_t rtv_module = {
};
+static char * randomize_module_setup(const rototiller_module_t *module)
+{
+ settings_t *settings;
+ setting_desc_t *desc;
+ char *arg;
+
+ if (!module->setup)
+ return NULL;
+
+ settings = settings_new(NULL);
+ if (!settings)
+ return NULL;
+
+ while (module->setup(settings, &desc) > 0) {
+ if (desc->values) {
+ int n;
+
+ for (n = 0; desc->values[n]; n++);
+
+ n = rand() % n;
+
+ settings_add_value(settings, desc->key, desc->values[n]);
+ } else {
+ /* TODO: only randomizing multiple choice currently, so
+ * here I'm always taking the default for now.
+ */
+ settings_add_value(settings, desc->key, desc->preferred);
+ }
+
+ setting_desc_free(desc);
+ }
+
+ arg = settings_as_arg(settings);
+ settings_free(settings);
+
+ return arg;
+}
+
+
static void setup_next_module(rtv_context_t *ctxt)
{
time_t now = time(NULL);
@@ -81,6 +119,8 @@ static void setup_next_module(rtv_context_t *ctxt)
ctxt->module = ctxt->snow_module;
ctxt->next_switch = now + RTV_SNOW_DURATION_SECS;
} else {
+ char *setup;
+
do {
i = rand() % ctxt->n_modules;
} while (ctxt->modules[i] == &rtv_module ||
@@ -89,11 +129,17 @@ static void setup_next_module(rtv_context_t *ctxt)
ctxt->module = ctxt->modules[i];
- ctxt->caption = txt_newf("Title: %s\nAuthor: %s\nDescription: %s\nLicense: %s",
+ setup = randomize_module_setup(ctxt->module);
+
+ ctxt->caption = txt_newf("Title: %s\nAuthor: %s\nDescription: %s\nLicense: %s%s%s",
ctxt->module->name,
ctxt->module->author,
ctxt->module->description,
- ctxt->module->license);
+ ctxt->module->license,
+ setup ? "\nSettings: " : "",
+ setup ? setup : "");
+
+ free(setup);
ctxt->next_switch = now + RTV_DURATION_SECS;
ctxt->next_hide_caption = now + RTV_CAPTION_DURATION_SECS;
© All Rights Reserved