Skip to content

Commit

Permalink
Start to replace swashbuckler stub with start of actual flags-based i…
Browse files Browse the repository at this point in the history
…mplementation. Needs tests for issue #56. ChargenView is still using the menu stubs instead of the flags-based implementation but can be swapped out with one line of code.
  • Loading branch information
MaxWilson committed Feb 12, 2024
1 parent cb01915 commit cd50347
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/Core/Menus.fs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ type Op =
match children with
| Fulfilled(value, childMenus) ->
// when we're at quota, exclude all the unpicked options from the menu unless and until some current selections are unpicked
// let values = lst |> List.collect fst
// let childMenus = lst |> List.map snd
value, Either(config.label, childMenus)
| Partial(value, allChildMenus) ->
// let allChildMenus = children |> List.map snd
value, Either(config.label, allChildMenus)
| Fallback(fallbackValue, allChildMenus) ->
// let allChildMenus = children |> List.map snd
fallbackValue, Either(config.label, allChildMenus)
)
static let andF config (offers: _ ListOffer list) =
Expand Down
40 changes: 32 additions & 8 deletions src/Domain/DFRPG/Chargen.Templates.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,46 @@ module Flags =
open Flags
let allFlags = { flags = [] }
let flag name = Flag(name, allFlags)

let combatReflexes = flag "Combat Reflexes"
let highPainThreshold = flag "High Pain Threshold"
type FlagOutput = Literal of FlagKey | Bonus of FlagKey * int
let toString (f:FlagOutput) =
match f with
| Literal s -> s
| Bonus(s, n) -> $"%+d{n} {s}"
let ST = flag "ST"
let DX = flag "DX"
let IQ = flag "IQ"
let HT = flag "HT"
let luck = flag "Luck"
let Ambi = flag "Ambidexterity"
let CombatReflexes = flag "Combat Reflexes"
let ETS = flag "Enhanced Time Sense"
let HPT = flag "High Pain Threshold"
let Luck = flag "Luck"
open Flags

type FlagOutput = Literal of FlagKey | Bonus of FlagKey * int

type Op with
static member adv (flag:Flag) = Op.trait' (Literal flag.Key)
static member bonus (flag:Flag) n = Op.trait' (Bonus(flag.Key, n))
static member adv (flag:Flag) =
Op.trait' ({ blank() with toString = Some Flags.toString }, Literal flag.Key)
static member bonus (flag:Flag) n =
Op.trait' ({ blank() with toString = Some Flags.toString }, Bonus(flag.Key, n))
static member bonusRange (flag:Flag) (ns: int list) =
let spec : LevelSpec<int, FlagOutput> = { toString = toString; ctor = fun n -> Bonus(flag.Key, n) }
Op.level(flag.Key, spec, ns)
static member chooseN n (options: _ OptionOffer list) =
Op.eitherN(blank(), n, options)
open type Op
let swashbuckler: FlagOutput ListOffer list = [
Op.and' [ bonus ST 1; bonus DX 5; bonus HT 3; adv combatReflexes; adv luck ]
Op.and' [
bonus ST 1
bonus DX 5
bonus HT 3
adv CombatReflexes
adv Luck
]
Op.chooseN 4 [
bonusRange ST [1..6]
bonusRange DX [1..3]
adv Ambi
adv ETS
]
]
8 changes: 8 additions & 0 deletions src/UI/DFRPG/Chargen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ let swash = [
advantage CombatReflexes
skill("Acrobatics", [1..3])
])
eitherN(Menus.blank(), 3, [
skill("Rapier", 3) |> promote
skill("Sling", 3) |> promote
skill("Bow", 3) |> promote
skill("Two-handed Sword", 3) |> promote
skill("Stealth", 3) |> promote
skill("Climbing", 3) |> promote
])
let mainWeapons = ["Rapier"; "Broadsword"; "Polearm"; "Two-handed sword"]
let weaponsAt (bonus: int) = mainWeapons |> List.map (fun name -> skill(name, bonus))
eitherN [
Expand Down
4 changes: 2 additions & 2 deletions src/UI/DFRPG/ChargenView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module private Impl =
]
]
}
let eval dispatch selections (template: Trait ListOffer list) =
let eval dispatch selections (template: _ ListOffer list) =
let value, menus =
[
for offer in template do
Expand All @@ -56,7 +56,7 @@ open Impl
[<ReactComponent>]
let View() =
let model, dispatch = React.useElmishSimple init update
let profession = swash
let profession = swash // Domain.DFRPG.Templates.swashbuckler
let value, react = eval dispatch model.selections profession // value will be used later for things like enabling/disabling the Save button
Html.div [
srcLink
Expand Down

0 comments on commit cd50347

Please sign in to comment.