<commit_before>package net.mostlyoriginal.game.manager;

import com.artemis.*;
import com.artemis.annotations.Wire;
import com.artemis.managers.TagManager;
import com.artemis.utils.EntityBuilder;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapProperties;
import net.mostlyoriginal.api.component.basic.Bounds;
import net.mostlyoriginal.api.component.basic.Pos;
import net.mostlyoriginal.api.component.graphics.Anim;
import net.mostlyoriginal.api.component.graphics.Renderable;
import net.mostlyoriginal.game.component.*;
import net.mostlyoriginal.game.component.buildings.ResourceNode;
import net.mostlyoriginal.game.component.buildings.Techpoint;
import net.mostlyoriginal.game.component.ui.*;
import net.mostlyoriginal.game.system.logic.ToolSystem;

import java.util.EnumSet;

/**
 * Game specific entity factory.
 *
 * @todo transform this into a manager.
 * @author <NAME>
 */
@Wire
public class EntityFactoryManager extends Manager {

    private Archetype resourceNode;
    private Archetype techpoint;
    private Archetype duct;

    private Archetype marine;
    private Archetype alien;

    protected ComponentMapper<Pos> mPos;
    protected ComponentMapper<Anim> mAnim;
    protected ComponentMapper<Bounds> mBounds;
    protected ComponentMapper<Blockade> mBlockade;
    protected ComponentMapper<Draggable> mDraggable;
    protected ComponentMapper<Renderable> mRenderable;
    protected ComponentMapper<TeamMember> mTeamMember;
    protected ComponentMapper<Persistable> mPersistable;
    protected ComponentMapper<RenderMask> mRenderMask;
    private ComponentMapper<Routable> mRoutable;
    private TagManager tagManager;


    @Override
    protected void initialize() {
        super.initialize();

        resourceNode = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Renderable.class,
                TeamAsset.class,
                Deletable.class,
                Draggable.class,
                Clickable.class,
                Persistable.class,
                RenderMask.class,
                ResourceNode.class,
                TeamMember.class,
                Routable.class
        ).build(world);
        techpoint = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Draggable.class,
                Renderable.class,
                TeamAsset.class,
                Deletable.class,
                Clickable.class,
                Persistable.class,
                RenderMask.class,
                Routable.class,
                TeamMember.class,
                Techpoint.class
        ).build(world);
        marine = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Traveler.class,
                TeamMember.class,
                Transient.class,
                RenderMask.class,
                Renderable.class
        ).build(world);
        alien = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Traveler.class,
                TeamMember.class,
                Transient.class,
                RenderMask.class,
                Renderable.class
        ).build(world);
        duct = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Renderable.class,
                Draggable.class,
                Blockade.class,
                Deletable.class,
                Clickable.class,
                Persistable.class,
                RenderMask.class,
                Bounds.class
        ).build(world);

        createInstancingButton("tool-resource-node", "resource-node", "resourceNode", 50);
        createInstancingButton("tool-techpoint", "techpoint", "techpoint", 50 + 40*1);
        createInstancingButton("duct", "duct", "duct", 50 + 40*2);
        createInstancingButton("wall", "wall", "wall", 50 + 40 * 3);

        addMaskTitle(RenderMask.Mask.BASIC, "Map overview", "Drag and place techpoints, rts, blockades and ducts.", "", "Rightclick to delete. Middleclick to cycle team on techpoints.");
        addMaskTitle(RenderMask.Mask.RT_PRESSURE, "RT head start", "highlight team that reaches RT first.", "Number signifies seconds head start.","Assign at least two techpoints to different teams.");
        addMaskTitle(RenderMask.Mask.RT_SYMMETRY_ALIEN, "Alien - RT run times", "Travel time in seconds between techpoints and RTs for aliens.", "", "");
        addMaskTitle(RenderMask.Mask.RT_SYMMETRY_MARINE, "Marine - RT run times", "Travel time in seconds between techpoints and RTs for marines.", "", "");
        addMaskTitle(RenderMask.Mask.PATHFIND_ALIEN, "Alien - all routes", "Travel time in seconds for aliens.", "", "");
        addMaskTitle(RenderMask.Mask.PATHFIND_MARINE, "Marine - all routes", "Travel time in seconds for marines.", "", "");
        addMaskTitle(RenderMask.Mask.TEAM_DOMAINS, "Presence", "Estimated presence of each team, strong to weak.", "Overlap indicates high encounter chance.", "");
    }

    ToolSystem toolSystem;
    AssetSystem assetSystem;

    private void createInstancingButton(final String toolIcon, final String animId, final String entityId, int x) {
        Entity button = createBasicButton(animId, x, new ButtonListener() {
            @Override
            public void run() {

                Tool tool = new Tool(new ButtonListener() {
                    @Override
                    public void run() {

                        final Entity cursor = tagManager.getEntity("cursor");

                        if ( cursor != null ) {
                            Entity entity = createEntity(entityId, 0, 0, null);

                            Pos cursorPos = mPos.get(cursor);

                            // don't allow placement under a certain cursor position.
                            if ( cursorPos.y <= 100 ) return;

                            Pos ePos = mPos.get(entity);
                            TextureRegion icon = assetSystem.get(mAnim.get(entity).id).getKeyFrame(0);
                            ePos.x = cursorPos.x - icon.getRegionWidth()/2;
                            ePos.y = cursorPos.y - icon.getRegionHeight()/2;
                        }
                    }

                    @Override
                    public boolean enabled() {
                        return true;
                    }
                });
                tool.continuous = false;
                toolSystem.reset();
                new EntityBuilder(world).with(tool, new Pos(), new Renderable(1200), new Anim(toolIcon)).build();
            }

            @Override
            public boolean enabled() {
                return true;
            }
        }, 50);

        // make only visible when rendering.
    }<commit_msg>Refresh map upon placement of entities.<commit_after>package net.mostlyoriginal.game.manager;

