Skip to content

Commit

Permalink
启动mower时直接加载排班表;将plan移至config中;修复排班表导出
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Jul 27, 2024
1 parent a362bde commit 3a6bbf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
9 changes: 6 additions & 3 deletions arknights_mower/utils/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ def load_conf():
load_conf()


def load_plan() -> PlanModel:
def load_plan():
global plan
with open(conf.planFile, "r", encoding="utf-8") as f:
plan = PlanModel(**json.load(f))
return plan


def save_plan(plan: PlanModel):
def save_plan():
with open(conf.planFile, "w", encoding="utf-8") as f:
json.dump(plan.model_dump(exclude_none=True), f, ensure_ascii=False, indent=2)


plan: PlanModel
load_plan()

stop_mower = Event()

# 日志
Expand Down
32 changes: 13 additions & 19 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pathlib
import sys
import time
from copy import deepcopy
from functools import wraps
from threading import Thread

Expand All @@ -30,8 +29,6 @@
sock = Sock(app)
CORS(app)

plan = {}

mower_thread = None
log_lines = []
ws_connections = []
Expand Down Expand Up @@ -93,19 +90,17 @@ def load_config():
@app.route("/plan", methods=["GET", "POST"])
@require_token
def load_plan_from_json():
global plan

if request.method == "GET":
try:
plan = config.load_plan()
config.load_plan()
except Exception as e:
logger.exception(f"plan.json路径错误{e},重置为plan.json")
logger.exception(f"排班表文件路径错误{e},重置为plan.json")
config.conf.planFile = "./plan.json"
plan = config.load_plan()
return plan.model_dump(exclude_none=True)
config.load_plan()
return config.plan.model_dump(exclude_none=True)
else:
plan = config.PlanModel(**request.json)
config.save_plan(plan)
config.plan = config.PlanModel(**request.json)
config.save_plan()
return f"New plan saved at {config.conf.planFile}"


Expand Down Expand Up @@ -149,7 +144,6 @@ def start():
tmp_dir.mkdir(exist_ok=True)

config.stop_mower.clear()
config.plan = deepcopy(plan)
config.operators = {}

from arknights_mower.__main__ import main
Expand Down Expand Up @@ -234,11 +228,10 @@ def import_from_image():
from arknights_mower.utils import qrcode

img = Image.open(img_path)
global plan
plan = qrcode.decode(img)
if plan:
plan = config.PlanModel(**plan)
config.save_plan(plan)
data = qrcode.decode(img)
if data:
config.plan = config.PlanModel(**data)
config.save_plan()
return "排班已加载"
return "排班表导入失败!"

Expand All @@ -256,8 +249,9 @@ def save_file_dialog():

upper = Image.open(img)

global plan
img = qrcode.export(plan, upper, config.conf.theme)
img = qrcode.export(
config.plan.model_dump(exclude_none=True), upper, config.conf.theme
)

img_path = conn_send("save")
if img_path == "":
Expand Down

0 comments on commit 3a6bbf3

Please sign in to comment.