Skip to content

Commit

Permalink
[no ci] Prevent downloaded addons from turning into detached git subm…
Browse files Browse the repository at this point in the history
…odules (by deleting the git repository). Remove `--resource-pack-book` as we can infer it automatically.
  • Loading branch information
alcatrazEscapee committed Oct 4, 2024
1 parent 1122681 commit b59b77d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
path: 'tfc'
- name: Build
run: |
python src/main.py --tfc-dir tfc --out-dir build --resource-pack-book --root-dir "${GITHUB_REPOSITORY#*/}" --use-mcmeta --use-addons --copy-existing-versions
python src/main.py --tfc-dir tfc --out-dir build --root-dir "${GITHUB_REPOSITORY#*/}" --use-mcmeta --use-addons --copy-existing-versions
touch build/.nojekyll
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ $ python src/main.py --tfc-dir /path/to/tfc [--debug]
$ cd out
$ python -m http.server 8000

# New versions (1.20) require additional arguments:
$ python src/main.py ... --resource-pack-book --copy-existing-versions
# Include Minecraft data (stored locally in /.cache) and Addons (stored locally in /addons)
$ python src/main.py ... --use-mcmeta --use-addons

# Include the old versions (stored in /assets/versions)
$ python src/main.py ... --copy-existing-versions

# For 'old' local versions
# When generating an old version to commit
Expand Down
6 changes: 3 additions & 3 deletions src/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from i18n import I18n
from components import text_formatter
from loader import Loader
from versions import IS_RESOURCE_PACK

import util
import json
Expand All @@ -17,15 +18,14 @@

class Context:

def __init__(self, tfc_dir: str, output_dir: str, root_dir: str, use_mcmeta: bool, use_addons: bool, debug_i18n: bool, resource_pack: bool):
def __init__(self, tfc_dir: str, output_dir: str, root_dir: str, use_mcmeta: bool, use_addons: bool, debug_i18n: bool):
self.tfc_dir = tfc_dir
self.output_root_dir = output_dir
self.root_dir = root_dir
self.output_dir = output_dir
self.loader: Loader = Loader(tfc_dir, output_dir, use_mcmeta, use_addons)
self.last_context = None
self.debug_i18n = debug_i18n
self.resource_pack = resource_pack

self.categories: Dict[str, Category] = {}
self.entries: Dict[str, Entry] = {}
Expand All @@ -52,7 +52,7 @@ def __init__(self, tfc_dir: str, output_dir: str, root_dir: str, use_mcmeta: boo
self.blocks_failed = 0

def resource_dir(self, path: str) -> str:
return util.path_join(self.tfc_dir, BOOK_DIR % ('assets' if self.resource_pack else 'data'), self.lang, path)
return util.path_join(self.tfc_dir, BOOK_DIR % ('assets' if IS_RESOURCE_PACK else 'data'), self.lang, path)

def with_lang(self, lang: str):
self.lang = lang
Expand Down
11 changes: 7 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def main():
# Version handling
parser.add_argument('--old-version-key', type=str, dest='old_version_key', default=None, help='If present, the key of the old version to generate')
parser.add_argument('--copy-existing-versions', action='store_true', dest='copy_existing_versions', default=False, help='If present, this will copy existing old versions from /assets/versions/ into the root output directory')
parser.add_argument('--resource-pack-book', action='store_true', dest='resource_pack_book', default=False, help='If the book is stored as a resource pack (core content in /assets/) vs. not (core content in /data/)')

# External resources
parser.add_argument('--use-mcmeta', action='store_true', dest='use_mcmeta', help='Download Minecraft and Forge source')
Expand Down Expand Up @@ -86,7 +85,7 @@ def main():

LOG.info('Setting root output dir to "%s"' % root_dir)

context = Context(tfc_dir, out_dir, root_dir, use_mcmeta, use_addons, args.debug_i18n, args.resource_pack_book)
context = Context(tfc_dir, out_dir, root_dir, use_mcmeta, use_addons, args.debug_i18n)

if use_mcmeta:
mcmeta.load_cache()
Expand All @@ -98,6 +97,10 @@ def main():
os.makedirs('addons/%s-%s' % (addon.mod_id, addon.version), exist_ok=True)
subprocess.call('git clone -b %s https://github.com/%s/%s addons/%s-%s' % (addon.version, addon.user, addon.repo, addon.mod_id, addon.version), shell=True)

# This is a hack - we don't want git submodules or sub-repos to be present, but keep the cache around
# So just delete the /.git/ folder
shutil.rmtree('addons/%s-%s/.git' % (addon.mod_id, addon.version), True)

LOG.info('Generating docs...')
LOG.debug('Running with:\n tfc_dir = %s\n out_dir = %s\n langs = %s\n version = %s' % (
tfc_dir, out_dir, versions.LANGUAGES, versions.VERSION
Expand Down Expand Up @@ -130,7 +133,7 @@ def parse_book(context: Context, use_addons: bool):

if use_addons:
for addon in versions.ADDONS:
addon_dir = util.path_join(addon.book_dir(context.resource_pack), context.lang, 'categories')
addon_dir = util.path_join(addon.book_dir(versions.IS_RESOURCE_PACK), context.lang, 'categories')
for category_file in util.walk(addon_dir):
parse_category(context, addon_dir, category_file, is_addon=True)

Expand All @@ -141,7 +144,7 @@ def parse_book(context: Context, use_addons: bool):

if use_addons:
for addon in versions.ADDONS:
addon_dir = util.path_join(addon.book_dir(context.resource_pack), context.lang, 'entries')
addon_dir = util.path_join(addon.book_dir(versions.IS_RESOURCE_PACK), context.lang, 'entries')
for entry_file in util.walk(addon_dir):
parse_entry(context, addon_dir, entry_file)

Expand Down
2 changes: 2 additions & 0 deletions src/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class OldVersion(NamedTuple):

TFC_VERSION = '%s - %s' % (MC_VERSION, VERSION)

IS_RESOURCE_PACK = MC_VERSION != '1.18.2'


if __name__ == '__main__':
print(VERSION)

0 comments on commit b59b77d

Please sign in to comment.