Initial commit

This commit is contained in:
xtaodada 2023-05-10 22:05:06 +08:00
parent 03f5e21f0b
commit bfa9e45f19
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
7 changed files with 474 additions and 1 deletions

3
.gitignore vendored
View File

@ -157,4 +157,5 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
data/

34
main.py Normal file
View File

@ -0,0 +1,34 @@
import flet as ft
from src.choose import choose_view
from src.data import Page
from src.edit import edit_view
def main(page: Page):
def on_route_change(e: Page):
page.views.clear()
choose_view(page)
if e.route == "/edit":
edit_view(page)
page.update()
def view_pop():
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
page.title = "PropScoreEditor"
page.vertical_alignment = "center"
page.horizontal_alignment = "center"
page.on_route_change = on_route_change
page.on_view_pop = view_pop
page.window_min_width = 800
page.window_width = 800
page.window_height = 600
page.window_min_height = 600
page.go(page.route)
if __name__ == "__main__":
ft.app(target=main)

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
flet

52
src/choose.py Normal file
View File

@ -0,0 +1,52 @@
from flet_core import MainAxisAlignment, CrossAxisAlignment
from src.components import show_snack_bar
import flet as ft
from src.data import Core, genshin_path, Genshin, starrail_path, Starrail, Page
def choose_view(page: Page):
def genshin(_e):
page.core = Core(genshin_path, Genshin())
page.go("/edit")
show_snack_bar(page, "开始编辑原神圣遗物有效词条", ft.colors.GREEN)
def starrail(_e):
page.core = Core(starrail_path, Starrail())
page.go("/edit")
show_snack_bar(page, "开始编辑崩坏:星穹铁道遗器有效词条", ft.colors.GREEN)
# View
page.views.append(
ft.View(
"/",
[
ft.Column(
[
ft.Container(
content=ft.Text(
"PropScoreEditor",
size=50,
),
),
ft.FilledButton(
"Genshin",
icon=ft.icons.LOGIN,
on_click=genshin,
),
ft.FilledButton(
"Starrail",
icon=ft.icons.LOGIN,
on_click=starrail,
),
],
alignment=MainAxisAlignment.CENTER,
)
],
horizontal_alignment=CrossAxisAlignment.CENTER,
vertical_alignment=MainAxisAlignment.CENTER,
)
)

11
src/components.py Normal file
View File

@ -0,0 +1,11 @@
import flet as ft
def show_snack_bar(page, text, color, selectable=False):
return page.show_snack_bar(
ft.SnackBar(
open=True,
content=ft.Text(text, selectable=selectable),
bgcolor=color,
)
)

203
src/data.py Normal file
View File

@ -0,0 +1,203 @@
import json
import flet as ft
from pathlib import Path
from typing import List, Dict, Optional
data_path = Path("data")
data_path.mkdir(exist_ok=True)
genshin_path = data_path / "genshin.json"
starrail_path = data_path / "starrail.json"
class Base:
character: List[str]
type: List[str]
class Genshin(Base):
character = [
'旅行者',
'神里绫华',
'丽莎',
'芭芭拉',
'凯亚',
'迪卢克',
'雷泽',
'安柏',
'温迪',
'香菱',
'北斗',
'行秋',
'',
'凝光',
'可莉',
'钟离',
'菲谢尔',
'班尼特',
'达达利亚',
'诺艾尔',
'七七',
'重云',
'甘雨',
'阿贝多',
'迪奥娜',
'莫娜',
'刻晴',
'砂糖',
'辛焱',
'罗莎莉亚',
'胡桃',
'枫原万叶',
'烟绯',
'宵宫',
'托马',
'优菈',
'雷电将军',
'早柚',
'珊瑚宫心海',
'五郎',
'九条裟罗',
'荒泷一斗',
'八重神子',
'鹿野院平藏',
'夜兰',
'埃洛伊',
'申鹤',
'云堇',
'久岐忍',
'神里绫人',
'柯莱',
'多莉',
'提纳里',
'妮露',
'赛诺',
'坎蒂丝',
'纳西妲',
'莱依拉',
'流浪者',
'珐露珊',
'瑶瑶',
'艾尔海森',
'迪希雅',
'米卡',
'卡维',
'白术',
]
type = [
'基础血量',
'基础攻击力',
'基础防御力',
'攻击力',
'攻击力百分比',
'生命值',
'生命值百分比',
'防御力',
'防御力百分比',
'元素精通',
'暴击率',
'暴击伤害',
'元素充能效率',
'火元素抗性',
'雷元素抗性',
'冰元素抗性',
'水元素抗性',
'风元素抗性',
'岩元素抗性',
'草元素抗性',
'火元素伤害加成',
'雷元素伤害加成',
'冰元素伤害加成',
'水元素伤害加成',
'风元素伤害加成',
'岩元素伤害加成',
'草元素伤害加成',
'物理伤害加成',
'治疗加成',
]
class Starrail(Base):
character = [
'三月七',
'丹恒',
'姬子',
'瓦尔特',
'卡芙卡',
'银狼',
'阿兰',
'艾丝妲',
'黑塔',
'布洛妮娅',
'希儿',
'希露瓦',
'杰帕德',
'娜塔莎',
'佩拉',
'克拉拉',
'桑博',
'虎克',
'青雀',
'停云',
'罗刹',
'景元',
'素裳',
'彦卿',
'白露',
]
type = [
"攻击力百分比",
"攻击力",
"击破特攻",
"暴击率百分比",
"暴击伤害百分比",
"防御力百分比",
"防御力",
"火属性伤害提高百分比",
"生命值百分比",
"生命值",
"治疗量加成百分比",
"冰属性伤害提高百分比",
"虚数属性伤害提高百分比",
"物理属性伤害提高百分比",
"量子属性伤害提高百分比",
"速度",
"能量恢复效率百分比",
"效果命中百分比",
"效果抵抗百分比",
"雷属性伤害提高百分比",
"风属性伤害提高百分比",
]
class Core:
def __init__(self, path: Path, model: Base):
self.path = path
self.model = model
self.data: Dict[str, List[str]] = {}
self.get_data_from_file()
def get_data_from_file(self):
if self.path.exists():
with open(self.path, "r", encoding="utf-8") as f:
self.data = json.load(f)
def save_data_to_file(self):
with open(self.path, "w", encoding="utf-8") as f:
json.dump(self.data, f, ensure_ascii=False, indent=4)
def get_value(self, ch_name: str, type_name: str) -> bool:
return type_name in self.data.get(ch_name, [])
def change_value(self, ch_name: str, type_name: List[str]):
if len(type_name):
self.data[ch_name] = type_name
else:
if ch_name in self.data:
del self.data[ch_name]
self.save_data_to_file()
class Page(ft.Page):
core: Core
current_name: Optional[str] = None

