Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tristanpendergrass/e95272bd6a4f220e9399c1b6f297f3a4 to your computer and use it in GitHub Desktop.
Save tristanpendergrass/e95272bd6a4f220e9399c1b6f297f3a4 to your computer and use it in GitHub Desktop.
-- Simple example: WORKS
followSplit : Mod -> Mod
followSplit oldMod =
let
newTransformer : Node -> Node
newTransformer node =
case node of
Split nodes ->
let
newNodes : List Node
newNodes =
List.map newTransformer nodes
in
Split newNodes
_ ->
oldMod.transformer node
in
{ oldMod | transformer = newTransformer }
-- Real example: DOESN'T WORK
includeVariableEffects : Mod -> Mod
includeVariableEffects mod =
let
transformer =
mod.transformer
newTransformer : Int -> Effect -> Effect
newTransformer =
\multiplier effect ->
case getType effect of
VariableSuccess { successProbability, successEffects, failureEffects } ->
let
( successEffectsDidChange, newSuccessEffects ) =
let
newEffects : List Effect
newEffects =
List.concatMap (applyModsToEffect 0 [ { mod | transformer = newTransformer multiplier } ]) successEffects
in
( successEffects /= newEffects, newEffects )
( failureEffectsDidChange, newFailureEffects ) =
let
newEffects : List Effect
newEffects =
List.concatMap (applyModsToEffect 0 [ mod ]) failureEffects
in
( failureEffects /= newEffects, newEffects )
effectDidChange =
successEffectsDidChange || failureEffectsDidChange
in
if effectDidChange then
effect
|> setType
(VariableSuccess
{ successProbability = successProbability
, successEffects = newSuccessEffects
, failureEffects = newFailureEffects
}
)
|> ChangeEffect
else
NoChange
_ ->
transformer multiplier effect
in
{ mod | transformer = newTransformer }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment