Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / flattenTargetGroups

Function: flattenTargetGroups() ​

flattenTargetGroups(groups): AbilityTarget[]

Defined in: packages/ts-sdk/src/actionable.ts:55

Concatenates every group's candidate targets, in group order.

This is what the retired flat validTargets field on the action views carried, so "how many targets could this action pick from?" stays a one-liner. Duplicates are kept: one entity legal in two groups appears twice, matching the retired field.

Example:

ts
import {
  createSimulatorClient,
  flattenTargetGroups,
  targetGroupsOf,
} from '@my-swu/simulator-client'

// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})

const matchSnapshot = await simulatorClient.matches.get('match_123')

// Every candidate target across the plan, in group order. One entity legal
// in two groups appears twice.
const [playAction] = matchSnapshot.playActions

console.log(flattenTargetGroups(targetGroupsOf(playAction)).length)

Parameters ​

groups ​

Example:

ts
import {
  createSimulatorClient,
  flattenTargetGroups,
  targetGroupsOf,
} from '@my-swu/simulator-client'

// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})

const matchSnapshot = await simulatorClient.matches.get('match_123')

// Every candidate target across the plan, in group order. One entity legal
// in two groups appears twice.
const [playAction] = matchSnapshot.playActions

console.log(flattenTargetGroups(targetGroupsOf(playAction)).length)

readonly TargetSelectionGroup[] | null | undefined

Groups from targetGroupsOf, or a nullish value.

Returns ​

AbilityTarget[]

Every candidate target across the groups.

Released under the MIT License.