Temporarily add overall production percentage for usability

This commit is contained in:
Ben 2024-02-02 00:35:14 +01:00
parent e106fe6a03
commit 51ef6fe385
Signed by: ben
GPG key ID: 0F54A7ED232D3319

View file

@ -191,17 +191,14 @@ class Machine(BaseNode):
checkbox_widget.setStyleSheet(
checkbox_widget.styleSheet() + "\nQCheckBox {\n" f"background-color: transparent;\n" "}"
)
self.actual_performance_slider = NodeSlider(
self.add_text_input(
name=Machine.ACTUAL_PERFORMANCE_PROP,
label="Machine Production Factor",
parent=self.view,
readonly=True,
label="Overall Production",
text="100",
)
self.add_custom_widget(
widget=self.actual_performance_slider,
widget_type=NodePropWidgetEnum.HIDDEN.value,
)
self.actual_performance_slider.value_changed.connect(self.actual_performance_changed)
widget: NodeLineEdit = self.get_widget(Machine.ACTUAL_PERFORMANCE_PROP)
line_edit_widget: QLineEdit = widget.get_custom_widget()
line_edit_widget.setReadOnly(True)
def max_performance_changed(self):
self.set_property(Machine.AUTOMATIC_PERFORMANCE_PROP, False)
@ -210,30 +207,32 @@ class Machine(BaseNode):
def recalculate_factor(self):
max_factor: float = self.get_property(Machine.MAXIMUM_PERFORMANCE_PROP) / 100.0
if max_factor < 1.0 and self.get_property(Machine.AUTOMATIC_PERFORMANCE_PROP):
new_factor = 1.0
per_machine_factor = 1.0
else:
new_factor = max_factor
per_machine_factor = max_factor
all_machines_factor = None
for resource_label, wanted_resource in self.input_resources.items():
if len(self.get_input(resource_label).connected_ports()) != 0:
input_factor = self.possible_input_resources[resource_label] / wanted_resource
if input_factor < new_factor:
new_factor = input_factor
new_perf = int(new_factor * 100.0)
if self.get_property(Machine.ACTUAL_PERFORMANCE_PROP) != new_perf:
self.set_property(name=Machine.ACTUAL_PERFORMANCE_PROP, value=new_perf, push_undo=False)
if (
self.get_property(Machine.AUTOMATIC_PERFORMANCE_PROP)
and self.get_property(Machine.MAXIMUM_PERFORMANCE_PROP) != new_perf
):
self.set_property(name=Machine.MAXIMUM_PERFORMANCE_PROP, value=new_perf, push_undo=False)
new_factor = self.possible_input_resources[resource_label] / wanted_resource / per_machine_factor
if all_machines_factor is None:
all_machines_factor = new_factor
elif new_factor < all_machines_factor:
all_machines_factor = new_factor
if all_machines_factor is None:
all_machines_factor = per_machine_factor
new_perf = int(all_machines_factor * 100.0)
if int(self.get_property(Machine.ACTUAL_PERFORMANCE_PROP)) != new_perf:
self.get_widget(name=Machine.ACTUAL_PERFORMANCE_PROP).set_value(str(new_perf))
self.actual_performance_changed(name=Machine.ACTUAL_PERFORMANCE_PROP, factor=all_machines_factor)
if self.get_property(Machine.AUTOMATIC_PERFORMANCE_PROP):
self.set_property(name=Machine.MAXIMUM_PERFORMANCE_PROP, value=100, push_undo=False)
def update_input(self, resource_label: str, value: float):
self.possible_input_resources[resource_label] = value
self.recalculate_factor()
def actual_performance_changed(self, name: str, perf: int):
def actual_performance_changed(self, name: str, factor: float):
if name == Machine.ACTUAL_PERFORMANCE_PROP:
factor = perf / 100.0
for ingredient_label, amount in self.input_resources.items():
resource_text_widget = self.get_widget(in_amount_name(ingredient_label))
assert (
@ -321,7 +320,7 @@ class Machine(BaseNode):
return add_resource_text(node=self, name=name, text=text, border_color=border_color, readonly=True)
def get_resource_output(self, resource_label: str) -> float:
return self.output_resources[resource_label] * (self.get_property(Machine.ACTUAL_PERFORMANCE_PROP) / 100.0)
return self.output_resources[resource_label] * (int(self.get_property(Machine.ACTUAL_PERFORMANCE_PROP)) / 100.0)
def on_port_connected(input_port: Port, output_port: Port):