Author SHA1 Message Date
zephyr 6262e3c430 cmd/factorfactor: initial work 2026-09-23 09:17:27 -04:00
zephyr 1cfabb18f5 zenno: fix type error on fake data
ci/woodpecker/push/horsebot Pipeline was successful
ci/woodpecker/push/zenno Pipeline was successful
2026-09-22 22:31:12 -04:00
zephyr bf4e750825 zenno/chara/convo: hyperlink to umadump 2026-09-22 22:30:00 -04:00
zephyr 57ffadb06a zenno/chara/convo: integrate umadump talk gallery
ci/woodpecker/push/horsebot Pipeline was successful
ci/woodpecker/push/zenno Pipeline failed
Fixes #47.
2026-09-22 22:25:43 -04:00
6 changed files with 297 additions and 8 deletions
+77
View File
@@ -0,0 +1,77 @@
package main
import (
"log/slog"
"git.sunturtle.xyz/zephyr/horse"
"git.sunturtle.xyz/zephyr/horse/umadump/ism"
)
// For each gain type from inspiration (stats, caps, aptitudes, skills):
// find all activated sparks that can give that gain type.
// Then, find all subsets of effect groups among those sparks
// that have effects summing to those observed
// (or more if the .end_info result is maxed),
// with the restriction that one comes from each spark.
// Deduplicate permutations.
// Lastly, find the intersection of possible effects from sparks that appear
// multiple times.
//
// To some extent, we rely on there being no sparks with the random stats effect type,
// although we also don't know the distribution of stats from overcapped skill hints.
type target struct {
spark *horse.Spark
group int
effect horse.SparkEffect
}
func skilltargets(sparks []horse.Spark) map[horse.SkillID]map[horse.SparkID][]target {
r := make(map[horse.SkillID]map[horse.SparkID][]target)
for i, sp := range sparks {
for j, g := range sp.Effects {
for _, e := range g {
if e.Target != horse.SparkSkillHint {
continue
}
if r[horse.SkillID(e.Value1)] == nil {
r[horse.SkillID(e.Value1)] = make(map[horse.SparkID][]target)
}
r[horse.SkillID(e.Value1)][sp.ID] = append(r[horse.SkillID(e.Value1)][sp.ID], target{&sparks[i], j, e})
}
}
}
return r
}
func resolveSkills(tab tables, career *ism.WorkIdleSingleMode)
// skillsparks appends all activated sparks that can yield a given skill to r.
// It assumes that no spark can give multiple skills.
func skillsparks(tab tables, sparks []ism.Factor, id horse.SkillID, r []*horse.Spark) []*horse.Spark {
for _, f := range sparks {
sp := tab.sparks[f.FactorID]
if sp == nil {
// ATM we do generally exclude Carnival Bonus from spark info.
// Better to check.
slog.Warn("skipped spark", slog.Int("id", int(f.FactorID)))
continue
}
if sparkHasSkill(sp, id) {
r = append(r, sp)
}
}
return r
}
func sparkHasSkill(sp *horse.Spark, id horse.SkillID) bool {
for _, g := range sp.Effects {
for _, e := range g {
if e.Target != horse.SparkSkillHint {
continue
}
return id == horse.SkillID(e.Value1)
}
}
return false
}
+111
View File
@@ -0,0 +1,111 @@
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log/slog"
"os"
"os/signal"
"path/filepath"
"slices"
"git.sunturtle.xyz/zephyr/horse/mdb"
"git.sunturtle.xyz/zephyr/horse/umadump/ism"
"golang.org/x/sync/errgroup"
"zombiezen.com/go/sqlite"
"zombiezen.com/go/sqlite/sqlitex"
)
func main() {
var (
mdbf string
dirs []string
files []string
)
flag.StringVar(&mdbf, "-mdb", "", "`path` to master.mdb")
flag.Func("d", "idle_single_mode `dir`ectory (may be specified multiple times)", func(s string) error {
dirs = append(dirs, s)
return nil
})
flag.Parse()
files = slices.Clone(flag.Args())
for _, dir := range dirs {
ds, err := os.ReadDir(dir)
if err != nil {
slog.Error("getting files in directory", slog.String("dir", dir), slog.Any("err", err))
os.Exit(1)
}
for _, d := range ds {
if d.IsDir() {
continue
}
files = append(files, filepath.Join(dir, d.Name()))
}
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
go func() {
<-ctx.Done()
stop()
}()
db, err := sqlitex.NewPool(mdbf, sqlitex.PoolOptions{Flags: sqlite.OpenReadOnly})
if err != nil {
slog.Error("mdb", slog.Any("err", err))
os.Exit(1)
}
slog.Info("load skills")
skills, err := mdb.Skills(ctx, db)
if err != nil {
slog.Error("skills", slog.Any("err", err))
os.Exit(1)
}
slog.Info("load sparks")
sparks, err := mdb.Sparks(ctx, db)
if err != nil {
slog.Error("sparks", slog.Any("err", err))
os.Exit(1)
}
slog.Info("load umas")
umas, err := mdb.Umas(ctx, db)
if err != nil {
slog.Error("umas", slog.Any("err", err))
os.Exit(1)
}
slog.Info("mdb",
slog.Int("sparks", len(sparks)),
slog.Int("skills", len(skills)),
slog.Int("umas", len(umas)),
)
tab := makeTables(skills, sparks, umas)
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(64)
for _, file := range files {
g.Go(func() error {
return dofile(ctx, file)
})
}
if err := g.Wait(); err != nil {
slog.Error("process", slog.Any("err", err))
os.Exit(1)
}
}
func dofile(ctx context.Context, file string) error {
f, err := os.Open(file)
if err != nil {
return err
}
var career ism.WorkIdleSingleMode
d := json.NewDecoder(f)
d.DisallowUnknownFields()
if err := d.Decode(&career); err != nil {
return fmt.Errorf("%s: %w", file, err)
}
}
+37
View File
@@ -0,0 +1,37 @@
package main
import "git.sunturtle.xyz/zephyr/horse"
type tables struct {
skills map[horse.SkillID]*horse.Skill
groups map[horse.SkillGroupID]map[int8]*horse.Skill
sparks map[horse.SparkID]*horse.Spark
umas map[horse.UmaID]*horse.Uma
}
func makeTables(skills []horse.Skill, sparks []horse.Spark, umas []horse.Uma) tables {
tab := tables{
skills: make(map[horse.SkillID]*horse.Skill, len(skills)),
groups: make(map[horse.SkillGroupID]map[int8]*horse.Skill, len(skills)/2),
sparks: make(map[horse.SparkID]*horse.Spark, len(sparks)),
umas: make(map[horse.UmaID]*horse.Uma, len(umas)),
}
for i, sk := range skills {
tab.skills[sk.ID] = &skills[i]
if tab.groups[sk.Group] == nil {
tab.groups[sk.Group] = make(map[int8]*horse.Skill, 4)
}
// Only add the skill to the groups table if they're rare, the base
// version of the common skill, or there isn't anything else there.
if sk.Rarity == 2 || sk.GroupRate == 1 || tab.groups[sk.Group][sk.Rarity] == nil {
tab.groups[sk.Group][sk.Rarity] = &skills[i]
}
}
for i, sp := range sparks {
tab.sparks[sp.ID] = &sparks[i]
}
for i, u := range umas {
tab.umas[u.ID] = &umas[i]
}
return tab
}
+1
View File
@@ -20,6 +20,7 @@
skill_id: 0, skill_id: 0,
name: 'Skill data is loading...', name: 'Skill data is loading...',
description: 'Skill data is still loading, or else something went wrong.', description: 'Skill data is still loading, or else something went wrong.',
group_skills: [],
group: 0, group: 0,
rarity: 1, rarity: 1,
group_rate: 1, group_rate: 1,
+14
View File
@@ -0,0 +1,14 @@
import * as z from 'zod';
const Entry = z.strictObject({
home_story_trigger_id: z.int32(),
new_flag: z.literal(0).or(z.literal(1)),
});
export type Entry = z.infer<typeof Entry>;
export const Gallery = z.object({
talk_gallery_list: z.array(Entry),
});
export type Gallery = z.infer<typeof Gallery>;
+57 -8
View File
@@ -9,25 +9,51 @@
requiredCharas, requiredCharas,
convoCharas, convoCharas,
} from '$lib/data/convo'; } from '$lib/data/convo';
import * as talk from '$lib/umadump/talk';
import CharaPick from '$lib/CharaPick.svelte'; import CharaPick from '$lib/CharaPick.svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import CharaIcon from '$lib/CharaIcon.svelte'; import CharaIcon from '$lib/CharaIcon.svelte';
import { SvelteSet } from 'svelte/reactivity';
let conversations: Conversation[] = $state([]); let allConvos: Conversation[] = $state([]);
const convoMap = $derived(byChara(conversations)); const popular = $derived(groupPopulars(allConvos));
const popular = $derived(groupPopulars(conversations));
let characters: Character[] = $state([]); let characters: Character[] = $state([]);
const selCharas = $derived(characters.filter((c) => convoMap.has(c.chara_id)));
const names = $derived(charaNames(characters)); const names = $derived(charaNames(characters));
const minSuggest = 8; const minSuggest = 8;
onMount(async () => { onMount(async () => {
[conversations, characters] = await Promise.all([conversation(), character()]); [allConvos, characters] = await Promise.all([conversation(), character()]);
}); });
let chara: Character | undefined = $state(); let chara: Character | undefined = $state();
let convo = $state(1); let convo = $state(1);
let talkFiles: FileList | undefined = $state();
let readIDs = new SvelteSet<number>();
let talkFileInvalid = $state(false);
async function setRead(f: FileList) {
talkFiles = f;
readIDs.clear();
talkFileInvalid = false;
if (talkFiles == null || talkFiles.length === 0) {
return;
}
const t = await talkFiles[0].text();
const d = JSON.parse(t);
const g = talk.Gallery.safeDecode(d);
if (!g.success) {
talkFileInvalid = true;
console.warn(g.error);
return;
}
for (const e of g.data.talk_gallery_list) {
readIDs.add(e.home_story_trigger_id);
}
}
const conversations = $derived(allConvos.filter((c) => !readIDs.has(c.id)));
const convoMap = $derived(byChara(conversations));
const selCharas = $derived(characters.filter((c) => convoMap.has(c.chara_id)));
const options = $derived(convoMap.get(chara?.chara_id ?? 0) ?? []); const options = $derived(convoMap.get(chara?.chara_id ?? 0) ?? []);
const cur = $derived(options.find((c) => c.number === convo)); const cur = $derived(options.find((c) => c.number === convo));
const charaIDs = $derived(cur != null ? convoCharas(cur) : []); const charaIDs = $derived(cur != null ? convoCharas(cur) : []);
@@ -47,12 +73,12 @@
</script> </script>
<h1 class="text-4xl">Lobby Conversations</h1> <h1 class="text-4xl">Lobby Conversations</h1>
<div class="mx-auto mt-8 flex flex-col rounded-md text-center shadow-md ring md:max-w-xl md:flex-row"> <div class="mx-auto mt-8 grid grid-cols-1 gap-4 rounded-md p-4 text-center shadow-md ring md:max-w-xl md:grid-cols-6">
<div class="m-4 flex-1 md:mt-3"> <div class="md:col-span-3">
<label for="chara" class="hidden md:inline">Character</label> <label for="chara" class="hidden md:inline">Character</label>
<CharaPick id="chara" characters={selCharas} class="w-full" bind:value={chara} required /> <CharaPick id="chara" characters={selCharas} class="w-full" bind:value={chara} required />
</div> </div>
<div class="m-4 flex-1 md:mt-3"> <div class="md:col-span-3">
<label for="convo" class="hidden md:inline">Conversation</label> <label for="convo" class="hidden md:inline">Conversation</label>
<select id="convo" bind:value={convo} class="w-full"> <select id="convo" bind:value={convo} class="w-full">
{#each options as opt (opt.number)} {#each options as opt (opt.number)}
@@ -60,6 +86,29 @@
{/each} {/each}
</select> </select>
</div> </div>
<div class="col-span-full">
<label for="talkgallery" class="block">
Select
<a href="https://werseter.github.io/umadump/" target="_blank" rel="noopener noreferrer">
<span class="inline-block font-mono">talk_gallery_data.json</span>
</a>
to hide read conversations.
</label>
<input
type="file"
class="rounded-full p-4"
accept="application/json"
id="talkgallery"
bind:files={() => talkFiles ?? new DataTransfer().files, setRead}
/>
<button
class="ml-4 rounded-full bg-mist-300 p-2 hover:cursor-pointer dark:bg-mist-900"
onclick={() => setRead(new DataTransfer().files)}>Reset</button
>
</div>
{#if talkFileInvalid}
<div class="col-span-full">Invalid File</div>
{/if}
</div> </div>
{#if cur} {#if cur}
<div class="shadow-sm transition-shadow hover:shadow-md"> <div class="shadow-sm transition-shadow hover:shadow-md">