<commit_before>import com.cardshifter.api.config.DeckConfig
import com.cardshifter.modapi.base.ECSGame;
import com.cardshifter.modapi.base.Entity
import com.cardshifter.modapi.base.PlayerComponent
import com.cardshifter.modapi.cards.DeckComponent
import com.cardshifter.modapi.players.Players
import com.cardshifter.modapi.resources.ECSResource
import com.cardshifter.modapi.resources.ECSResourceDefault
import net.zomis.cardshifter.ecs.config.ConfigComponent
import SystemsDelegate;
import PlayerDelegate;
import NeutralDelegate;
import systems.GeneralSystems;

public class GroovyMod {

    protected ECSGame game

    ECSResource createResource(String name) {
        return new ECSResourceDefault(name)
    }

    void resources(List<ECSResource> resources) {
        println "Adding ${resources.size()} resources"
        def map = [:]
        for (ECSResource res in resources) {
            map.put(res.toString().toUpperCase(), res)
        }
        game.metaClass.resource << {String name -> map[name.toUpperCase()]}
    }

    private def enableMeta() {
        GeneralSystems.setup()
        GeneralSystems.cardSystems()
        ECSGame.class.metaClass.neutral << {Closure closure ->
            def cl = closure.rehydrate(new NeutralDelegate(entity: game.newEntity()), this, this)
            cl.call()
        }
        ECSGame.class.metaClass.players << {int count, Closure closure ->
            for (int i = 0; i < count; i++) {
                println 'Creating player ' + i
                Entity player = game.newEntity()
                def cl = closure.rehydrate(new PlayerDelegate(player), this, this)
                player.addComponent(new PlayerComponent(i, "Player $i"))
                cl.setResolveStrategy(Closure.DELEGATE_FIRST)
                cl.call()
            }
        }
    }

    private Closure<?> configClosure
    private Closure<?> setupClosure

    void declareConfiguration(ECSGame game) {
        this.game = game
        enableMeta()
        def cl = configClosure.rehydrate(game, this, this)
        cl.setResolveStrategy(Closure.DELEGATE_FIRST)
        cl.call()
    }

    void setupGame(ECSGame game) {
        this.game = game
        println 'Creating setup delegate'
        def cl = setupClosure.rehydrate(new SetupDelegate(this, game), this, this)
        cl.setResolveStrategy(Closure.DELEGATE_ONLY)
        cl.call()
    }

    void setup(Closure<?> closure) {
        this.setupClosure = closure
    }

    void config(Closure<?> closure) {
        this.configClosure = closure
    }

}

class SetupDelegate {
    def mod
    ECSGame game

    SetupDelegate(GroovyMod mod, ECSGame game) {
        println 'Creating setup delegate 2'
        this.mod = mod
        this.game = game
    }

    def playerDeckFromConfig(String name) {
        println "Player deck from config $name"
        def players = Players.getPlayersInGame(game)
        for (Entity player in players) {
            DeckComponent deck = player.getComponent(DeckComponent)
            ConfigComponent playerConfig = player.getComponent(ConfigComponent)
            DeckConfig config = playerConfig.getConfigs().get(name)
            setupDeck(deck, config)
        }
    }

    def setupDeck(DeckComponent deck, DeckConfig deckConf) {
        def game = deck.owner.game;
        for (def chosen in deckConf.chosen.entrySet()) {
            def entityId = chosen.key;
            def count = chosen.value;

            for (int i = 0; i < count; i++) {
                def existing = game.getEntity(entityId);
                def copy = existing.copy();
                deck.addOnBottom(copy);
            }
        }
    }

    def playerDeckShuffle() {
        def players = Players.getPlayersInGame(game)
        for (Entity player in players) {
            DeckComponent deck = player.getComponent(DeckComponent)
            deck.shuffle()
        }
    }

    def methodMissing(String name, args) {
        println 'Setup Unsupported method: ' + name
    }

