New floors - Alexofp/BDCC GitHub Wiki
Floors can be registered by putting the script and scene file in res://Game/World/Floors
, the ID will be whatever the file name is without the extension.
Or it can be registered with a module calling a method registerMapFloor(id:string, path:string)
in GlobalRegistry
If the ID existed already, it will replace the floor entirely with new one.
Registering new floor requires scene file (will go into detail next section)
For example:
GlobalRegistry.registerMapFloor("grindingFloor","res://Modules/Z_IgrindingFloor/Floor/grindingFloor.tscn")
This will register a floor with ID "grindingFloor" with the path res://Modules/Z_IgrindingFloor/Floor/grindingFloor.tscn
aka scene file
A floor is essentially 2 files, the scripting part and the floor layout (or scene part).
The scripting part is optional but this article will include it.
It is recommended to include scripting, you will thank me later.
Inside the scene file, a floor is essentially a Node2D which instanced res://Game/World/SubWorld.tscn
(will go into detail how to create such)
Each floor is consists of rooms in 64 unit grids in both X and Y axis, if they're unaligned, on runtime it will automatically snap to the nearest point in a grid*
* it's not exactly the nearest point, please check these lines.
A room is a Node2D which instanced res://Game/World/GameRoom.tscn
(will go into detail how to create such)
Each room must be assigned to unique ID, if 2 rooms have the same ID, whichever loads last get rejected, this also applies to other floors. This means that if you have a room that have the same ID as the other, the room that load last will disappear or crash the game entirely
(as of 2024-05-16 - I, CanInBad, didn't check if it cause crashes or not)
A room can be configured a lot to do a lot of things, below image is an example
![A image showing properties in a room](https://github.com/Alexofp/BDCC/wiki/images/floor/roomProperties.png)
A image showing properties in a room
- Room Name
- This is used to display room's name on the top of the floor preview on runtime
Can be repeated with other rooms'
- This is used to display room's name on the top of the floor preview on runtime
- Room Id
⚠️ This is required and must not be repeated.
- Room Description
- This is for showing message when you're in a room. The message will appear on the text log.
- Can X
- If the direction is off, any room that connected in that direction will not be walkable, This will also affect path finding for scene using them.
- Room Sprite & Color
- Changes room's appearance on presets, experiment and see what they do.
- Grid Color
- Changes striped color across the room, if its on white the stripe will be invisible.
- Loctags
- Changes which type(s) of guards spawns in the room. I haven't check if having multiple of them do anything.
- Population
- Changes which type of NPC to spawn. Please note that nurses, guards, and engineers are grouped as Guards
- Lootable and its settings
- Table Id
- Which loot table to use when looting.
At the time of writing, I haven't experiment with this yet -CIB
- Which loot table to use when looting.
- Around Message
- What message to display when the room is lootable
- Credits
- How much credit do player get once looting
- Every X Days
- When do the loots get refills. If not specified, it will never get refilled.
- Table Id
It is recommended that you do not use Lootable properties, using events will give you more flexibility.
First step is to create a new scene file. It can be in the folder we discuss in Floors Basics but this guide will follow registering the floor with module.
(if you don't know anything about module, you can learn about it here)
Right click on FileSystem window, it can be any folder or even a file and click "New Scene..."
You can name it whatever, the file extension will be .tscn
.
![A image showing steps to create new scene](https://github.com/Alexofp/BDCC/wiki/images/floor/newSceneFloor.png)
A image showing steps to create new scene
Next, Click the chain link icon in the scene tab
![A image showing mouse cursor hovering over the icon with text "Instance Child Scene"](https://github.com/Alexofp/BDCC/wiki/images/floor/instanceChildScene.png)
A image showing mouse cursor hovering over the icon with text "Instance Child Scene"
You then have to navigate yourself to res://Game/World
, select SubWorld.tscn
, and open it
![A image showing a window title "Open Base Scene" while selecting "SubWorld.tscn" in its file explorer](https://github.com/Alexofp/BDCC/wiki/images/floor/floorSelectingSubWorld.png)
A image showing a window title "Open Base Scene" while selecting "SubWorld.tscn" in its file explorer
After opening, you will see a item/Node2D in Scene tab.
You can rename it whatever but ideally I recommend name it to the ID you're going to use, mine is going to be "helloWorld".
Please note that this Node2D is a root of a floor, without it a floor doesn't exist
![Renaming a node by right click on it and click "Rename", or click F2](https://github.com/Alexofp/BDCC/wiki/images/floor/floorRenamingRootNode.png)
Renaming a node by right click on it and click "Rename", or hit F2
Adding scripting is easy as selecting the Node2D and click arrow drop down menu then click Extend Script, it is recommended to keep them together in the same folder as the floor scene file.
A script can do things that events could but bundled with the floor itself.
(There will be demo later after we finish making rooms)
It is recommended to save at this stage. If you haven't save earlier it will prompt you to choose a location. Please be mindful of where you put it.
![Image showing steps to extend script](https://github.com/Alexofp/BDCC/wiki/images/floor/floorExtendScript.png)
Image showing steps to extend script
After creating floor root node, we'll be covering how to make rooms
Firstly, click the root node to select, then click the chain icon again to add another PackedScene, then search for "GameRoom". Select the one that says Game/World/GameRoom.tscn
then open it.
![Image showing a dialog box with text "GameRoom"](https://github.com/Alexofp/BDCC/wiki/images/floor/floorAddNewRoom.png)
Image showing a dialog box with text "GameRoom"
Congratulations! You successfully created a room. Please give them ID an make sure that its not duplicating others.
Note
If you don't put in any ID, it will use the editor's room name or node's name to be used as ID.
And if you don't put any room's name, it will use the ID as room's name.
See the relevant code here.
If you don't want to click the chain icon everytime you want to add a room, I recommend duplicating it, this can be done by either right clicking a room on the left and click "Duplicate". Or hitting Control + D. Be sure to change the ID every time you do this.
Now to move it. It is recommend to set up grid snapping for easier room moving. On the scene editor, there is a 3 vertical dot (its called kabab menu) next to magnet on a grid, click the kebab menu. Then click "Configure Snap...", a window will pop up. Set the "Grid Step" for both X and y to 64px.
Make sure that you have Grid Snapping turned on when you're moving or else it won't snap
![Image showing steps to configure snap](https://github.com/Alexofp/BDCC/wiki/images/floor/floorConfigureSnap.png)
Image showing steps to configure snap
![This is my snap config when editing floor -CIB](https://github.com/Alexofp/BDCC/wiki/images/floor/floorSnapConfig.png)
This is my snap config when editing floor -CIB
Room connections is done in runtime so you don't have to manually put them down.
They are made when a room has walkable room either to east or south. Please see the relevant code here.
This section will be short and not very helpful since most things that room scripting can do, events does it better.
This will take advantage of signals, and this section will assumed that you already read Connecting a signal in the editor.
Signal onEnter
will trigger when a player entered the room
Signal onPreEnter
will trigger when a player is moving to the room
Signal onReact
is only used with buttons.
List of methods you can use is inside res://Game/World/GameRoom.gd
and examples for using it can be look for inside res://Game/World/Floors
.
This is a example project demonstrating how to add new floor as a module as well as other topics in this page. If you do not know what is a module please consult this wiki page on Alexofp/BDCC.