-
Notifications
You must be signed in to change notification settings - Fork 9
StructureToolPicker
See also Components, Tool
The structure tool picker is a UI component which can be used to select a structure tool. When a structure tool is selected, it can perform an interaction at a given grid position within the map. Available tools are defined within the structure_tools.json
config file and must have a corresponding class inheriting from Tool
.
Tools can be unlocked via the Upgrade Tree. This allows for progression throughout the game. See here for more information about the Upgrade Tree.
To use the Tool Picker in game, you must first select the hammer in the players inventory by either clicking the button on the right hand side of the screen or pressing H.
Once the hammer is selected, you should then see all your available structures and tools in the hotbar down the bottom of the screen. You can either click on the buttons or press the associated number key to select each tool.
Only the extractor and heal tool are unlocked at the beginning of the game.
Once a tool has been selected you may click on a map tile to interact with it.
To unlock more tools, you must navigate to the Upgrade Tree.
The list of tools available are:
- Dirt Wall Tool which is used to place dirt walls.
- Stone Wall Tool which is used to place stone walls.
- Turret Tool which is used to place turrets.
- Advanced Turret Tool which is used to place advanced turrets.
- Extractor Tool which is used to place extractors on fissures.
- Gate Tool which is used to place gates.
- Heal Tool which is used to heal damaged structures.
- Landmine Tool which is used to place landmines.
- Explosive Barrel Tool which is used to place explosive barrels.
PREREQUISITE: you must have created a config file names structure_tools.json
within the assets/configs
directory. To learn more about this config file, read this section.
First, add the following to your import list:
import com.csse3200.game.components.structures.StructureToolPicker;
Now you can instantiate a new StructureToolPicker
as follows:
var structureToolPicker = new StructureToolPicker();
You can now add this component to an entity. Please note that the entity this component is added to will be passed to the interact function of each tool.
var player = new Entity();
player.addComponent(structureToolPicker);
Register your entity with the entity service.
ServiceLocator.getEntityService().registerEntity(player);
To show the UI to the player, call structureToolPicker.show()
, and to hide the UI, call structureToolPicker.hide()
. You can also check whether the UI is visible by called structureToolPicker.isVisible()
.
It is possible to manually change the selected tool by calling the following:
structureToolPicker.setSelectedTool(tool);
This is not necessary, however, since the buttons within the UI will call this when invoked.
You may get the currently selected tool via structureToolPicker.getSelectedTool()
.
You may change the level of the StructureToolPicker
via setLevel(int level)
, and you may get the current level by calling getLevel()
.
Finally, you may interact with the selected tool as follows:
// getClickGridPosition is an example function. It is not implemented within the game.
var gridPosition = getClickGridPosition();
structureToolPicker.interact(gridPosition);
This will call the interact method on the selected Tool
.
In order for this component to work, you must have created a config file names structure_tools.json
within the assets/configs
directory.
Here is an example config file.
{
"toolConfigs": {
"com.csse3200.game.components.structures.tools.BasicWallTool": {
"name": "Dirt Wall",
"description": "A sturdy wall made of dirt for basic protection!",
"cost": {
"Durasteel": 25
},
"texture": "images/structure-icons/wall.png",
"ordering": 2,
"range": 8.0
},
"com.csse3200.game.components.structures.tools.IntermediateWallTool": {
"name": "Stone Wall",
"description": "Upgrade to stone for enhanced durability against attacks!",
"cost": {
"Durasteel": 50
},
"texture": "images/structure-icons/stone_wall.png".
"ordering": 2,
"range": 8.0
}
}
}
The key for each entry (e.g. com.csse3200.game.components.structures.tools.BasicWallTool
) must point to a class inheriting from Tool
. The values following the class name contain the properties for that particular tool. You must define:
- name - this specified the display name to use for the tool.
- description - the description for the tool used in the unlock menu.
- cost - this specifies the cost associated with the tool. This may be per use, per structure placed, or used another way as defined in the specified
Tool
class. - texture - this points to a png file containing the icon to use for this tool.
- ordering - the order the tool should appear in the hotbar.
- range - how far away the tool can be used.
To add your own tool to the StructureToolPicker, you must first create a Tool
(see here). Once a Tool
is created, you can then add a new entry to the config by creating a new key value entry within toolConfigs
, where the key is the long name of your new Tool
class, and the value is an object containing the properties here.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files