<commit_before>package com.gdxjam.utils;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.PooledEngine;
import com.badlogic.gdx.ai.fsm.StackStateMachine;
import com.badlogic.gdx.ai.steer.Proximity;
import com.badlogic.gdx.ai.steer.proximities.RadiusProximity;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.utils.Array;
import com.gdxjam.Assets;
import com.gdxjam.ai.states.UnitState;
import com.gdxjam.components.CommanderComponent;
import com.gdxjam.components.CommanderHolderComponent;
import com.gdxjam.components.Components;
import com.gdxjam.components.HealthComponent;
import com.gdxjam.components.PhysicsComponent;
import com.gdxjam.components.ProximityComponent;
import com.gdxjam.components.SpriteComponent;
import com.gdxjam.components.StateMachineComponent;
import com.gdxjam.components.SteerableBodyComponent;
import com.gdxjam.components.SteeringBehaviorComponent;
import com.gdxjam.systems.PhysicsSystem;

public class EntityFactory {
	
	private static PooledEngine engine;
	
	private static final float wallWidth = 0.75f;
	private static final float gateSize = 1.5f;
	private static final float towerSize = 2.5f;
	
	public static void setEngine(PooledEngine engine){
		EntityFactory.engine = engine;
	}
	
	public static Entity createFortress(Vector2 position, float width, float height){
		Entity entity = engine.createEntity();
		
		BodyDef def = new BodyDef();
		def.type = BodyType.StaticBody;
		def.position.set(position);
		Body body = engine.getSystem(PhysicsSystem.class).createBody(def);
		
		//Towers
		createTower(new Vector2(position.x - (width * 0.5f), position.y + height * 0.5f));
		createTower(new Vector2(position.x + (width * 0.5f), position.y + height * 0.5f));
		createTower(new Vector2(position.x - (width * 0.5f), position.y - height * 0.5f));
		createTower(new Vector2(position.x + (width * 0.5f), position.y - height * 0.5f));
		
		//Walls
		float horizontalSegmentSize = (width*0.5f) - (gateSize * 0.5f) - (towerSize * 0.5f);
		float horizontalSegmentCenter = (-width * 0.5f) + (horizontalSegmentSize * 0.5f) + (towerSize*0.5f);
		float horizontalSegmentOffset = (height * 0.5f) + (wallWidth * 0.5f);
		
		float verticalSegmentSize = (height*0.5f) - (gateSize * 0.5f) - (towerSize * 0.5f);
		float verticalSegmentCenter = (-height * 0.5f) + (verticalSegmentSize * 0.5f) + (towerSize * 0.5f);
		float verticalSegmentOffset = (width* 0.5f) + (wallWidth * 0.5f);
		
		FixtureDef topLeftWall = createWallFixture(horizontalSegmentSize, new Vector2(horizontalSegmentCenter, horizontalSegmentOffset), 0);
		FixtureDef topRightWall = createWallFixture(horizontalSegmentSize, new Vector2(-horizontalSegmentCenter, horizontalSegmentOffset), 0);
		FixtureDef bottomLeftWall = createWallFixture(horizontalSegmentSize,new Vector2(horizontalSegmentCenter, -horizontalSegmentOffset), 0);
		FixtureDef bottomRightWall = createWallFixture(horizontalSegmentSize, new Vector2(-horizontalSegmentCenter, -horizontalSegmentOffset), 0);
		
		FixtureDef leftTopWall = createWallFixture(verticalSegmentSize, new Vector2(-verticalSegmentOffset, verticalSegmentCenter), MathUtils.PI * 0.5f);
		FixtureDef leftBottomWall = createWallFixture(verticalSegmentSize, new Vector2(-verticalSegmentOffset, -verticalSegmentCenter), MathUtils.PI * 0.5f);
		FixtureDef rightTopWall = createWallFixture(verticalSegmentSize, new Vector2(verticalSegmentOffset, verticalSegmentCenter), MathUtils.PI * 0.5f);
		FixtureDef rightBottomWall = createWallFixture(verticalSegmentSize, new Vector2(verticalSegmentOffset, -verticalSegmentCenter), MathUtils.PI * 0.5f);
		
		body.createFixture(topLeftWall);
		topLeftWall.shape.dispose();
		body.createFixture(topRightWall);
		topRightWall.shape.dispose();
		
		body.createFixture(bottomLeftWall);
		bottomLeftWall.shape.dispose();
		body.createFixture(bottomRightWall);
		bottomRightWall.shape.dispose();
		
		body.createFixture(leftTopWall);
		leftTopWall.shape.dispose();
		body.createFixture(leftBottomWall);
		leftBottomWall.shape.dispose();
		
		body.createFixture(rightTopWall);
		rightTopWall.shape.dispose();
		body.createFixture(rightBottomWall);
		rightBottomWall.shape.dispose();
		
		entity.add(engine.createComponent(PhysicsComponent.class).init(body));
		
		engine.addEntity(entity);
		return entity;
	}
	
