Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

TheSephyr
Copy link

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.

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.
@@ -10,6 +10,8 @@ signal selected(type)
var event_bus: EventBus

var is_selected := false
var current_ticks: int = 0
Copy link

@theludovyc theludovyc Nov 11, 2024

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

Copy link
Author

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.

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]],
Copy link

@theludovyc theludovyc Nov 11, 2024

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

Copy link
Author

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 :/

@@ -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?"

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

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/GUI/ResourceControl.gd Outdated Show resolved Hide resolved


enum LevelTypes { Gathered, TransformedOnce, TransformedTwice }
return AllResources.get(resource_type)[2]

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

Copy link
Author

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?

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


const Levels = {Types.Wood: LevelTypes.Gathered, Types.Textile: LevelTypes.TransformedTwice}

static func get_rescources_level(resource_type: Types):

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused method


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] = []

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return 0

return Resources.Levels[resource_type] + 1
#TODO Michael: check this method

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

Copy link
Author

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):

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 ? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIth storage.add_resource().

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

Michael Kröll added 2 commits November 13, 2024 16:41
@TheSephyr TheSephyr requested a review from theludovyc November 14, 2024 18:44
@@ -9,11 +9,11 @@ class_name Game2D

@onready var node_entities := %Entities

@onready var the_storage := $TheStorage
@onready var the_storage: TheStorage = $TheStorage
Copy link

@theludovyc theludovyc Nov 18, 2024

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 😊

Comment on lines 116 to 74
i += 1
i = i + 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously ? 😅

Comment on lines 92 to 93
for single_building in buildings:
if is_instance_of(single_building, ProductionBuildingModel):

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.

Comment on lines 99 to 101
for building_model in buildings:
if building_model.id == id:
return building_model

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):

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

Comment on lines 204 to 205
var uuid: String = uuid_util.v4()
instance.id = uuid

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() ?

Comment on lines 10 to 31
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)

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 ?

@TheSephyr TheSephyr closed this Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants