Skip to content

Commit

Permalink
Merge pull request #17 from spaceskynet/main
Browse files Browse the repository at this point in the history
自动拉取整合包的指定 Commit,并处理需要翻译的硬编码
  • Loading branch information
spaceskynet authored Feb 28, 2023
2 parents 527dfd7 + b3fb307 commit 9a2cd43
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 2,747 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/manual-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ on:
# 手动触发事件
workflow_dispatch:
inputs:
tags:
release_tag:
description: 'Release Tag'
commit:
description: 'Full SHA of Special Commit'

jobs:
build:
Expand All @@ -19,15 +21,20 @@ jobs:
with:
python-version: '3.10'

- name: Clone Official Modpack Repo (With Special Commit)
run: |
git clone https://github.com/Laskyyy/Create-Astral.git
cd Create-Astral && git reset --hard ${{ github.event.inputs.commit }} && cd ..
- name: Make Release
run: python make_release.py

- name: Create GitHub release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ github.event.inputs.tags }}
title: ${{ github.event.inputs.tags }}
automatic_release_tag: ${{ github.event.inputs.release_tag }}
title: ${{ github.event.inputs.release_tag }}
prerelease: false
files: |
release/release.zip
Expand Down
143 changes: 143 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,144 @@
release/
Create-Astral/

# PYTHON

# pipenv
Pipfile
Pipfile.lock

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Ubuntu
.Trash-*/

# binarys or dumps
*.bin
118 changes: 118 additions & 0 deletions handle_hard_coding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
import json, glob
import os, shutil

def copy_tree(src, dst, symlinks=False, ignore=None):
if os.path.isfile(src):
if not os.path.exists(os.path.dirname(dst)):
os.makedirs(os.path.dirname(dst))
shutil.copy2(src, dst)
return

if not os.path.exists(dst):
os.makedirs(dst)

for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
copy_tree(s, d, symlinks, ignore)
else:
if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
shutil.copy2(s, d)

def handle_custom_machinery(work_dir):
machines_path = os.path.join(work_dir, "global_packs/required_data/zLaky Core/data/createastral/machines")

# 键名为自定义机器的英文原文,值为翻译
with open(os.path.join('v2.0', 'hard_coding', 'custom_machinery.json'), 'r', encoding='utf-8') as fp:
machineries = json.load(fp)

json_files = glob.glob(os.path.join(machines_path, "*.json"))

for json_file in json_files:
with open(json_file, 'r', encoding="utf-8") as fp:
content = fp.read()
for key, value in machineries.items():
content = content.replace(f'"{key}"', f'"{value}"')
with open(json_file, 'w', encoding="utf-8") as fp:
fp.write(content)

def find_the_matched_bracket(text, left_index):
left_brackets = r"[{"
right_brackets = r"]}"
if text[left_index] not in left_brackets: return -1
stack = []

for index in range(left_index, len(text)):
if text[index] in left_brackets:
stack.append(index)
elif text[index] in right_brackets:
if len(stack) == 0:
return -1
else:
stack.pop()
if len(stack) == 0:
return index
return -1

def handle_ftb_quests(work_dir):
last_chapter = os.path.join(work_dir, "config/ftbquests/quests/chapters/6_raow.snbt")

with open(last_chapter, 'r', encoding="utf-8") as f:
content = f.read()
feature_str = 'quests: ['
left_index = content.find(feature_str) + len(feature_str) - 1
assert(content[left_index] == '[')
right_index = find_the_matched_bracket(content, left_index)
assert(right_index != -1 and content[right_index] == ']')
insert_index = content.rfind('\n', left_index, right_index) + 1

with open(os.path.join('v2.0', 'hard_coding', 'trans_acknowledgements.snbt'), 'r', encoding='utf-8') as fp:
acknowledgements = fp.read()

insert_content = acknowledgements.replace('\n', "\n\t\t")
content = content[:insert_index] + f"\t\t{insert_content}\n" + content[insert_index:]

with open(last_chapter, 'w', encoding="utf-8") as f:
f.write(content)

def handle_startup_js(work_dir):
startup_js_path = os.path.join(work_dir, "kubejs/startup_scripts/startup.js")

with open(os.path.join('v2.0', 'hard_coding', 'startup.json'), 'r', encoding='utf-8') as fp:
trans_dict = json.load(fp)

with open(startup_js_path, 'r', encoding="utf-8") as f:
content = f.read()

for key, value in trans_dict.items():
content = content.replace(f"Text.of('{key}", f"Text.of('{value}")
content = content.replace(f'Text.of("{key}', f'Text.of("{value}')

with open(startup_js_path, 'w', encoding="utf-8") as f:
f.write(content)

def start_handle_hard_coding(official_dir, release_dir):

if not os.path.isdir(official_dir):
print("[ERROR] Please pull the repository of the official integration package to the same level directory first!")
os._exit(-1)

required_paths = [
"kubejs/startup_scripts/startup.js",
"config/ftbquests/quests/chapters/6_raow.snbt",
"global_packs/required_data/zLaky Core/data/createastral/machines",
]

for required_path in required_paths:
src = os.path.join(official_dir, required_path)
dict = os.path.join(release_dir, required_path)
copy_tree(src, dict)

handle_startup_js(release_dir)
handle_custom_machinery(release_dir)
handle_ftb_quests(release_dir)

if __name__ == "__main__":
start_handle_hard_coding("release")
22 changes: 6 additions & 16 deletions make_release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import zipfile
import glob, os, shutil
from handle_hard_coding import start_handle_hard_coding

def copy_tree(src, dst, symlinks=False, ignore=None):
if not os.path.exists(dst):
Expand Down Expand Up @@ -39,12 +40,7 @@ def add_objs(files, zip_fp, base_dir = '.'):
resourcepack_path = os.path.join(src_dir, 'resourcepacks', resourcepack_name)

# Required directories
required_dirs = []
required_dirs.append('config')
required_dirs.append('kubejs')
required_dirs.append('resourcepacks')
required_dirs.append('global_packs')

required_dirs = ['resourcepacks', 'config', 'kubejs', 'global_packs']

# Make Dirs
if not os.path.isdir(release_dir): os.makedirs(release_dir)
Expand All @@ -53,16 +49,10 @@ def add_objs(files, zip_fp, base_dir = '.'):
if not os.path.isdir(required_path):
os.makedirs(required_path)

# KubeJS, quests, machine startup configs

# Directories to copy
copy_dirs = []
copy_dirs.append('config')
copy_dirs.append('kubejs')
copy_dirs.append('global_packs')

for copy_dir in copy_dirs:
copy_tree(os.path.join(src_dir, copy_dir), os.path.join(release_dir, copy_dir))
# Handle Hard Coding and Copy to Release Dir
## KubeJS startup.js, FTB Quests, Custom Machinery
official_dir = os.path.join(work_dir, "Create-Astral")
start_handle_hard_coding(official_dir, release_dir)

# Resourcepack
os.chdir(resourcepack_path)
Expand Down
Loading

0 comments on commit 9a2cd43

Please sign in to comment.