import com.artemis.*;
import com.artemis.annotations.Wire;
import com.artemis.managers.TagManager;
import com.artemis.utils.EntityBuilder;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapProperties;
import net.mostlyoriginal.api.component.basic.Bounds;
import net.mostlyoriginal.api.component.basic.Pos;
import net.mostlyoriginal.api.component.graphics.Anim;
import net.mostlyoriginal.api.component.graphics.Renderable;
import net.mostlyoriginal.api.event.common.EventManager;
import net.mostlyoriginal.game.component.*;
import net.mostlyoriginal.game.component.buildings.ResourceNode;
import net.mostlyoriginal.game.component.buildings.Techpoint;
import net.mostlyoriginal.game.component.ui.*;
import net.mostlyoriginal.game.events.DragEvent;
import net.mostlyoriginal.game.system.logic.ToolSystem;

import java.util.EnumSet;

/**
 * Game specific entity factory.
 *
 * @todo transform this into a manager.
 * @author <NAME>
 */
@Wire
public class EntityFactoryManager extends Manager {

    private Archetype resourceNode;
    private Archetype techpoint;
    private Archetype duct;

    private Archetype marine;
    private Archetype alien;

    protected ComponentMapper<Pos> mPos;
    protected ComponentMapper<Anim> mAnim;
    protected ComponentMapper<Bounds> mBounds;
    protected ComponentMapper<Blockade> mBlockade;
    protected ComponentMapper<Draggable> mDraggable;
    protected ComponentMapper<Renderable> mRenderable;
    protected ComponentMapper<TeamMember> mTeamMember;
    protected ComponentMapper<Persistable> mPersistable;
    protected ComponentMapper<RenderMask> mRenderMask;
    private ComponentMapper<Routable> mRoutable;
    private TagManager tagManager;


