Add TXTP special value "all" in random groups

This commit is contained in:
bnnm 2020-11-01 16:49:43 +01:00
parent a41110404b
commit 48a32e6631
2 changed files with 17 additions and 5 deletions

View File

@ -190,7 +190,7 @@ group = -S2 #segment prev 2 (will start from pos.1 = bgm1+2, makes group of bgm
# may mix groups of auto and manual positions too, but results are harder to predict
```
Group `R` is meant to help with games that randomly select a file in a group. You can set with `>N` which file will be selected. This way you can quickly edit the TXTP and change the file (you could/should just comment files too, this is just for convenience in complex cases and testing). Files do need to exist and are parsed before being selected, and it can select groups too.
Group `R` is meant to help with games that randomly select a file in a group. You can set with `>N` which file will be selected. This way you can quickly edit the TXTP and change the file (you could just comment files too, this is just for convenience in complex cases and testing). You can also set `>-`, meaning "play all", basically turning `R` into `S`. Files do need to exist and are parsed before being selected, and it can select groups too.
```
bgm1.adx
bgm2.adx

View File

@ -10,6 +10,7 @@
#define TXTP_GROUP_MODE_SEGMENTED 'S'
#define TXTP_GROUP_MODE_LAYERED 'L'
#define TXTP_GROUP_MODE_RANDOM 'R'
#define TXTP_GROUP_RANDOM_ALL '-'
#define TXTP_GROUP_REPEAT 'R'
#define TXTP_POSITION_LOOPS 'L'
@ -479,9 +480,13 @@ static int make_group_random(txtp_header* txtp, int is_group, int position, int
return 1;
}
/* special case meaning "play all", basically for quick testing */
if (selected == count) {
return make_group_segment(txtp, is_group, position, count);
}
/* 0=actually random for fun and testing, but undocumented since random music is kinda weird, may change anytime
* (plus foobar caches song duration so it can get strange if randoms are too different) */
* (plus foobar caches song duration unless .txtp is modifies, so it can get strange if randoms are too different) */
if (selected < 0) {
static int random_seed = 0;
srand((unsigned)txtp + random_seed++); /* whatevs */
@ -1518,11 +1523,18 @@ static int add_group(txtp_header* txtp, char* line) {
line += n;
}
m = sscanf(line, " >%d%n", &cfg.selected, &n);
if (m == 1) {
cfg.selected--; /* externally 1=first but internally 0=first */
m = sscanf(line, " >%c%n", &c, &n);
if (m == 1 && c == TXTP_GROUP_RANDOM_ALL) {
cfg.selected = cfg.count; /* special meaning */
line += n;
}
else {
m = sscanf(line, " >%d%n", &cfg.selected, &n);
if (m == 1) {
cfg.selected--; /* externally 1=first but internally 0=first */
line += n;
}
}
parse_params(&cfg.group_settings, line);