Created
January 12, 2023 06:31
-
-
Save tristanpendergrass/e95272bd6a4f220e9399c1b6f297f3a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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