    @Override
    protected void initialize() {
        super.initialize();

        resourceNode = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Renderable.class,
                TeamAsset.class,
                Deletable.class,
                Draggable.class,
                Clickable.class,
                Persistable.class,
                RenderMask.class,
                ResourceNode.class,
                TeamMember.class,
                Routable.class
        ).build(world);
        techpoint = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Draggable.class,
                Renderable.class,
                TeamAsset.class,
                Deletable.class,
                Clickable.class,
                Persistable.class,
                RenderMask.class,
                Routable.class,
                TeamMember.class,
                Techpoint.class
        ).build(world);
        marine = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Traveler.class,
                TeamMember.class,
                Transient.class,
                RenderMask.class,
                Renderable.class
        ).build(world);
        alien = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Traveler.class,
                TeamMember.class,
                Transient.class,
                RenderMask.class,
                Renderable.class
        ).build(world);
        duct = new ArchetypeBuilder().add(
                Pos.class,
                Anim.class,
                Bounds.class,
                Renderable.class,
                Draggable.class,
                Blockade.class,
                Deletable.class,
                Clickable.class,
                Persistable.class,
                RenderMask.class,
                Bounds.class
        ).build(world);

        createInstancingButton("tool-resource-node", "resource-node", "resourceNode", 50);
        createInstancingButton("tool-techpoint", "techpoint", "techpoint", 50 + 40*1);
        createInstancingButton("duct", "duct", "duct", 50 + 40*2);
        createInstancingButton("wall", "wall", "wall", 50 + 40 * 3);

        addMaskTitle(RenderMask.Mask.BASIC, "Map overview", "Drag and place techpoints, rts, blockades and ducts.", "", "Rightclick to delete. Middleclick to cycle team on techpoints.");
        addMaskTitle(RenderMask.Mask.RT_PRESSURE, "RT head start", "highlight team that reaches RT first.", "Number signifies seconds head start.","Assign at least two techpoints to different teams.");
        addMaskTitle(RenderMask.Mask.RT_SYMMETRY_ALIEN, "Alien - RT run times", "Travel time in seconds between techpoints and RTs for aliens.", "", "");
        addMaskTitle(RenderMask.Mask.RT_SYMMETRY_MARINE, "Marine - RT run times", "Travel time in seconds between techpoints and RTs for marines.", "", "");
        addMaskTitle(RenderMask.Mask.PATHFIND_ALIEN, "Alien - all routes", "Travel time in seconds for aliens.", "", "");
        addMaskTitle(RenderMask.Mask.PATHFIND_MARINE, "Marine - all routes", "Travel time in seconds for marines.", "", "");
        addMaskTitle(RenderMask.Mask.TEAM_DOMAINS, "Presence", "Estimated presence of each team, strong to weak.", "Overlap indicates high encounter chance.", "");
    }

    ToolSystem toolSystem;
    AssetSystem assetSystem;
    EventManager em;

    private void createInstancingButton(final String toolIcon, final String animId, final String entityId, int x) {
        Entity button = createBasicButton(animId, x, new ButtonListener() {
            @Override
            public void run() {

                Tool tool = new Tool(new ButtonListener() {
                    @Override
                    public void run() {

                        final Entity cursor = tagManager.getEntity("cursor");

                        if ( cursor != null ) {
                            Entity entity = createEntity(entityId, 0, 0, null);

                            Pos cursorPos = mPos.get(cursor);

                            // don't allow placement under a certain cursor position.
                            if ( cursorPos.y <= 100 ) return;

                            Pos ePos = mPos.get(entity);
                            TextureRegion icon = assetSystem.get(mAnim.get(entity).id).getKeyFrame(0);
                            ePos.x = cursorPos.x - icon.getRegionWidth()/2;
                            ePos.y = cursorPos.y - icon.getRegionHeight()/2;

                            em.dispatch(new DragEvent(entity));
                        }
                    }

                    @Override
                    public boolean enabled() {
                        return true;
                    }
                });
                tool.continuous = false;
                toolSystem.reset();
                new EntityBuilder(world).with(tool, new Pos(), new Renderable(1200), new Anim(toolIcon)).build();
            }

            @Override
            public boolean enabled() {
                return true;
            }
        }, 50);

        // make only visible when rendering.
    }
{'fraction_non_alphanumeric': 0.09275954359768981, 'fraction_numerical': 0.004507677137625018, 'mean_word_length': 1.862701612903226, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, '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': '3750676', 'n_tokens_mistral': 3798, 'n_tokens_neox': 3491, 'n_words': 833}