From 23aefaa9f1328718550c3b30b3415e7d101cdee4 Mon Sep 17 00:00:00 2001 From: Simon Forsberg Date: Sun, 4 Dec 2022 23:04:48 +0100 Subject: [PATCH] Remove old-style event triggers #320 --- .../zomis/games/dsl/GameActionRulesScope.kt | 19 ------- .../net/zomis/games/dsl/impl/RulesImpl.kt | 52 ------------------- 2 files changed, 71 deletions(-) diff --git a/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/GameActionRulesScope.kt b/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/GameActionRulesScope.kt index f11e2d91..b421095d 100644 --- a/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/GameActionRulesScope.kt +++ b/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/GameActionRulesScope.kt @@ -6,7 +6,6 @@ import net.zomis.games.api.MetaScope import net.zomis.games.api.UsageScope import net.zomis.games.common.PlayerIndex import net.zomis.games.dsl.events.EventFactory -import net.zomis.games.dsl.events.EventSource import net.zomis.games.dsl.flow.GameMetaScope import net.zomis.games.dsl.impl.ActionOptionsContext import net.zomis.games.dsl.impl.GameMarker @@ -121,21 +120,3 @@ interface ActionChoicesScope : UsageScope { fun options(options: ActionOptionsScope.() -> Iterable, next: ActionChoicesScope.(E) -> Unit) fun optionsWithIds(options: ActionOptionsScope.() -> Iterable>, next: ActionChoicesScope.(E) -> Unit) } - -@GameMarker -@Deprecated("Use Events instead") -interface GameRuleTriggerScope : UsageScope { - val game: T - val trigger: E - val replayable: ReplayStateI - val eliminations: PlayerEliminationsWrite -} - -@Deprecated("old-style event system. Use Event class instead") -interface GameRuleTrigger { - fun effect(effect: GameRuleTriggerScope.() -> Unit): GameRuleTrigger - fun map(mapping: GameRuleTriggerScope.() -> E): GameRuleTrigger - fun after(effect: GameRuleTriggerScope.() -> Unit): GameRuleTrigger - fun ignoreEffectIf(condition: GameRuleTriggerScope.() -> Boolean): GameRuleTrigger - operator fun invoke(trigger: E): E? -} diff --git a/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/impl/RulesImpl.kt b/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/impl/RulesImpl.kt index ba4aa9c2..4ed8d847 100644 --- a/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/impl/RulesImpl.kt +++ b/games-dsl/common/src/main/kotlin/net/zomis/games/dsl/impl/RulesImpl.kt @@ -1,6 +1,5 @@ package net.zomis.games.dsl.impl -import net.zomis.games.PlayerEliminationsWrite import net.zomis.games.common.PlayerIndex import net.zomis.games.dsl.* import net.zomis.games.dsl.events.EventFactory @@ -273,54 +272,3 @@ class GameActionRuleContext( override fun isComplex(): Boolean = this.choices != null } - -@Deprecated("old-style event system. Use Event class instead") -data class GameRuleTriggerContext( - override val game: T, - override val trigger: E, - override val replayable: ReplayStateI, - override val eliminations: PlayerEliminationsWrite -): GameRuleTriggerScope - -@Deprecated("old-style event system. Use Event class instead") -class GameRuleTriggerImpl( - val gameContext: GameMetaScope, -) : GameRuleTrigger { - private val effects = mutableListOf.() -> Unit>() - private val mappings = mutableListOf.() -> E>() - private val ignoreConditions = mutableListOf.() -> Boolean>() - private val after = mutableListOf.() -> Unit>() - - override fun effect(effect: GameRuleTriggerScope.() -> Unit): GameRuleTrigger { - this.effects.add(effect) - return this - } - - override fun map(mapping: GameRuleTriggerScope.() -> E): GameRuleTrigger { - this.mappings.add(mapping) - return this - } - - override fun after(effect: GameRuleTriggerScope.() -> Unit): GameRuleTrigger { - this.after.add(effect) - return this - } - - override fun ignoreEffectIf(condition: GameRuleTriggerScope.() -> Boolean): GameRuleTrigger { - this.ignoreConditions.add(condition) - return this - } - - override fun invoke(trigger: E): E? { - val result = mappings.fold(GameRuleTriggerContext(gameContext.game, trigger, gameContext.replayable, gameContext.eliminations)) { - acc, next -> acc.copy(trigger = next.invoke(acc)) - } - val process = ignoreConditions.none { it.invoke(result) } - if (process) { - effects.forEach { it.invoke(result) } - } - after.forEach { it.invoke(result) } - return if (process) result.trigger else null - } - -} \ No newline at end of file