Skip to content

resources: add response compose helpers#1070

Open
Bing-su wants to merge 6 commits into
OverlayPlugin:mainfrom
Bing-su:compose
Open

resources: add response compose helpers#1070
Bing-su wants to merge 6 commits into
OverlayPlugin:mainfrom
Bing-su:compose

Conversation

@Bing-su

@Bing-su Bing-su commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

fixes #1058

Add compose and compose3 helper functions for combining LocaleText output strings into static built-in responses.

Based on my experience so far, I am confident that as long as it is used only for simple and clear content, there will be no translation issues.

2026-06-05

  • make combineLocaleText function public

2026-06-23

  • Change compose to a variadic function that takes severity as an argument later, and remove compose3.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds small composition helpers to the resources/responses.ts module to build static built-in responses by concatenating multiple LocaleText values with separators (with language fallback to en), plus unit tests validating composition behavior and severity handling.

Changes:

  • Add combineLocaleText helper to concatenate localized strings with per-language fallback.
  • Export new compose and compose3 helpers to generate static built-in responses from 2 or 3 LocaleText parts.
  • Add unit tests covering composed output strings, severity selection, and locale fallbacks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
resources/responses.ts Introduces combineLocaleText plus exported compose / compose3 static response helpers.
test/unittests/responses_test.ts Adds unit tests validating composed output strings and severity / locale fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/unittests/responses_test.ts Outdated
@github-actions github-actions Bot added needs-review Awaiting review and removed needs-review Awaiting review labels Jun 3, 2026
@valarnin

valarnin commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

re: compose3

It's possible to make a function in Typescript require pairs of arguments, such that:

const compose = (a: LocaleText, ...rest: SpecialType)...;

const lt = { en: 'Test' };
const sep1 = { en: '=>' };
const sep2 = { en: '+' };

// Returns `Test`
compose(lt);

// Returns `Test => Test`
compose(lt, sep1, lt);

// Results in compile error
compose(lt, sep1);

// Returns `Test => Test + Test`
compose(lt, sep1, lt, sep2, lt);

(setting up the Typescript types to get this functioning is a bit complicated, but it's possible).

I think the better question here is, "is there any case where more than 3 combines should be required, or would any case that potentially fits that criteria be better off broken up into separate triggers".

If it should always be broken up, then some function parameter type checking with optional parameters can allow for a single compose function that accepts 3 or 5 arguments while compile-time erroring with 1/2/4 arguments.

If we might want to allow additional combines, it would be better to use a generic function setup that allows 1 + any number of pairs of arguments as described above.

@Bing-su

Bing-su commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

There are quite a few cases where combining 3 LocaleTexts:

  • In => Out => Spread
  • Out => Stack => Spread
  • Right => Left + In
  • Out => In + Stacks

There are also a few cases that combine four pieces:

  • Out => In => Knockback => Spread
    • {
      id: 'R3S Octoboom Bombarian Special',
      type: 'StartsUsing',
      netRegex: { id: '9752', source: 'Brute Bomber', capture: false },
      infoText: (_data, _matches, output) => output.text!(),
      outputStrings: {
      text: {
      en: 'Out => In => Knockback => Spread',
      de: 'Raus => Rein => Rückstoß => Verteilen',
      fr: 'Extérieur => Intérieur => Poussée => Dispersion',
      ja: '外側 => 内側 => ノックバック => 散開',
      cn: '钢铁 => 月环 => 击退 => 分散',
      ko: '밖으로 => 안으로 => 넉백 => 산개',
      tc: '鋼鐵 => 月環 => 擊退 => 分散',
      },
      },
      },
  • Back => Front => Out => Stacks
    • outputStrings: {
      backThenFront: Outputs.backThenFront,
      backThenFrontThenHealerGroups: {
      en: 'Back => Front => Out => Stacks',
      de: 'Hinten => Vorne => Raus => Sammeln',
      fr: 'Derrière => Devant => Extérieur => Package',
      ja: '後ろ => 前 => 外側 => ペア',
      cn: '后 => 前 => 钢铁 => 分组分摊',
      ko: '뒤 => 앞 => 밖 => 쉐어',
      tc: '後 => 前 => 鋼鐵 => 分組分攤',
      },
      backThenFrontThenSpread: {
      en: 'Back => Front => Under => Spread',
      de: 'Hinten => Vorne => Unter ihn => Verteilen',
      fr: 'Derrière => Devant => Dessous => Écartez-vous',
      ja: '後ろ => 前 => 内側 => 散会',
      cn: '后 => 前 => 月环 => 分散',
      ko: '뒤 => 앞 => 안 => 산개',
      tc: '後 => 前 => 月環 => 分散',
      },

So I don’t think compose3 is useless.

After trying a few things, I found that the type definitions for a fully generic version were actually longer and more complex than the implementation itself. I opted for the current structure because it's easier to read and maintain, even if it's less flexible.

@Bing-su

Bing-su commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

The hardest part of implementing generics is the existence of Severity. If it didn't exist, I'd just have implemented it using generics...

@Bing-su Bing-su force-pushed the compose branch 2 times, most recently from 9113271 to 355cbdf Compare June 11, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Response.compose for combining registered outputs

3 participants