Archived
fixes #1; Migrate card activation effect to factory in card_behaviour.py
This commit is contained in:
+16
-12
@@ -1,10 +1,12 @@
|
||||
from json import JSONDecodeError
|
||||
from typing import List, Dict, Optional
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
|
||||
from model.card_validator import CardParser, EffectParser
|
||||
from model.card import Effect, Card
|
||||
from .card_behaviour import create_effect_behaviour
|
||||
|
||||
|
||||
class CardContainerFile(BaseModel):
|
||||
@@ -57,7 +59,7 @@ def create_card_effects(
|
||||
mutexes[mutex] = []
|
||||
|
||||
for effect in card.effects:
|
||||
real_effect, sub_effects = create_effect(effect)
|
||||
real_effect, sub_effects = create_effect_and_subeffects(effect)
|
||||
for e in sub_effects:
|
||||
all_effects.append(e)
|
||||
all_effects.append(real_effect)
|
||||
@@ -72,7 +74,7 @@ def create_card_effects(
|
||||
return combined, all_effects
|
||||
|
||||
|
||||
def create_effect(
|
||||
def create_effect_and_subeffects(
|
||||
effect: EffectParser, all_effects: Optional[List[Effect]] = None
|
||||
) -> (Effect, List[Effect]):
|
||||
if all_effects is None:
|
||||
@@ -83,7 +85,7 @@ def create_effect(
|
||||
mutexes[mutex] = []
|
||||
|
||||
for s in effect.sub_effects:
|
||||
real_effect, all_effects2 = create_effect(s, all_effects)
|
||||
real_effect, all_effects2 = create_effect_and_subeffects(s, all_effects)
|
||||
for e in all_effects2:
|
||||
all_effects.append(e)
|
||||
all_effects.append(real_effect)
|
||||
@@ -95,13 +97,15 @@ def create_effect(
|
||||
if s.mutex in mutexes:
|
||||
sub_effects[index].mutex = mutexes[s.mutex]
|
||||
|
||||
return (
|
||||
Effect(
|
||||
effect=effect.effect,
|
||||
amount=effect.amount,
|
||||
effect_type=effect.effect_type,
|
||||
sub_effects=sub_effects,
|
||||
times=effect.times,
|
||||
actual_effect = Effect(
|
||||
effect=effect.effect,
|
||||
amount=effect.amount,
|
||||
effect_type=effect.effect_type,
|
||||
sub_effects=sub_effects,
|
||||
times=effect.times,
|
||||
activate=lambda *args, **kwargs: create_effect_behaviour(effect=effect)(
|
||||
actual_effect, *args, **kwargs
|
||||
),
|
||||
all_effects,
|
||||
)
|
||||
|
||||
return actual_effect, all_effects
|
||||
|
||||
Reference in New Issue
Block a user