From ce87c1bcbbcda77573ac5bd486a8c2d7aa7af9c8 Mon Sep 17 00:00:00 2001 From: Nhat Minh Le Date: Tue, 17 Oct 2023 01:07:14 +1000 Subject: [PATCH] Fix code smells in BaseTowerConfigs: set private fields + add getters --- .../entities/configs/BaseTowerConfigs.java | 105 ++++++++++++++++++ .../configs/FireworksTowerConfig.java | 2 +- .../entities/configs/baseTowerConfigs.java | 18 --- .../game/entities/factories/TowerFactory.java | 26 ++--- 4 files changed, 119 insertions(+), 32 deletions(-) create mode 100644 source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java delete mode 100644 source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java diff --git a/source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java new file mode 100644 index 000000000..03530fef3 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java @@ -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; + } +} \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java index d8b595af8..099ab0dce 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java @@ -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 diff --git a/source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java deleted file mode 100644 index c1b3f997a..000000000 --- a/source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.csse3200.game.entities.configs; - -/** - * Defines all tower configs to be loaded by the Tower Factory. - */ -public class baseTowerConfigs { - public WeaponTowerConfig weapon = new WeaponTowerConfig(); - public WallTowerConfig wall = new WallTowerConfig(); - public IncomeTowerConfig income = new IncomeTowerConfig(); - public FireTowerConfig fireTower = new FireTowerConfig(); - public StunTowerConfig stunTower = new StunTowerConfig(); - public TNTTowerConfigs TNTTower = new TNTTowerConfigs(); - public DroidTowerConfig DroidTower = new DroidTowerConfig(); - public FireworksTowerConfig fireworksTower = new FireworksTowerConfig(); - public PierceTowerConfig pierceTower = new PierceTowerConfig(); - public RicochetTowerConfig ricochetTower = new RicochetTowerConfig(); - public HealTowerConfig HealTower = new HealTowerConfig(); -} \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java index 4314c0d13..a0dd250a7 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java @@ -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); @@ -113,8 +113,8 @@ 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 @@ -122,7 +122,7 @@ public class TowerFactory { */ 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()); @@ -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)); @@ -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)); @@ -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)); @@ -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() @@ -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() @@ -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)); @@ -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)); @@ -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)); @@ -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));