feat: support edit gcsim scripts

This commit is contained in:
xtaodada 2023-11-30 21:10:11 +08:00
parent d67912acac
commit 0ab616999b
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
6 changed files with 161 additions and 0 deletions

38
.github/workflows/python.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: python build
on:
push:
branches:
- 'main'
workflow_dispatch: ~
jobs:
Python-Build:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install Dependencies
run: |
python -m pip install -r gcsim/requirements.txt
- name: Check GCSIM scripts
run: |
python gcsim/main.py
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
author_name: github-actions[bot]
author_email: github-actions[bot]@users.noreply.github.com
push: 'origin remote --force'
new_branch: 'remote'
message: ':sparkles: Update gcsim scripts'
add: |
'gcsim.json'

View File

@ -7,6 +7,7 @@ on:
paths-ignore: paths-ignore:
- '**.md' - '**.md'
- '**.json' - '**.json'
- 'gcsim/**'
tags: tags:
- '**' - '**'
workflow_dispatch: ~ workflow_dispatch: ~

1
.gitignore vendored
View File

@ -160,3 +160,4 @@ cython_debug/
.idea/ .idea/
data/ data/
*.exe *.exe
gcsim/temp

77
gcsim/main.py Normal file
View File

@ -0,0 +1,77 @@
import asyncio
import json
import platform
from pathlib import Path
import aiofiles
import re
import gcsim_pypi
data_path = Path("gcsim.json")
gcsim_path = Path("gcsim")
scripts_path = gcsim_path / "scripts"
temp_path = gcsim_path / "temp"
temp_path.mkdir(exist_ok=True)
def _get_gcsim_bin_name() -> str:
if platform.system() == "Windows":
return "gcsim.exe"
bin_name = "gcsim"
if platform.system() == "Darwin":
bin_name += ".darwin"
if platform.machine() == "arm64":
bin_name += ".arm64"
return bin_name
gcsim_pypi_path = Path(gcsim_pypi.__file__).parent
bin_path = gcsim_pypi_path.joinpath("bin").joinpath(_get_gcsim_bin_name())
async def run_gcsim(path: Path) -> bool:
try:
process = await asyncio.create_subprocess_exec(
bin_path,
"-c",
path.absolute().as_posix(),
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
_, stderr = await process.communicate()
err = stderr.decode()
if err:
print(f"{path.name} 解析失败 {err}")
return False
return True
except Exception:
return False
async def modify_script(path: Path):
async with aiofiles.open(path, "r", encoding="utf-8") as f:
content = await f.read()
content = re.sub(r"iteration=\d+", "iteration=1", content)
new_path = temp_path / path.name
async with aiofiles.open(new_path, "w", encoding="utf-8") as f:
await f.write(content)
async def main():
for path in scripts_path.iterdir():
if path.is_file() and path.suffix == ".txt":
await modify_script(path)
allow = []
for path in temp_path.iterdir():
if await run_gcsim(temp_path / path.name):
allow.append(path)
data = {}
for path in allow:
async with aiofiles.open(path, "r", encoding="utf-8") as f:
data[path.stem] = await f.read()
async with aiofiles.open(data_path, "w", encoding="utf-8") as f:
await f.write(json.dumps(data, ensure_ascii=False, indent=4))
if __name__ == "__main__":
asyncio.run(main())

2
gcsim/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
gcsim-pypi>=2.8.2.10
aiofiles

View File

@ -0,0 +1,42 @@
raiden char lvl=90/90 cons=0 talent=9,9,9;
raiden add weapon="engulfinglightning" refine=1 lvl=90/90;
raiden add set="eosf" count=4;
raiden add stats hp=4780 atk=311 er=0.518 electro%=0.466 cr=0.311;
raiden add stats def%=0.124 def=39.36 hp=507.88 hp%=0.0992 atk=33.08 atk%=0.1984 er=0.1102 em=39.64 cr=0.331 cd=0.7944;
xingqiu char lvl=90/90 cons=6 talent=9,9,9;
xingqiu add weapon="pjc" refine=1 lvl=90/90;
xingqiu add set="no" count=4;
xingqiu add stats hp=4780 atk=311 atk%=0.466 hydro%=0.466 cd=0.662 ; #main
xingqiu add stats def%=0.124 def=39.36 hp=507.88 hp%=0.0992 atk=33.08 atk%=0.0992 er=0.4408 em=39.64 cr=0.2979 cd=0.5958;
bennett char lvl=90/90 cons=6 talent=9,9,9;
bennett add weapon="mistsplitterreforged" refine=1 lvl=90/90;
bennett add set="instructor" count=4;
bennett add stats hp=3571 atk=232 em=140.25 pyro%=0.466 cr=0.23325 ; #main
bennett add stats def%=0.124 def=39.36 hp=507.88 hp%=0.0992 atk=33.08 atk%=0.0992 er=0.1102 em=39.64 cr=0.2979 cd=0.4634;
xiangling char lvl=90/90 cons=6 talent=9,9,9;
xiangling add weapon="staffofthescarletsands" refine=1 lvl=90/90;
#xiangling add weapon="staffofthescarletsands" refine=5 lvl=90/90;
xiangling add set="emblemofseveredfate" count=4;
xiangling add stats hp=4780 atk=311 em=187 pyro%=0.466 cd=0.622;
xiangling add stats def%=0.124 def=39.36 hp=507.88 hp%=0.0992 atk=33.08 atk%=0.0992 er=0.6612 em=39.64 cr=0.2317 cd=0.4634;
options swap_delay=12 iteration=1000;
target lvl=100 resist=0.1 hp=100000000 pos=3,0 radius=2;
energy every interval=480,720 amount=1;
set_particle_delay("bennett", 100);
active raiden;
raiden skill;
for let x=0; x<5; x=x+1 {
xingqiu skill, dash, burst, attack;
bennett burst, attack, skill;
xiangling attack, burst, attack, skill, dash;
bennett attack, skill;
raiden attack, burst, attack:4, skill, attack:4, dash, attack:4, dash, attack:5;
bennett skill;
}