171
src/edit.py Normal file
View File

@ -0,0 +1,171 @@
from flet_core import MainAxisAlignment
from src.components import show_snack_bar
import flet as ft
from src.data import Page
def edit_view(page: Page):
page.current_name = ""
name_list = ft.ListView(
width=230,
)
prop_list = ft.ListView(
expand=True,
)
top_title = ft.Ref[ft.Text]()
def update_top_title(title: str):
"""更新当前页面标题"""
top_title.current.value = title
page.update()
def back_choose(_):
page.go("/")
page.update()
def choose_character(e=None):
if e is not None:
ch_name = e.control.data[0]
page.current_name = ch_name
else:
ch_name = page.current_name
# 获取课程任务列表
page.update()
update_top_title(ch_name)
prop_list.controls.clear()
for i in page.core.model.type:
prop_list.controls.append(
ft.Checkbox(
label=i,
value=page.core.get_value(ch_name, i),
disabled=False,
data=i,
)
)
page.update()
for index, name in enumerate(page.core.model.character):
name_list.controls.append(
ft.TextButton(
text=name,
tooltip=name,
style=ft.ButtonStyle(
shape={
"hovered": ft.RoundedRectangleBorder(),
"": ft.RoundedRectangleBorder(),
}
),
data=(
name,
),
on_click=choose_character,
disabled=False,
),
)
def save(_):
choose_results = list(
filter(
lambda x: x is not None,
map(
lambda x: x.data if x.value else None,
prop_list.controls.copy(),
),
)
)
if len(choose_results) == 0:
show_snack_bar(page, "已清空有效词条〜", ft.colors.ERROR)
def close_alert(_):
success_dialog.open = False
top_title.current.value = ""
choose_character()
page.update()
page.core.change_value(page.current_name, choose_results)
success_dialog = ft.AlertDialog(
modal=True,
title=ft.Text("保存成功"),
content=ft.Text("保存成功"),
actions=[
ft.TextButton("", on_click=close_alert),
],
actions_alignment=MainAxisAlignment.END,
)
page.dialog = success_dialog
success_dialog.open = True
page.update()
def select_all(_):
prop_list_controls = prop_list.controls.copy()
have_selection_some = len(
list(filter(lambda prop_: prop_.value, prop_list_controls))
) < len(prop_list_controls)
if have_selection_some:
for prop in prop_list_controls:
prop.value = True
else:
for i in prop_list_controls:
i.value = not i.value if i.disabled is False else i.value
page.update()
page.views.append(
ft.View(
"/edit",
[
ft.Stack(
[
ft.Container(
content=ft.Row(
[
ft.Text(
ref=top_title,
value="请选择需要编辑的角色",
size=30,
),
ft.Row(
[
ft.ElevatedButton(
"返回",
icon=ft.icons.ARROW_BACK,
on_click=back_choose,
),
ft.ElevatedButton(
"全选",
icon=ft.icons.ALL_INBOX,
on_click=select_all,
),
ft.ElevatedButton(
"保存",
icon=ft.icons.DONE,
on_click=save,
),
],
alignment=MainAxisAlignment.CENTER,
spacing=50,
),
],
alignment=MainAxisAlignment.SPACE_BETWEEN,
),
padding=10,
),
]
),
ft.Divider(
height=1,
),
ft.Row(
[name_list, ft.VerticalDivider(width=1), prop_list],
expand=True,
spacing=0,
),
],
padding=0,
spacing=0,
)
)