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