Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit c3d85ab

Browse files
Assign interaction sim to fix broken null check (#114)
* Assign interaction sim to fix broken null check * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/control_any_sim/patches/small_business_income_data.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d096cce commit c3d85ab

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/control_any_sim/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020

2121
import control_any_sim.cheats
22+
import control_any_sim.patches.small_business_income_data
2223
from control_any_sim import ts4_services
2324
from control_any_sim.services.integrity import IntegrityService
2425
from control_any_sim.services.interactions_service import InteractionsService
@@ -221,6 +222,7 @@ def canys_client_get_selector_visual_type(
221222
Override for Client::_get_selector_visual_type method.
222223
223224
Clear selector visual type override for controled sims.
225+
224226
"""
225227
try:
226228
Logger.log("getting selector visual type")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Patches for existing game classes."""
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Patches for the SmallBusinessIncomeData class."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING, Any, Callable
6+
7+
from small_business.small_business_income_data import SmallBusinessIncomeData
8+
9+
from control_any_sim.util.inject import (
10+
inject_method_to,
11+
)
12+
13+
if TYPE_CHECKING:
14+
from sims.sim import Sim
15+
16+
17+
@inject_method_to(SmallBusinessIncomeData, "_should_apply_markup_for_gain")
18+
def canys_should_apply_markup_for_gain(
19+
original: Callable[[SmallBusinessIncomeData, Sim, Any, Any], bool],
20+
self: SmallBusinessIncomeData,
21+
target_sim: Sim,
22+
interaction: Any, # noqa: ANN401
23+
tags: Any | None = None, # noqa: ANN401
24+
) -> bool:
25+
"""
26+
Override for SmallBusinessIncomeData::_should_apply_markup_for_gain method.
27+
28+
Fixes bug in the original implementation when the interaction.sim is not present.
29+
30+
Returns
31+
-------
32+
If the markup should be applied.
33+
34+
"""
35+
if target_sim is None:
36+
return False
37+
38+
# set an interaction sim when none is present. The original function incorrectly checks for a null value and runs into an attribute error otherwise.
39+
if (
40+
interaction is not None
41+
and self.is_sim_an_employee(target_sim.sim_info)
42+
and isinstance(interaction.sim, property)
43+
):
44+
interaction.sim = target_sim
45+
46+
return original(self, target_sim, interaction, tags)

0 commit comments

Comments
 (0)