Skip to content

Commit

Permalink
Merge pull request #160 from vegastrike/task_radar
Browse files Browse the repository at this point in the history
Fix issue in upgrade view
  • Loading branch information
royfalk authored Mar 2, 2025
2 parents 5c45bb8 + 4dd5292 commit cf8fbef
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion python/base_computer/upgrade_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,30 @@ def process_resource(key, resource_text):
original = float(parts[original_index])

return f"{format_number(damaged)} (orig: {format_number(original)})"

# Process a serialized int Resource
# Output is in the format of <current>/<max_damaged>/<max_original>
# We convert to <current> (orig: <max_original>)
def process_range(text):
parts = text.split('/')

damaged_index = 0
original_index = 0

if len(parts) == 2:
damaged_index = 0
original_index = 1
elif len(parts) == 3:
damaged_index = 1
original_index = 2
else:
return text

damaged = int(parts[damaged_index])/1000
original = int(parts[original_index])/1000

return f"{format_number(damaged)} (orig: {format_number(original)})"

# We process a line to find the tag <key> or <key=value>
# <key> we convert to unit[key] and replace the tag with it.
# <key=value> we again convert and check if equal to value.
Expand Down Expand Up @@ -273,7 +296,7 @@ def get_upgrade_info(unit_stats):

# Radar range in km not meters
if 'Radar_Range' in unit:
unit['Radar_Range'] = format_number(int(unit['Radar_Range'])/ 1000)
unit['Radar_Range'] = process_range(unit['Radar_Range'])

text = ''

Expand Down

0 comments on commit cf8fbef

Please sign in to comment.