Skip to content

Commit

Permalink
Fix code smells in BaseTowerConfigs: set private fields + add getters
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Oct 16, 2023
1 parent bf99946 commit ce87c1b
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.csse3200.game.entities.configs;

/**
* Defines all tower configs to be loaded by the Tower Factory.
*/
public class BaseTowerConfigs {
private WeaponTowerConfig weapon = new WeaponTowerConfig();
private WallTowerConfig wall = new WallTowerConfig();
private IncomeTowerConfig income = new IncomeTowerConfig();
private FireTowerConfig fireTower = new FireTowerConfig();
private StunTowerConfig stunTower = new StunTowerConfig();
private TNTTowerConfigs TNTTower = new TNTTowerConfigs();
private DroidTowerConfig DroidTower = new DroidTowerConfig();
private FireworksTowerConfig fireworksTower = new FireworksTowerConfig();
private PierceTowerConfig pierceTower = new PierceTowerConfig();
private RicochetTowerConfig ricochetTower = new RicochetTowerConfig();
private HealTowerConfig healTower = new HealTowerConfig();

/**
* Function for getting the wall tower's config
* @return The config of wall tower
*/
public WallTowerConfig getWall() {
return wall;
}

/**
* Function for getting the weapon tower's config
* @return The config of weapon tower
*/
public WeaponTowerConfig getWeapon() {
return weapon;
}

/**
* Function for getting the income tower's config
* @return The config of income tower
*/
public IncomeTowerConfig getIncome() {
return income;
}

/**
* Function for getting the fire tower's config
* @return The config of fire tower
*/
public FireTowerConfig getFireTower() {
return fireTower;
}

/**
* Function for getting the stun tower's config
* @return The config of stun tower
*/
public StunTowerConfig getStunTower() {
return stunTower;
}

/**
* Function for getting the TNT tower's config
* @return The config of TNT tower */
public TNTTowerConfigs getTNTTower() {
return TNTTower;
}

/**
* Function for getting the droid tower's config
* @return The config of droid tower
*/
public DroidTowerConfig getDroidTower() {
return DroidTower;
}

/**
* Function for getting the fireworks tower's config
* @return The config of fireworks tower
*/
public FireworksTowerConfig getFireworksTower() {
return fireworksTower;
}

/**
* Function for getting the pierce tower's config
* @return The config of pierce tower
*/
public PierceTowerConfig getPierceTower() {
return pierceTower;
}

/**
* Function for getting the ricochet tower's config
* @return The config of ricochet tower
*/
public RicochetTowerConfig getRicochetTower() {
return ricochetTower;
}

/**
* Function for getting the heal tower's config
* @return The config of heal tower
*/
public HealTowerConfig getHealTower() {
return healTower;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class FireworksTowerConfig {
private int baseAttack = 0;
private int cost = 1;
private int attackRate = 0;
public int incomeRate = 0;
private int incomeRate = 0;

/**
* Function for getting tower's health
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Factory to create a tower entity.
*
* Predefined tower properties are loaded from a config stored as a json file and should have
* the properties stores in 'baseTowerConfigs'.
* the properties stores in 'BaseTowerConfigs'.
*/
public class TowerFactory {
private static final Logger logger = LoggerFactory.getLogger(TowerFactory.class);
Expand Down Expand Up @@ -113,16 +113,16 @@ public class TowerFactory {
private static final String ECO_IDLE = "idle";
private static final float ECO_IDLE_SPEED = 0.3f;

private static final baseTowerConfigs configs =
FileLoader.readClass(baseTowerConfigs.class, "configs/tower.json");
private static final BaseTowerConfigs configs =
FileLoader.readClass(BaseTowerConfigs.class, "configs/tower.json");

/**
* Creates an income tower that generates scrap
* @return income
*/
public static Entity createIncomeTower() {
Entity income = createBaseTower();
IncomeTowerConfig config = configs.income;
IncomeTowerConfig config = configs.getIncome();

// Create the CurrencyIncomeTask and add it to the AITaskComponent
CurrencyTask currencyTask = new CurrencyTask(INCOME_TASK_PRIORITY, (int) config.getIncomeRate());
Expand Down Expand Up @@ -155,7 +155,7 @@ public static Entity createIncomeTower() {
*/
public static Entity createWallTower() {
Entity wall = createBaseTower();
WallTowerConfig config = configs.wall;
WallTowerConfig config = configs.getWall();
AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new WallTowerDestructionTask(COMBAT_TASK_PRIORITY,TNT_TOWER_MAX_RANGE));

Expand Down Expand Up @@ -191,7 +191,7 @@ public static Entity createTNTTower() {
.setLayer(PhysicsLayer.NONE)
.setSensor(true);
TNTTower.getComponent(ColliderComponent.class).setSensor(true);
TNTTowerConfigs config = configs.TNTTower;
TNTTowerConfigs config = configs.getTNTTower();

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new TNTTowerCombatTask(COMBAT_TASK_PRIORITY,TNT_TOWER_MAX_RANGE));
Expand Down Expand Up @@ -227,7 +227,7 @@ public static Entity createTNTTower() {
*/
public static Entity createDroidTower() {
Entity droidTower = createBaseTower();
DroidTowerConfig config = configs.DroidTower;
DroidTowerConfig config = configs.getDroidTower();

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new DroidCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE));
Expand Down Expand Up @@ -264,7 +264,7 @@ public static Entity createDroidTower() {
*/
public static Entity createWeaponTower() {
Entity weapon = createBaseTower();
WeaponTowerConfig config = configs.weapon;
WeaponTowerConfig config = configs.getWeapon();

// AiTaskComponent will run the tower task which carries out detection of targets and trigger events
AITaskComponent aiTaskComponent = new AITaskComponent()
Expand Down Expand Up @@ -298,7 +298,7 @@ public static Entity createWeaponTower() {
*/
public static Entity createFireTower() {
Entity fireTower = createBaseTower();
FireTowerConfig config = configs.fireTower;
FireTowerConfig config = configs.getFireTower();

//Component that handles triggering events and animations
AITaskComponent aiTaskComponent = new AITaskComponent()
Expand Down Expand Up @@ -331,7 +331,7 @@ public static Entity createFireTower() {
*/
public static Entity createStunTower() {
Entity stunTower = createBaseTower();
StunTowerConfig config = configs.stunTower;
StunTowerConfig config = configs.getStunTower();

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new StunTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE));
Expand Down Expand Up @@ -362,7 +362,7 @@ public static Entity createStunTower() {
*/
public static Entity createFireworksTower() {
Entity fireworksTower = createBaseTower();
FireworksTowerConfig config = configs.fireworksTower;
FireworksTowerConfig config = configs.getFireworksTower();

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new FireworksTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE));
Expand Down Expand Up @@ -391,7 +391,7 @@ public static Entity createFireworksTower() {
*/
public static Entity createPierceTower() {
Entity pierceTower = createBaseTower();
PierceTowerConfig config = configs.pierceTower;
PierceTowerConfig config = configs.getPierceTower();

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new PierceTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE));
Expand Down Expand Up @@ -422,7 +422,7 @@ public static Entity createPierceTower() {
*/
public static Entity createRicochetTower() {
Entity ricochetTower = createBaseTower();
RicochetTowerConfig config = configs.ricochetTower;
RicochetTowerConfig config = configs.getRicochetTower();

AITaskComponent aiTaskComponent = new AITaskComponent()
.addTask(new RicochetTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE));
Expand Down

0 comments on commit ce87c1b

Please sign in to comment.