mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 08:49:24 +08:00
Fix: save global to a single file for cross-module use
This commit is contained in:
11
alas.py
11
alas.py
@@ -14,9 +14,7 @@ from module.exception import *
|
||||
from module.logger import logger
|
||||
from module.notify import handle_notify
|
||||
from module.gg_handler.gg_handler import GGHandler
|
||||
|
||||
g_current_task: str = ""
|
||||
g_config: AzurLaneConfig = None
|
||||
import gl
|
||||
|
||||
|
||||
class AzurLaneAutoScript:
|
||||
@@ -547,9 +545,7 @@ class AzurLaneAutoScript:
|
||||
exit(1)
|
||||
|
||||
def loop(self):
|
||||
global g_config
|
||||
if g_config is not None:
|
||||
g_config = self.config
|
||||
gl.gl_set("g_config", self.config)
|
||||
|
||||
self.gg_check()
|
||||
logger.set_file_logger(self.config_name)
|
||||
@@ -580,8 +576,7 @@ class AzurLaneAutoScript:
|
||||
# Init device and change server
|
||||
_ = self.device
|
||||
|
||||
global g_current_task
|
||||
g_current_task = task
|
||||
gl.gl_set("g_current_task", task)
|
||||
|
||||
# Skip first restart
|
||||
if task == 'Restart':
|
||||
|
||||
19
gl.py
Normal file
19
gl.py
Normal file
@@ -0,0 +1,19 @@
|
||||
g_current_task = ""
|
||||
g_config = None
|
||||
|
||||
|
||||
def gl_init():
|
||||
...
|
||||
|
||||
|
||||
def gl_set(k, v):
|
||||
globals()[k] = v
|
||||
|
||||
|
||||
def gl_get(k, d=None):
|
||||
try:
|
||||
return globals()[k]
|
||||
except KeyError:
|
||||
return d
|
||||
|
||||
return None
|
||||
@@ -10,6 +10,7 @@ from module.ui.assets import BACK_ARROW
|
||||
from module.ui.navbar import Navbar
|
||||
from module.ui.switch import Switch
|
||||
from module.equipment.assets_override import equip_assets_override
|
||||
import gl
|
||||
|
||||
equipping_filter = Switch('Equiping_filter')
|
||||
equipping_filter.add_status('on', check_button=EQUIPPING_ON)
|
||||
@@ -545,7 +546,7 @@ class EquipmentNew(StorageHandler):
|
||||
self.equipment_has_take_on = True
|
||||
|
||||
|
||||
class Equipment(EquipmentOld if globals().get("g_current_task", "") == "GemsFarming" else EquipmentNew):
|
||||
class Equipment(EquipmentOld if gl.gl_get("g_current_task", "") == "GemsFarming" else EquipmentNew):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if isinstance(self, EquipmentOld):
|
||||
logger.info("use EquipmentOld")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import gl
|
||||
from module.base.button import ButtonGrid
|
||||
from module.base.decorator import Config
|
||||
from module.base.utils import *
|
||||
@@ -314,7 +315,7 @@ class EquipmentChangeNew(Equipment):
|
||||
return
|
||||
|
||||
|
||||
class EquipmentChange(EquipmentChangeOld if globals().get("g_current_task", "") == "GemsFarming" else EquipmentChangeNew):
|
||||
class EquipmentChange(EquipmentChangeOld if gl.gl_get("g_current_task", "") == "GemsFarming" else EquipmentChangeNew):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if isinstance(self, EquipmentChangeOld):
|
||||
logger.info("use EquipmentChangeOld")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import gl
|
||||
from module.equipment.assets import *
|
||||
from module.equipment.equipment import Equipment
|
||||
from module.equipment.equipment_change import EquipmentChange
|
||||
@@ -78,7 +79,7 @@ class FleetEquipmentNew(EquipmentChange):
|
||||
self.ui_back(FLEET_CHECK)
|
||||
|
||||
|
||||
class FleetEquipment(DailyEquipment if globals().get("g_current_task", "") == "GemsFarming" else FleetEquipmentNew):
|
||||
class FleetEquipment(DailyEquipment if gl.gl_get("g_current_task", "") == "GemsFarming" else FleetEquipmentNew):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if isinstance(self, DailyEquipment):
|
||||
logger.info("use DailyEquipment")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import gl
|
||||
from module.base.timer import Timer
|
||||
from module.combat.assets import BATTLE_PREPARATION
|
||||
from module.equipment.equipment import Equipment
|
||||
@@ -104,7 +105,7 @@ class ExerciseEquipmentNew(EquipmentChange):
|
||||
self._inactive_edit()
|
||||
|
||||
|
||||
class ExerciseEquipment(ExerciseEquipmentOld if globals().get("g_current_task", "") == "GemsFarming" else ExerciseEquipmentNew):
|
||||
class ExerciseEquipment(ExerciseEquipmentOld if gl.gl_get("g_current_task", "") == "GemsFarming" else ExerciseEquipmentNew):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if isinstance(self, ExerciseEquipmentOld):
|
||||
logger.info("use ExerciseEquipmentOld")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import gl
|
||||
from module.equipment.equipment import Equipment
|
||||
from module.equipment.equipment_change import EquipmentChange
|
||||
from module.hard.assets import *
|
||||
@@ -51,7 +52,7 @@ class HardEquipmentNew(EquipmentChange):
|
||||
return True
|
||||
|
||||
|
||||
class HardEquipment(HardEquipmentOld if globals().get("g_current_task", "") == "GemsFarming" else HardEquipmentNew):
|
||||
class HardEquipment(HardEquipmentOld if gl.gl_get("g_current_task", "") == "GemsFarming" else HardEquipmentNew):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if isinstance(self, HardEquipmentOld):
|
||||
logger.info("use HardEquipmentOld")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import gl
|
||||
from module.base.button import ButtonGrid
|
||||
from module.base.decorator import cached_property
|
||||
from module.base.timer import Timer
|
||||
@@ -394,8 +395,8 @@ class DockNew(UI):
|
||||
|
||||
|
||||
def redirect_inherit_to_old() -> bool:
|
||||
current_task = globals().get("g_current_task", "")
|
||||
current_config = globals().get("g_config", None)
|
||||
current_task = gl.gl_get("g_current_task", "")
|
||||
current_config = gl.gl_get("g_config", None)
|
||||
|
||||
if current_task == "GemsFarming":
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user