Skip to content

Commit

Permalink
Merge branch 'feature/issue-276' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aussig committed Oct 29, 2024
2 parents fef895f + ed05e86 commit 68c3350
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New Features:

* Added new Discord formatter supporting the Celestial Light Brigade's preferred Discord structure and layout for BGS reports.
* Each faction now has its influence % shown in the on-screen activity window.

### Changes:

Expand Down
26 changes: 15 additions & 11 deletions bgstally/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def clear_activity(self, mission_log: MissionLog):
sum(int(d['scooped']) for d in system['TWSandR'].values()) > 0:
# The system has a current mission, or it's the current system, or it has TWSandR scoops - zero, don't delete
for faction_name, faction_data in system['Factions'].items():
system['Factions'][faction_name] = self._get_new_faction_data(faction_name, faction_data['FactionState'])
system['Factions'][faction_name] = self._get_new_faction_data(faction_name, faction_data['FactionState'], faction_data['Influence'])
system['TWKills'] = self._get_new_tw_kills_data()
# Note: system['TWSandR'] scooped data is carried forward, delivered data is cleared
for d in system['TWSandR'].values():
Expand Down Expand Up @@ -313,15 +313,16 @@ def system_entered(self, journal_entry: Dict, state: State):
if faction['Name'] == "Pilots' Federation Local Branch": continue

# Ignore conflict states in FactionState as we can't trust they always come in pairs. We deal with conflicts separately below.
faction_state = faction['FactionState'] if faction['FactionState'] not in STATES_WAR and faction['FactionState'] not in STATES_ELECTION else "None"
faction_state: str = faction['FactionState'] if faction['FactionState'] not in STATES_WAR and faction['FactionState'] not in STATES_ELECTION else "None"
faction_inf: float = faction['Influence']

if faction['Name'] in current_system['Factions']:
# We have this faction, ensure it's up to date with latest state
faction_data = current_system['Factions'][faction['Name']]
self._update_faction_data(faction_data, faction_state)
self._update_faction_data(faction_data, faction_state, faction_inf)
else:
# We do not have this faction, create a new clean entry
current_system['Factions'][faction['Name']] = self._get_new_faction_data(faction['Name'], faction_state)
current_system['Factions'][faction['Name']] = self._get_new_faction_data(faction['Name'], faction_state, faction_inf)

# Set war states for pairs of factions in War / Civil War / Elections
for conflict in journal_entry.get('Conflicts', []):
Expand Down Expand Up @@ -1126,9 +1127,9 @@ def get_sample_system_data(self) -> dict:
return {'System': "Sample System Name",
'SystemAddress': 1,
'zero_system_activity': False,
'Factions': {"Sample Faction Name 1": self._get_new_faction_data("Sample Faction Name 1", "None", True),
"Sample Faction Name 2": self._get_new_faction_data("Sample Faction Name 2", "None", True),
"Sample Faction Name 3": self._get_new_faction_data("Sample Faction Name 3", "None", True)},
'Factions': {"Sample Faction Name 1": self._get_new_faction_data("Sample Faction Name 1", "None", 40, True),
"Sample Faction Name 2": self._get_new_faction_data("Sample Faction Name 2", "None", 30, True),
"Sample Faction Name 3": self._get_new_faction_data("Sample Faction Name 3", "None", 30, True)},
'TWKills': self._get_new_tw_kills_data(True),
'TWSandR': self._get_new_tw_sandr_data(True),
'TWReactivate': 5}
Expand All @@ -1154,7 +1155,7 @@ def _get_new_system_data(self, system_name: str, system_address: str, faction_da
'TWReactivate': 0}