    void systems(Closure<?> closure) {
        def cl = closure.rehydrate(new SystemsDelegate(game: game), this, this);
        cl.call()
    }
}
<commit_msg>created a real ConfigDelegate<commit_after>import com.cardshifter.api.config.DeckConfig
import com.cardshifter.modapi.base.ECSGame;
import com.cardshifter.modapi.base.Entity
import com.cardshifter.modapi.base.PlayerComponent
import com.cardshifter.modapi.cards.DeckComponent
import com.cardshifter.modapi.players.Players
import com.cardshifter.modapi.resources.ECSResource
import com.cardshifter.modapi.resources.ECSResourceDefault
import net.zomis.cardshifter.ecs.config.ConfigComponent
import SystemsDelegate;
import PlayerDelegate;
import NeutralDelegate;
import systems.GeneralSystems;

public class GroovyMod {

    protected ECSGame game

    ECSResource createResource(String name) {
        return new ECSResourceDefault(name)
    }

    void resources(List<ECSResource> resources) {
        println "Adding ${resources.size()} resources"
        def map = [:]
        for (ECSResource res in resources) {
            map.put(res.toString().toUpperCase(), res)
        }
        game.metaClass.resource << {String name -> map[name.toUpperCase()]}
    }

    private def enableMeta() {
        GeneralSystems.setup()
        GeneralSystems.cardSystems()
    }

    private Closure<?> configClosure
    private Closure<?> setupClosure

    void declareConfiguration(ECSGame game) {
        this.game = game
        enableMeta()
        def cl = configClosure.rehydrate(new ConfigDelegate(game: game), this, this)
        cl.setResolveStrategy(Closure.DELEGATE_FIRST)
        cl.call()
    }

    void setupGame(ECSGame game) {
        this.game = game
        println 'Creating setup delegate'
        def cl = setupClosure.rehydrate(new SetupDelegate(this, game), this, this)
        cl.setResolveStrategy(Closure.DELEGATE_ONLY)
        cl.call()
    }

    void setup(Closure<?> closure) {
        this.setupClosure = closure
    }

    void config(Closure<?> closure) {
        this.configClosure = closure
    }
}

class ConfigDelegate {
    ECSGame game

    def neutral(Closure closure) {
        def cl = closure.rehydrate(new NeutralDelegate(entity: game.newEntity()), this, this)
        cl.call()
    }

    def players(int count, Closure closure) {
        for (int i = 0; i < count; i++) {
            println 'Creating player ' + i
            Entity player = game.newEntity()
            def cl = closure.rehydrate(new PlayerDelegate(player), this, this)
            player.addComponent(new PlayerComponent(i, "Player $i"))
            cl.setResolveStrategy(Closure.DELEGATE_FIRST)
            cl.call()
        }
    }
}

class SetupDelegate {
    def mod
    ECSGame game

    SetupDelegate(GroovyMod mod, ECSGame game) {
        println 'Creating setup delegate 2'
        this.mod = mod
        this.game = game
    }

    def playerDeckFromConfig(String name) {
        println "Player deck from config $name"
        def players = Players.getPlayersInGame(game)
        for (Entity player in players) {
            DeckComponent deck = player.getComponent(DeckComponent)
            ConfigComponent playerConfig = player.getComponent(ConfigComponent)
            DeckConfig config = playerConfig.getConfigs().get(name)
            setupDeck(deck, config)
        }
    }

    def setupDeck(DeckComponent deck, DeckConfig deckConf) {
        def game = deck.owner.game;
        for (def chosen in deckConf.chosen.entrySet()) {
            def entityId = chosen.key;
            def count = chosen.value;

            for (int i = 0; i < count; i++) {
                def existing = game.getEntity(entityId);
                def copy = existing.copy();
                deck.addOnBottom(copy);
            }
        }
    }

    def playerDeckShuffle() {
        def players = Players.getPlayersInGame(game)
        for (Entity player in players) {
            DeckComponent deck = player.getComponent(DeckComponent)
            deck.shuffle()
        }
    }

    def methodMissing(String name, args) {
        println 'Setup Unsupported method: ' + name
    }

    void systems(Closure<?> closure) {
        def cl = closure.rehydrate(new SystemsDelegate(game: game), this, this);
        cl.call()
    }
}

{'fraction_non_alphanumeric': 0.09454238106737503, 'fraction_numerical': 0.0007244626901714562, 'mean_word_length': 2.422727272727273, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3832378', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2344, 'n_words': 541}