	public static Entity createTower(Vector2 position){<commit_msg>Fortress walls are now their own entities<commit_after>package com.gdxjam.utils;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.PooledEngine;
import com.badlogic.gdx.ai.fsm.StackStateMachine;
import com.badlogic.gdx.ai.steer.Proximity;
import com.badlogic.gdx.ai.steer.proximities.RadiusProximity;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.utils.Array;
import com.gdxjam.Assets;
import com.gdxjam.ai.states.UnitState;
import com.gdxjam.components.CommanderComponent;
import com.gdxjam.components.CommanderHolderComponent;
import com.gdxjam.components.Components;
import com.gdxjam.components.HealthComponent;
import com.gdxjam.components.PhysicsComponent;
import com.gdxjam.components.ProximityComponent;
import com.gdxjam.components.SpriteComponent;
import com.gdxjam.components.StateMachineComponent;
import com.gdxjam.components.SteerableBodyComponent;
import com.gdxjam.components.SteeringBehaviorComponent;
import com.gdxjam.systems.PhysicsSystem;

public class EntityFactory {
	
	private static PooledEngine engine;
	
	private static final float wallWidth = 0.75f;
	private static final float gateSize = 1.5f;
	private static final float towerSize = 2.5f;
	
	public static void setEngine(PooledEngine engine){
		EntityFactory.engine = engine;
	}
	
	public static void createFortress(Vector2 position, float width, float height){

		//Towers
		createTower(new Vector2(position.x - (width * 0.5f), position.y + height * 0.5f));
		createTower(new Vector2(position.x + (width * 0.5f), position.y + height * 0.5f));
		createTower(new Vector2(position.x - (width * 0.5f), position.y - height * 0.5f));
		createTower(new Vector2(position.x + (width * 0.5f), position.y - height * 0.5f));
		
		//Walls
		float horizontalSegmentSize = (width*0.5f) - (gateSize * 0.5f) - (towerSize * 0.5f);
		float horizontalSegmentCenter = (-width * 0.5f) + (horizontalSegmentSize * 0.5f) + (towerSize*0.5f);
		float horizontalSegmentOffset = (height * 0.5f) + (wallWidth * 0.5f);
		
		float verticalSegmentSize = (height*0.5f) - (gateSize * 0.5f) - (towerSize * 0.5f);
		float verticalSegmentCenter = (-height * 0.5f) + (verticalSegmentSize * 0.5f) + (towerSize * 0.5f);
		float verticalSegmentOffset = (width* 0.5f) + (wallWidth * 0.5f);
		
		createWall(new Vector2(horizontalSegmentCenter, horizontalSegmentOffset).add(position), horizontalSegmentSize, 0);
		createWall(new Vector2(-horizontalSegmentCenter, horizontalSegmentOffset).add(position), horizontalSegmentSize, 0);
		createWall(new Vector2(horizontalSegmentCenter, -horizontalSegmentOffset).add(position), horizontalSegmentSize, 0);
		createWall(new Vector2(-horizontalSegmentCenter, -horizontalSegmentOffset).add(position), horizontalSegmentSize, 0);

		createWall(new Vector2(-verticalSegmentOffset, verticalSegmentCenter).add(position), verticalSegmentSize, MathUtils.PI * 0.5f);
		createWall(new Vector2(-verticalSegmentOffset, -verticalSegmentCenter).add(position), verticalSegmentSize, MathUtils.PI * 0.5f);
		createWall(new Vector2(verticalSegmentOffset, verticalSegmentCenter).add(position), verticalSegmentSize, MathUtils.PI * 0.5f);
		createWall(new Vector2(verticalSegmentOffset, -verticalSegmentCenter).add(position), verticalSegmentSize, MathUtils.PI * 0.5f);

	}
	
	public static Entity createWall(Vector2 center, float length, float rotation){
		Entity entity = engine.createEntity();
		
		BodyDef def = new BodyDef();
		def.type = BodyType.StaticBody;
		def.position.set(center);
		Body body = engine.getSystem(PhysicsSystem.class).createBody(def);
		
		FixtureDef fixdef = new FixtureDef();
		PolygonShape shape = new PolygonShape();
		shape.setAsBox(length * 0.5f, wallWidth * 0.5f, new Vector2(0, 0), rotation);
		fixdef.shape = shape;
		
		body.createFixture(fixdef);
		fixdef.shape.dispose();
		
		entity.add(engine.createComponent(PhysicsComponent.class).init(body));
		entity.add(engine.createComponent(HealthComponent.class));
		
		engine.addEntity(entity);
		return entity;
	}
	
	public static Entity createTower(Vector2 position){
{'fraction_non_alphanumeric': 0.115549686365137, 'fraction_numerical': 0.020248706943985915, 'mean_word_length': 5.716925351071692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4616700', 'n_tokens_mistral': 3187, 'n_tokens_neox': 2892, 'n_words': 534}