def _get_new_faction_data(self, faction_name: str, faction_state: str, sample: bool = False) -> dict:
def _get_new_faction_data(self, faction_name: str, faction_state: str, faction_inf: float, sample: bool = False) -> dict:
"""Get a new data structure for storing faction data
Args:
Expand All @@ -1166,7 +1167,7 @@ def _get_new_faction_data(self, faction_name: str, faction_state: str, sample: b
dict: The faction data
"""
s: bool = sample # Shorter
return {'Faction': faction_name, 'FactionState': faction_state, 'Enabled': self.bgstally.state.EnableSystemActivityByDefault.get(),
return {'Faction': faction_name, 'FactionState': faction_state, 'Influence': faction_inf, 'Enabled': self.bgstally.state.EnableSystemActivityByDefault.get(),
'MissionPoints': {'1': 3 if s else 0, '2': 4 if s else 0, '3': 5 if s else 0, '4': 6 if s else 0, '5': 7 if s else 0, 'm': 8 if s else 0},
'MissionPointsSecondary': {'1': 3 if s else 0, '2': 4 if s else 0, '3': 5 if s else 0, '4': 6 if s else 0, '5': 7 if s else 0, 'm': 8 if s else 0},
'BlackMarketProfit': 50000 if s else 0, 'Bounties': 1000000 if s else 0, 'CartData': 2000000 if s else 0, 'ExoData': 3000000 if s else 0,
Expand Down Expand Up @@ -1260,12 +1261,13 @@ def _update_system_data(self, system_data:dict):
if not 'tp' in system_data['TWSandR']: system_data['TWSandR']['tp'] = {'scooped': 0, 'delivered': 0}


def _update_faction_data(self, faction_data: Dict, faction_state: str = None):
def _update_faction_data(self, faction_data: dict, faction_state: str|None = None, faction_inf: float|None = None):
"""
Update faction data structure for elements not present in previous versions of plugin
"""
# Update faction state as it can change at any time post-tick
# Update faction state and influence as it can change at any time post-tick
if faction_state: faction_data['FactionState'] = faction_state
if faction_inf: faction_data['Influence'] = faction_inf

# From < v1.2.0 to 1.2.0
if not 'SpaceCZ' in faction_data: faction_data['SpaceCZ'] = {}
Expand Down Expand Up @@ -1314,6 +1316,8 @@ def _update_faction_data(self, faction_data: Dict, faction_state: str = None):
faction_data['MissionPointsSecondary'] = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, 'm': int(faction_data.get('MissionPointsSecondary', 0))}
# From < 4.0.0 to 4.0.0
if not 'SandR' in faction_data: faction_data['SandR'] = {'dp': 0, 'op': 0, 'tp': 0, 'bb': 0, 'wc': 0, 'pe': 0, 'pp': 0, 'h': 0}
# From < 4.2.0 to 4.2.0
if not 'Influence' in faction_data: faction_data['Influence'] = 0


def _is_faction_data_zero(self, faction_data: Dict):
Expand Down
2 changes: 2 additions & 0 deletions bgstally/windows/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def show(self, activity: Activity):

col: int = 1
ttk.Label(frm_table, text=_("Faction"), font=FONT_HEADING_2).grid(row=0, column=col, padx=2, pady=2); col += 1 # LANG: Activity window column title
ttk.Label(frm_table, text="%", font=FONT_HEADING_2).grid(row=0, column=col, padx=2, pady=2); col += 1
ttk.Label(frm_table, text=_("State"), font=FONT_HEADING_2).grid(row=0, column=col, padx=2, pady=2); col += 1 # LANG: Activity window column title
lbl_inf: ttk.Label = ttk.Label(frm_table, text="INF", font=FONT_HEADING_2, anchor=tk.CENTER) # LANG: Activity window column title, abbreviation for influence
lbl_inf.grid(row=0, column=col, columnspan=2, padx=2)
Expand Down Expand Up @@ -272,6 +273,7 @@ def show(self, activity: Activity):
settlement_row_index += 1

col = 2
ttk.Label(frm_table, text="{0:.2f}".format(faction['Influence'] * 100)).grid(row=x + header_rows, column=col, sticky=tk.N); col += 1
ttk.Label(frm_table, text=faction['FactionState']).grid(row=x + header_rows, column=col, sticky=tk.N); col += 1
MissionPointsVar = tk.IntVar(value=faction['MissionPoints']['m'])
ttk.Spinbox(frm_table, from_=-999, to=999, width=3, textvariable=MissionPointsVar).grid(row=x + header_rows, column=col, sticky=tk.N, padx=2, pady=2); col += 1
Expand Down

0 comments on commit 68c3350

Please sign in to comment.