Skip to content

Commit

Permalink
small changes to ui, added debug tickbox
Browse files Browse the repository at this point in the history
Small changes to the ui for #36 hopefully it looks nice.
Hopefuilly it works as intended.

Added a debug tickbox.
- if on on various places the plugin will report all sorts of things to the edmc debug log, will have to expand what it reports soon aswell.

- removing ignore tags in the code for too high cognitive complexity
  • Loading branch information
Balvald committed May 21, 2023
1 parent 30a1e5b commit 526c723
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 39 deletions.
35 changes: 25 additions & 10 deletions AST.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import logging
import os
import requests
import tkinter as tk
from typing import Optional

import myNotebook as nb # type: ignore
import requests
from config import appname, config # type: ignore

import saving
import ui
import organicinfo as orgi
import saving
from journalcrawler import build_biodata_json


logger = logging.getLogger(f"{appname}.{os.path.basename(os.path.dirname(__file__))}")


Expand All @@ -39,7 +40,7 @@ def __init__(self, AST_VERSION, AST_REPO, PLUGIN_NAME,

self.AST_in_Legacy: Optional[bool] = False

self.debug = debug
self.AST_debug: Optional[tk.IntVar] = tk.IntVar(value=config.get_int("AST_debug"))

# Be sure to use names that wont collide in our config variables
# Bools for show hide checkboxes
Expand Down Expand Up @@ -134,7 +135,12 @@ def on_load(self) -> str:
:return: The name of the plugin, which will be used by EDMC for logging
and for the settings window
"""
self.AST_bios_on_planet = self.ask_canonn_nicely(self.AST_current_system.get())
try:
self.AST_bios_on_planet = self.ask_canonn_nicely(self.AST_current_system.get())
except Exception as e:
logger.warning(e)
logger.warning(e.__doc__)
logger.warning("Couldn't get info about the SAAsignals in current system")
return self.PLUGIN_NAME

def on_unload(self) -> None:
Expand All @@ -146,7 +152,7 @@ def on_unload(self) -> None:
"""
self.on_preferences_closed("", False) # Save our prefs

def setup_preferences(self, parent: nb.Notebook, cmdr: str, is_beta: bool) -> Optional[tk.Frame]: # noqa #CCR001
def setup_preferences(self, parent: nb.Notebook, cmdr: str, is_beta: bool) -> Optional[tk.Frame]:
"""
setup_preferences is called by plugin_prefs below.
Expand Down Expand Up @@ -213,7 +219,7 @@ def setup_preferences(self, parent: nb.Notebook, cmdr: str, is_beta: bool) -> Op
ui.prefs_tickbutton(frame, checkboxlistright[i], variablelistright[i], current_row, 1, tk.W)
current_row += 1

if self.debug:
if (self.AST_debug.get()):

debuglistleft = ["species", "System of last Scan",
"Body of last Scan", "Scan progress",
Expand Down Expand Up @@ -269,6 +275,13 @@ def setup_preferences(self, parent: nb.Notebook, cmdr: str, is_beta: bool) -> Op

current_row += 1

ui.prefs_label(frame, line, current_row, 0, tk.W)
ui.prefs_label(frame, line, current_row, 1, tk.W)

current_row += 1

ui.prefs_tickbutton(frame, "Debug Mode", self.AST_debug, current_row, 1, tk.W)

return frame

def on_preferences_closed(self, cmdr: str, is_beta: bool) -> None:
Expand Down Expand Up @@ -300,6 +313,8 @@ def on_preferences_closed(self, cmdr: str, is_beta: bool) -> None:
self.AST_current_scan_progress.get() + ") on: " +
self.AST_last_scan_body.get() + " (" + str(worth))

config.set("AST_debug", int(self.AST_debug.get()))

config.set("AST_value", int(self.rawvalue))

config.set("AST_hide_value", int(self.AST_hide_value.get()))
Expand All @@ -322,12 +337,12 @@ def on_preferences_closed(self, cmdr: str, is_beta: bool) -> None:

config.set("AST_hide_scans_in_system", int(self.AST_hide_scans_in_system.get()))

if self.debug:
if bool(self.AST_debug.get()):
logger.debug(f"Currently last Commander is: {cmdr}")

config.set("AST_last_CMDR", str(cmdr))

if self.debug:
if bool(self.AST_debug.get()):
logger.debug("ArtemisScannerTracker saved preferences")

ui.rebuild_ui(self, cmdr)
Expand Down Expand Up @@ -409,12 +424,12 @@ def buildsoldbiodatajson(self) -> None:

def ask_canonn_nicely(self, system: str):
"""Ask Canonn how many biological signals are on any planets"""
if self.debug:
if bool(self.AST_debug.get()):
logger.debug(f"Asking Canonn for Info about: {system}")
response = requests.get(
f"https://us-central1-canonn-api-236217.cloudfunctions.net/query/getSystemPoi?system={system}")
data = response.json()
if self.debug:
if bool(self.AST_debug.get()):
logger.debug(f"Retrieved data: {data}")
dict_of_biological_counts = {}
try:
Expand Down
17 changes: 12 additions & 5 deletions eventhandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import ui
import organicinfo as orgi

logger = logging.getLogger(f"{appname}.{os.path.basename(os.path.dirname(__file__))}")

logger = logging.getLogger(f"{appname}.{os.path.basename(os.path.dirname(__file__))}")

alphabet = "abcdefghijklmnopqrstuvwxyz0123456789-"

Expand All @@ -24,7 +24,7 @@ def resurrection_event(plugin) -> None:
return []


def bioscan_event(cmdr: str, is_beta, entry, plugin, currententrytowrite) -> None: # noqa #CCR001
def bioscan_event(cmdr: str, is_beta, entry, plugin, currententrytowrite) -> None:
"""Handle the ScanOrganic event."""

# In the eventuality that the user started EMDC after
Expand Down Expand Up @@ -138,7 +138,7 @@ def bioscan_event(cmdr: str, is_beta, entry, plugin, currententrytowrite) -> Non
ui.rebuild_ui(plugin, cmdr)


def system_body_change_event(cmdr: str, entry, plugin) -> None: # noqa #CCR001
def system_body_change_event(cmdr: str, entry, plugin) -> None:
"""Handle all events that give a tell in which system we are or on what planet we are on."""
systemchange = False

Expand All @@ -153,7 +153,12 @@ def system_body_change_event(cmdr: str, entry, plugin) -> None: # noqa #CCR001
pass

if systemchange:
plugin.AST_bios_on_planet = plugin.ask_canonn_nicely(entry["StarSystem"])
try:
plugin.AST_bios_on_planet = plugin.ask_canonn_nicely(entry["StarSystem"])
except Exception as e:
logger.warning(e)
logger.warning(e.__doc__)
logger.warning("Couldn't get info about the SAAsignals in current system")
ui.rebuild_ui(plugin, cmdr)

# To fix the aforementioned eventuality where the systems end up
Expand All @@ -174,7 +179,7 @@ def system_body_change_event(cmdr: str, entry, plugin) -> None: # noqa #CCR001
saving.save_cmdr(cmdr, plugin)


def biosell_event(cmdr: str, entry, plugin) -> None: # noqa #CCR001
def biosell_event(cmdr: str, entry, plugin) -> None:
"""Handle the SellOrganicData event."""
soldvalue = 0

Expand Down Expand Up @@ -405,6 +410,8 @@ def biosell_event(cmdr: str, entry, plugin) -> None: # noqa #CCR001

def SAASignalsFound_event(entry, plugin) -> None:
for i in range(len(entry["Signals"])):
if bool(plugin.AST_debug.get()):
logger.debug(f"{entry['Signals'][i]['Type']}")
if entry["Signals"][i]["Type"] != "$SAA_SignalType_Biological;":
continue
if entry["BodyName"] in plugin.AST_bios_on_planet.keys():
Expand Down
6 changes: 4 additions & 2 deletions journalcrawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
It retraces all exobiology scans and sell actions.
"""

import json
import os

from organicinfo import generaltolocalised, getvistagenomicprices


# This goes through a folder of journals that it'll parse
# and check for analysed bio signals and the selling of it.

Expand All @@ -19,14 +21,14 @@
# Losing said exobiology data.
# In this case the lost data is assumed as sold by this script.


# For best results you can put your whole selection of journals
# downloaded from Journal limpet into the journaldir


alphabet = "abcdefghijklmnopqrstuvwxyz0123456789-"


def build_biodata_json(logger: any, journaldir: str) -> int: # noqa #CCR001
def build_biodata_json(logger: any, journaldir: str) -> int:
"""Build a soldbiodata.json and a notsoldbiodata that includes all sold organic scans that the player sold.
Also return the value of still unsold scans.
Expand Down
22 changes: 19 additions & 3 deletions load.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import organicinfo as orgi
from AST import ArtemisScannerTracker


frame: Optional[tk.Frame] = None

# Shows debug fields in preferences when True
Expand Down Expand Up @@ -42,6 +43,7 @@

filenames = ["\\soldbiodata.json", "\\notsoldbiodata.json", "\\cmdrstates.json"]


for file in filenames:
if not os.path.exists(directory + file):
f = open(directory + file, "w", encoding="utf8")
Expand All @@ -60,7 +62,8 @@
f.write(r"{}")
f.truncate()

# load notyetsolddata

# load notyetsolddata and cmdrstates

with open(directory + "\\notsoldbiodata.json", "r+", encoding="utf8") as f:
not_yet_sold_data = json.load(f)
Expand All @@ -79,12 +82,15 @@ def dashboard_entry(cmdr: str, is_beta, entry) -> None:
:param is_beta: Is the game currently in beta
:param entry: full excerpt from status.json
"""
# TODO: Move most of this into AST.py class

global plugin, firstdashboard

if plugin.AST_in_Legacy is True:
# We're in legacy we don't update anything through dashboard entries
return

# flag determines if we have to rebuild the ui at the end.
flag = plugin.handle_possible_cmdr_change(cmdr)

if firstdashboard:
Expand All @@ -94,11 +100,18 @@ def dashboard_entry(cmdr: str, is_beta, entry) -> None:
if "PlanetRadius" in entry.keys():
currentbody = plugin.AST_current_body.get()
# We found a PlanetRadius again, this means we are near a planet.

if currentbody != entry["BodyName"]:
# Body we are currently at isn't the one we currently assume
currentbody = entry["BodyName"]
plugin.AST_current_body.set(entry["BodyName"])
flag = True

if not plugin.AST_near_planet:
# We just came into range of a planet again.
flag = True
if currentbody not in ["", None, "None"]:
if plugin.debug:
if bool(plugin.AST_debug.get()):
logger.debug(plugin.AST_bios_on_planet)
plugin.AST_num_bios_on_planet = plugin.AST_bios_on_planet[
currentbody.replace(plugin.AST_current_system.get(), "")[1:]]
Expand Down Expand Up @@ -183,15 +196,18 @@ def journal_entry(cmdr: str, is_beta: bool, system: str, station: str, entry, st
:param entry: the current Journal entry
:param state: More info about the commander, their ship, and their cargo
"""
# TODO: Move most of this into AST.py class

global plugin

if (int(state["GameVersion"][0]) < 4) and (plugin.AST_in_Legacy is False):
if (int(state["GameVersion"][0]) < 4) or (plugin.AST_in_Legacy is False):
# We're in Legacy, we'll not change the state of anything through journal entries.
plugin.AST_in_Legacy = True
return
else:
plugin.AST_in_Legacy = False

# flag determines if we have to rebuild the ui at the end.
flag = plugin.handle_possible_cmdr_change(cmdr)

if plugin.AST_current_system.get() != system:
Expand Down
1 change: 1 addition & 0 deletions organicinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import math


# Update 14 Prices
u14vistagenomicsprices = {
"Fonticulua Fluctus": 16777215,
Expand Down
Loading

0 comments on commit 526c723

Please sign in to comment.