119 lines
3.5 KiB
ReasonML
119 lines
3.5 KiB
ReasonML
/**
|
|
* A single active Activatable.
|
|
*/
|
|
type singleWithId = {
|
|
id: int,
|
|
index: int,
|
|
options: list(Id.Activatable.Option.t),
|
|
level: option(int),
|
|
customCost: option(int),
|
|
};
|
|
|
|
let singleToSingleWithId =
|
|
(x: Hero.Activatable.t, index, s: Hero.Activatable.single) => {
|
|
id: x.id,
|
|
index,
|
|
options: s.options,
|
|
level: s.level,
|
|
customCost: s.customCost,
|
|
};
|
|
|
|
let heroEntryToSingles = (x: Hero.Activatable.t) =>
|
|
x.active |> Ley_List.Index.imap(singleToSingleWithId(x));
|
|
|
|
let singleWithIdToSingle = s => {
|
|
Hero.Activatable.options: s.options,
|
|
level: s.level,
|
|
customCost: s.customCost,
|
|
};
|
|
/* /**
|
|
* Converts the object generated by the list item to an object that can be
|
|
* inserted into an array of ActiveObjects.
|
|
* @param obj The entry for which you want to convert the object.
|
|
* @param activate The object generated by the list item.
|
|
*/
|
|
export const convertUIStateToActiveObject =
|
|
(activate: Record<ActivatableActivationOptions>): Record<ActiveObject> => {
|
|
const id = AAOA.id (activate)
|
|
const selectOptionId1 = AAOA.selectOptionId1 (activate)
|
|
const selectOptionId2 = AAOA.selectOptionId2 (activate)
|
|
const selectOptionId3 = AAOA.selectOptionId3 (activate)
|
|
const input = AAOA.input (activate)
|
|
const level = AAOA.level (activate)
|
|
const customCost = AAOA.customCost (activate)
|
|
|
|
return id === AdvantageId.HatredOf
|
|
? ActiveObject ({
|
|
sid: selectOptionId1,
|
|
sid2: input,
|
|
cost: customCost,
|
|
})
|
|
: id === DisadvantageId.PersonalityFlaw
|
|
? ActiveObject ({
|
|
sid: selectOptionId1,
|
|
sid2: or (fmap (elemF (List<number | string> (7, 8)))
|
|
(selectOptionId1))
|
|
? input
|
|
: None,
|
|
cost: customCost,
|
|
})
|
|
: id === SpecialAbilityId.SkillSpecialization
|
|
? ActiveObject ({
|
|
sid: selectOptionId1,
|
|
sid2: alt<number | string> (input)
|
|
(selectOptionId2),
|
|
cost: customCost,
|
|
})
|
|
: isSome (input) && isSome (selectOptionId1)
|
|
? ActiveObject ({
|
|
sid: selectOptionId1,
|
|
sid2: input,
|
|
sid3: selectOptionId2,
|
|
tier: level,
|
|
cost: customCost,
|
|
})
|
|
: ActiveObject ({
|
|
sid: alt<number | string> (input)
|
|
(selectOptionId1),
|
|
sid2: then (guard (isSome (input) || isSome (selectOptionId1)))
|
|
(selectOptionId2),
|
|
sid3: selectOptionId3,
|
|
tier: level,
|
|
cost: customCost,
|
|
})
|
|
} */
|
|
/* /**
|
|
* Generates a list of ActiveObjects based on the given instance.
|
|
*/
|
|
export const convertActivatableToArray =
|
|
(x: Record<ActivatableDependent>) =>
|
|
pipe_ (
|
|
x,
|
|
ADA.active,
|
|
imap (index => toActiveObjectWithId (index) (ADA.id (x)))
|
|
) */
|
|
/* /**
|
|
* Get all active items in an array.
|
|
* @param state A state slice.
|
|
*/
|
|
export const getActiveFromState =
|
|
foldr (pipe (convertActivatableToArray, append)) (empty)
|
|
|
|
export interface ActiveObjectAny extends ActiveObject {
|
|
[key: string]: any
|
|
} */
|
|
|
|
let activatableOptionToSelectOptionId =
|
|
(id: Id.Activatable.Option.t): option(Id.SelectOption.t) =>
|
|
switch (id) {
|
|
| `Generic(_) as id
|
|
| `Skill(_) as id
|
|
| `CombatTechnique(_) as id
|
|
| `Spell(_) as id
|
|
| `Cantrip(_) as id
|
|
| `LiturgicalChant(_) as id
|
|
| `Blessing(_) as id
|
|
| `SpecialAbility(_) as id => Some(id)
|
|
| `CustomInput(_) => None
|
|
};
|