-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating boards from wood in a building #124
Conversation
Removing the production and now buildings are added to the factory. Buildings now keep information about the current workers and the amount of produces goods.
theLudovyc/Building/Building.gd
Outdated
@@ -10,6 +10,8 @@ signal selected(type) | |||
var event_bus: EventBus | |||
|
|||
var is_selected := false | |||
var current_ticks: int = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello 👋
I made an architecture like MVC, with backend and frontend. The class building2d is only here for the frontend part. Please do not add backend logic in here 😊
This is why the event_bus exist also.
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted the code in order to fit the MVC pattern.
theLudovyc/Building/Buildings.gd
Outdated
Ids.Warehouse: {Datas.Name: &"Warehouse", Datas.Type: Types.Warehouse}, | ||
Ids.Tent: | ||
{ | ||
Datas.Name: &"Tent", | ||
Datas.Type: Types.Residential, | ||
Datas.Cost: [[Resources.Types.Wood, 1], [Resources.Types.Textile, 1]], | ||
Datas.Cost: [[Resources.Types.Board, 1], [Resources.Types.Textile, 1]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the roadmap and code, I regroup resources in tiers.
T1 / Sailors => Gathering, Collecting, like get wood / construct building with woods
T2 / Pioneers => First transform, like wood in planks / construct building with planks
etc...
So, currently you work on the v0.02 and not on v0.01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new building sawmill which uses wood to generate boards / planks.
Using the flipped image and icon of the lumberjack because no specific icon and image are in the old game :/
theLudovyc/GUI/BuildingContainer.gd
Outdated
@@ -8,15 +8,15 @@ extends VBoxContainer | |||
|
|||
@onready var confirmation_dialog := %ConfirmationDialog | |||
|
|||
const confirmation_text = "Are you sure you want to demolish this building?" | |||
const confirmation_text: String = "Are you sure you want to demolish this building?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to type a constant. Instead of variable they are not Variant. They are typed are at creation. https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#constants
@@ -1,4 +1,5 @@ | |||
extends VBoxContainer | |||
class_name BuildingProducingContainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to add the class_name specifier if you do not use this class outside
theLudovyc/Resources/Resources.gd
Outdated
|
||
|
||
enum LevelTypes { Gathered, TransformedOnce, TransformedTwice } | ||
return AllResources.get(resource_type)[2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regroup the datas is a good idea. But here, you do not handle the case where resource_type can be not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair - your code did not either ;)
What should be the outcome if the type is not found? A dummy icon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do this with
static func get_resource_icon(resource_type: Types) -> Texture2D:
return Icons.get(resource_type)
From the doc about Dictionary.get(...) If the key does not exist, returns default, or null if the parameter is omitted.
In your proposal you can call [2] on a null value
theLudovyc/Resources/Resources.gd
Outdated
|
||
const Levels = {Types.Wood: LevelTypes.Gathered, Types.Textile: LevelTypes.TransformedTwice} | ||
|
||
static func get_rescources_level(resource_type: Types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bad, do not return 0 please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unused method
theLudovyc/TheFactory.gd
Outdated
|
||
var workers := 0: | ||
set(value): | ||
workers = value | ||
event_bus.available_workers_updated.emit(game.population - workers) | ||
|
||
enum Waiting_Lines { resource_type, needed_workers } | ||
var waiting_lines = [] | ||
var waiting_line_buildings: Array[Building2D] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way you use building here. But please respect the MVC architecture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
theLudovyc/TheMarket.gd
Outdated
return 0 | ||
|
||
return Resources.Levels[resource_type] + 1 | ||
#TODO Michael: check this method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#TODO Michael: check this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted method to current implementation.
@@ -50,18 +50,8 @@ func try_to_sell_resource(resource_type: Resources.Types, amount: int) -> bool: | |||
return false | |||
|
|||
|
|||
func update_global_production_rate(resource_type: Resources.Types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove it, how do you send the resource update ? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIth storage.add_resource().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the resource production rate per tick, with event_bus.resource_prodution_rate_updated
…to fit the MVC pattern
Producing boards from wood
@@ -9,11 +9,11 @@ class_name Game2D | |||
|
|||
@onready var node_entities := %Entities | |||
|
|||
@onready var the_storage := $TheStorage | |||
@onready var the_storage: TheStorage = $TheStorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay maybe it can help on the @onready var , and you need to write the type. But please try to add just the necessary ( := , and yes typing variable increase performances). GdScript is a scripting language, dynamically and weakly typed. I know it can be hard for a Java programmer, but try your best please 😊
theLudovyc/TheFactory.gd
Outdated
i += 1 | ||
i = i + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seriously ? 😅
theLudovyc/TheFactory.gd
Outdated
for single_building in buildings: | ||
if is_instance_of(single_building, ProductionBuildingModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm is not efficient. Maybe you can make an array with just ProductionBuildings in theFactory.
theLudovyc/TheFactory.gd
Outdated
for building_model in buildings: | ||
if building_model.id == id: | ||
return building_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm is not efficient. Maybe you can make a dictionary [id]=building_model .
@@ -50,18 +50,8 @@ func try_to_sell_resource(resource_type: Resources.Types, amount: int) -> bool: | |||
return false | |||
|
|||
|
|||
func update_global_production_rate(resource_type: Resources.Types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the resource production rate per tick, with event_bus.resource_prodution_rate_updated
theLudovyc/Game2D.gd
Outdated
var uuid: String = uuid_util.v4() | ||
instance.id = uuid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did not you write instance.id = uuid_util.v4()
?
sendProducedItems(storage) | ||
produce() | ||
collect(storage) | ||
|
||
|
||
func collect(storage: TheStorage): | ||
var amount: int = 1 | ||
if storage.has_enough_resources(amount, getNeedItemType()): | ||
storage.add_resource(getNeedItemType(), -amount) | ||
input_resource_amount = input_resource_amount + amount | ||
|
||
|
||
func produce(): | ||
if input_resource_amount > 0: | ||
input_resource_amount = input_resource_amount - 1 | ||
output_resource_amount = output_resource_amount + 1 | ||
|
||
|
||
func sendProducedItems(storage: TheStorage): | ||
var output: int = output_resource_amount | ||
output_resource_amount = 0 | ||
storage.add_resource(getProducedItemType(), output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make 3 methods who are called just once ?
Removing the production and now buildings are added to the factory. Buildings now keep information about the current workers and the amount of produces goods.