From 275d72f6c84a292e0e0fbe86104c7f1083cd8861 Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 31 Jan 2023 16:23:59 +0800 Subject: [PATCH 1/6] upgrade mgpp to v1.2.0 --- build.gradle | 10 +++++----- build.gradle.kts | 10 +++++----- mod.hjson | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index b2579fb..5cc0c14 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id "io.github.liplum.mgpp" version "1.1.10" + id "io.github.liplum.mgpp" version "1.2.0" } group 'org.example' @@ -23,14 +23,14 @@ dependencies { } mindustry { dependency { - mindustry version: 'v136' - arc version: 'v136.1' + mindustryMirror version: 'v141.2' + arc version: 'v141.3' } client { - official version: 'v136.1' + official version: 'v141.3' } server { - official version: 'v136.1' + official version: 'v141.3' } def name = project.archivesBaseName deploy { diff --git a/build.gradle.kts b/build.gradle.kts index 010726d..4cbffff 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import io.github.liplum.mindustry.* plugins { kotlin("jvm") version "1.7.0" - id("io.github.liplum.mgpp") version "1.1.10" + id("io.github.liplum.mgpp") version "1.2.0" } sourceSets { @@ -28,14 +28,14 @@ dependencies { } mindustry { dependency { - mindustry on "v136" - arc on "v136.1" + mindustry mirror "v141.2" + arc on "v141.3" } client { - mindustry official "v136.1" + mindustry official "v141.3" } server { - mindustry official "v136.1" + mindustry official "v141.3" } deploy { baseName = project.name diff --git a/mod.hjson b/mod.hjson index e384388..2d74c0d 100644 --- a/mod.hjson +++ b/mod.hjson @@ -6,7 +6,7 @@ repo: "%Owner%/%Repository%" subtitle: "" description: "" version: "1.0" -minGameVersion: "136" +minGameVersion: "141" java: true hidden: false dependencies: [] \ No newline at end of file From be4d8399105dec39e9c7668fea6b0455cab94736 Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 31 Jan 2023 17:05:29 +0800 Subject: [PATCH 2/6] better clean up script. --- .github/workflows/CleanUpTemplate.yml | 2 +- .github/workflows/cleanup/README.md | 17 ------- .../workflows/cleanup/{main.py => cleanup.py} | 46 ++++++++++++++----- 3 files changed, 36 insertions(+), 29 deletions(-) delete mode 100644 .github/workflows/cleanup/README.md rename .github/workflows/cleanup/{main.py => cleanup.py} (57%) diff --git a/.github/workflows/CleanUpTemplate.yml b/.github/workflows/CleanUpTemplate.yml index 51ef1f2..b888fa5 100644 --- a/.github/workflows/CleanUpTemplate.yml +++ b/.github/workflows/CleanUpTemplate.yml @@ -18,7 +18,7 @@ jobs: - name: Run Cleanup Script env: FULL_NAME: ${{ github.event.repository.full_name }} - run: python .github/workflows/cleanup/main.py "$FULL_NAME" + run: python .github/workflows/cleanup/cleanup.py "$FULL_NAME" # Commit modified files - name: Commit files diff --git a/.github/workflows/cleanup/README.md b/.github/workflows/cleanup/README.md deleted file mode 100644 index 1ab3fb5..0000000 --- a/.github/workflows/cleanup/README.md +++ /dev/null @@ -1,17 +0,0 @@ -
- -# %Repository% - -![Mod Icon](icon.png) - -
- -## Modding ToDo List: - -- [x] Create a new Mindustry Java mod project. -- [ ] Edit the [mod.hjson](mod.hjson) for your mod. -- [ ] Create your first content, a block, an item or anything you want. -- [ ] Put sprites and bundles into [assets](assets) directory. -- [ ] Check the Mindustry's sources with your IDE or on its [repository](https://github.com/Anuken/Mindustry). -- [ ] Make a beautiful [mod icon](icon.png) to replace the placeholder. -- [ ] Push a commit with any message containing `[release]` to generate a release draft on [GitHub](https://github.com/%Owner%/%Repository%/releases). diff --git a/.github/workflows/cleanup/main.py b/.github/workflows/cleanup/cleanup.py similarity index 57% rename from .github/workflows/cleanup/main.py rename to .github/workflows/cleanup/cleanup.py index 204ad05..3017b80 100644 --- a/.github/workflows/cleanup/main.py +++ b/.github/workflows/cleanup/cleanup.py @@ -7,16 +7,34 @@ full_name = args[1] owner, repo = full_name.split('/') package_name = owner.replace("-", "") -main_class_source_template = """ -package %PackageName%; +main_class_template = """package %PackageName%; import mindustry.mod.*; -public class %MainClassName% extends Mod{ +public class %MainClassName% extends Mod { + } """ +readme_template = """
+# %Repository% -def transform_repo_to_class(repo: str) -> str: +![Mod Icon](icon.png) + +
+ +## Modding ToDo List: + +- [x] Create a new Mindustry Java mod project. +- [ ] Edit the [mod.hjson](mod.hjson) for your mod. +- [ ] Create your first content, a block, an item or anything you want. +- [ ] Put sprites and bundles into [assets](assets) directory. +- [ ] Check the Mindustry's sources with your IDE or on its [repository](https://github.com/Anuken/Mindustry). +- [ ] Make a beautiful [mod icon](icon.png) to replace the placeholder. +- [ ] Push a commit with any message containing `[release]` to generate a release draft on [GitHub](https://github.com/%Owner%/%Repository%/releases). +""" + + +def transform_repo_to_class() -> str: with io.StringIO() as b: hyphen = False for i, c in enumerate(repo): @@ -37,15 +55,18 @@ def transform_repo_to_class(repo: str) -> str: return name -main_class_name = transform_repo_to_class(repo) + "Mod" +main_class_name = transform_repo_to_class() + "Mod" main_class_qualified_name = f"{package_name}.{main_class_name}" def replace_mod_meta(): - with open("mod.hjson", mode='r') as mod_meta: - text = mod_meta.read() - text = text.replace("%Repository%", repo).replace("%Owner%", owner).replace("%MainClassQualifiedName%", - main_class_qualified_name) + text = readme_template.replace( + "%Repository%", repo + ).replace( + "%Owner%", owner + ).replace( + "%MainClassQualifiedName%", main_class_qualified_name + ) with open("mod.hjson", mode='w') as mod_meta: mod_meta.write(text) @@ -53,8 +74,11 @@ def replace_mod_meta(): def generate_main_class(): os.makedirs(f"src/{package_name}", exist_ok=True) with open(f"src/{package_name}/{main_class_name}.java", mode='w+') as main_clz: - content = main_class_source_template.replace("%PackageName%", package_name).replace("%MainClassName%", - main_class_name) + content = main_class_template.replace( + "%PackageName%", package_name + ).replace( + "%MainClassName%", main_class_name + ) main_clz.write(content) From 54f65df9afdf38a583247e3204c77e401b20d127 Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 31 Jan 2023 17:08:15 +0800 Subject: [PATCH 3/6] remove unused property `kotlinVersion` in gradle.properties --- build.gradle.kts | 2 +- gradle.properties | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4cbffff..362b14f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import io.github.liplum.mindustry.* plugins { - kotlin("jvm") version "1.7.0" + kotlin("jvm") version "1.8.0" id("io.github.liplum.mgpp") version "1.2.0" } diff --git a/gradle.properties b/gradle.properties index 6d123ed..e69de29 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +0,0 @@ -kotlinVersion=1.6.10 From 69cbb8ea4d68dc7438ccb839940db88e45a0f36b Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 31 Jan 2023 17:39:01 +0800 Subject: [PATCH 4/6] manually trigger release workflow. --- .github/workflows/PullRequest.yml | 9 ++++++--- .github/workflows/Push.yml | 23 +--------------------- .github/workflows/ReleaseDraft.yaml | 30 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/ReleaseDraft.yaml diff --git a/.github/workflows/PullRequest.yml b/.github/workflows/PullRequest.yml index 207f18b..d50aa68 100644 --- a/.github/workflows/PullRequest.yml +++ b/.github/workflows/PullRequest.yml @@ -1,26 +1,29 @@ name: Pull Request Testing - -on: [ pull_request ] +on: pull_request jobs: - buildJar: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Set up PATH run: | echo "${ANDROID_HOME}/build-tools/30.0.1" >> $GITHUB_PATH + - name: Set up JDK 17 uses: actions/setup-java@v2 with: java-version: '17' distribution: 'temurin' cache: 'gradle' + - name: Build mod jar run: | chmod +x gradlew ./gradlew deploy + - name: Upload Mod Jar uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/Push.yml b/.github/workflows/Push.yml index 30d946c..179b674 100644 --- a/.github/workflows/Push.yml +++ b/.github/workflows/Push.yml @@ -17,9 +17,6 @@ jobs: distribution: 'temurin' cache: 'gradle' - - name: Get short commit hash - run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: Build Mod Jar run: | chmod +x gradlew @@ -28,22 +25,4 @@ jobs: - uses: actions/upload-artifact@v2 with: name: Mod-Unzip-This - path: build/tmp/deploy/*.jar - - release-draft: - needs: build - if: ${{ contains(github.event.head_commit.message,'[release]') }} - runs-on: ubuntu-latest - env: - GH_REPO: ${{ github.repository }} - steps: - - uses: actions/checkout@v2 - - - uses: actions/download-artifact@v2 - with: - name: Mod-Unzip-This - path: out - - name: Create Release Draft - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh release create new --draft out/*.jar \ No newline at end of file + path: build/tmp/deploy/*.jar \ No newline at end of file diff --git a/.github/workflows/ReleaseDraft.yaml b/.github/workflows/ReleaseDraft.yaml new file mode 100644 index 0000000..24fbcda --- /dev/null +++ b/.github/workflows/ReleaseDraft.yaml @@ -0,0 +1,30 @@ +name: Creat Release Draft +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + env: + GH_REPO: ${{ github.repository }} + steps: + - uses: actions/checkout@v2 + + - name: Set Android SDK tools + run: echo "$ANDROID_HOME/build-tools/30.0.3" >> $GITHUB_PATH + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' + + - name: Build Mod Jar + run: | + chmod +x gradlew + ./gradlew deploy + + - name: Create Release Draft + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release create new --draft build/tmp/deploy/*.jar \ No newline at end of file From 93c755b349e3e9d880030d7d9723e2ab1f868902 Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 31 Jan 2023 22:00:38 +0800 Subject: [PATCH 5/6] moved cleanup.py --- .github/workflows/CleanUpTemplate.yml | 4 ++-- .../cleanup/cleanup.py => cleanup.py | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) rename .github/workflows/cleanup/cleanup.py => cleanup.py (83%) diff --git a/.github/workflows/CleanUpTemplate.yml b/.github/workflows/CleanUpTemplate.yml index b888fa5..ef729f4 100644 --- a/.github/workflows/CleanUpTemplate.yml +++ b/.github/workflows/CleanUpTemplate.yml @@ -7,7 +7,7 @@ jobs: template-cleanup: name: Template Cleanup runs-on: ubuntu-latest - if: github.event.repository.full_name != 'liplum/MdtModTemplate' + if: github.event.repository.full_name != 'liplum/MindustryModTemplate' steps: - name: Fetch Sources uses: actions/checkout@v2.4.0 @@ -18,7 +18,7 @@ jobs: - name: Run Cleanup Script env: FULL_NAME: ${{ github.event.repository.full_name }} - run: python .github/workflows/cleanup/cleanup.py "$FULL_NAME" + run: python cleanup.py "$FULL_NAME" # Commit modified files - name: Commit files diff --git a/.github/workflows/cleanup/cleanup.py b/cleanup.py similarity index 83% rename from .github/workflows/cleanup/cleanup.py rename to cleanup.py index 3017b80..9e32fbc 100644 --- a/.github/workflows/cleanup/cleanup.py +++ b/cleanup.py @@ -1,7 +1,6 @@ import sys import os import io -import shutil args = sys.argv full_name = args[1] @@ -26,15 +25,15 @@ - [x] Create a new Mindustry Java mod project. - [ ] Edit the [mod.hjson](mod.hjson) for your mod. -- [ ] Create your first content, a block, an item or anything you want. +- [ ] Create your first content: a block or an item. - [ ] Put sprites and bundles into [assets](assets) directory. - [ ] Check the Mindustry's sources with your IDE or on its [repository](https://github.com/Anuken/Mindustry). -- [ ] Make a beautiful [mod icon](icon.png) to replace the placeholder. +- [ ] Make a nice [icon](icon.png) to replace the placeholder. - [ ] Push a commit with any message containing `[release]` to generate a release draft on [GitHub](https://github.com/%Owner%/%Repository%/releases). """ -def transform_repo_to_class() -> str: +def transform_repo_to_class_name() -> str: with io.StringIO() as b: hyphen = False for i, c in enumerate(repo): @@ -55,12 +54,14 @@ def transform_repo_to_class() -> str: return name -main_class_name = transform_repo_to_class() + "Mod" +main_class_name = transform_repo_to_class_name() + "Mod" main_class_qualified_name = f"{package_name}.{main_class_name}" def replace_mod_meta(): - text = readme_template.replace( + with open("mod.hjson", mode='r') as mod_meta: + text = mod_meta.read() + text = text.replace( "%Repository%", repo ).replace( "%Owner%", owner @@ -83,9 +84,11 @@ def generate_main_class(): def replace_readme(): - with open(".github/workflows/cleanup/README.md", mode='r') as readme: - text = readme.read() - text = text.replace("%Repository%", repo).replace("%Owner%", owner) + text = readme_template.replace( + "%Repository%", repo + ).replace( + "%Owner%", owner + ) with open("README.md", mode='w') as readme: readme.write(text) @@ -93,7 +96,7 @@ def replace_readme(): def delete_self(): os.remove(".github/workflows/CleanUpTemplate.yml") os.remove("LICENSE") - shutil.rmtree(".github/workflows/cleanup") + os.remove("cleanup.py") def main(): From 963fc79324d94acacbce92dcddf18717ad833216 Mon Sep 17 00:00:00 2001 From: Liplum Date: Wed, 1 Feb 2023 00:25:17 +0800 Subject: [PATCH 6/6] detailed use guide. --- .github/workflows/CleanUpTemplate.yml | 7 +++- README.md | 58 ++++++++++++++++++++++----- cleanup.py | 12 ++++-- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/.github/workflows/CleanUpTemplate.yml b/.github/workflows/CleanUpTemplate.yml index ef729f4..3d30894 100644 --- a/.github/workflows/CleanUpTemplate.yml +++ b/.github/workflows/CleanUpTemplate.yml @@ -18,7 +18,12 @@ jobs: - name: Run Cleanup Script env: FULL_NAME: ${{ github.event.repository.full_name }} - run: python cleanup.py "$FULL_NAME" + run: | + if [ -f cleanup.py ]; then + python cleanup.py "$FULL_NAME" + else + rm .github/workflows/CleanUpTemplate.yml + fi # Commit modified files - name: Commit files diff --git a/README.md b/README.md index 2f81789..a7aec76 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Mindustry Mod Template -This template utilized [MGPP gradle plugin](https://plumygame.github.io/mgpp/) to build and debug a mod. +#### *[MGPP](https://plumygames.github.io/mgpp/) helps you to build and debug a Java mod.* @@ -10,31 +10,67 @@ ___ It's recommended to `watch` this project, which will notify you anything updated of the template. -## How to use this template +## How To Use This Template -Hit the [green button](https://github.com/liplum/mdtmodtemplate/generate) `Use this template` above, not the `fork`, and enter your repository name, always the same as a mod name. +Above all, please take a look at the documentation of [MGPP](https://plumygames.github.io/mgpp/). +It'll help you to build your mod, run the Mindustry and debug your mod in game! -After the GitHub actions has done the clean-up job, you can clone your repository. +### GitHub Automation -There will be a generated `main class` and `mod.hjson`. +- Step 1: Hit the green button [Use this template](https://github.com/liplum/MindustryModTemplate/generate) above. +- Step 2: Enter your repository name, which is used to generate `mod.hjson`. +- Step 3: After GitHub Action has done the cleanup job, clone your repository. + ```shell + git clone https://github.com//.git + ``` + +### Manually Clone + +- Step 1: Clone this template. + ```shell + git clone https://github.com/liplum/MindustryModTemplate.git + ``` +- Step 2: Delete `.git` folder. + ```shell + cd + rm -rf .git + ``` + +You need [Python 3](https://www.python.org/) installed on your computer to run the cleanup script. +Otherwise, you can just delete the [cleanup.py](cleanup.py) file in the root folder. + +Replace `` to your name, `` to your mod name bellow, and run the command. + +```shell +python cleanup.py "/" +``` + +It will clean up your project and generate essential files. ## Building through GitHub Actions -Check the "Actions" tab on your repository page. -Select the most recent commit in the list. +Check the "Actions" tab on your repository page. +Select the most recent commit in the list. If it completed successfully, there should be a download link under the "Artifacts" section, that could work on both Desktop and Android. -## Generating release draft -Any push whose head commit contains `[release]` in its message, a release draft will be generated on GitHub. +## Create a Release Draft + +- Step 1: Check the "Actions" tab on your repository page. +- Step 2: Find `Creat Release Draft` on the left hand. +- Step 3: Hit `Run workflow` button and run on a branch you want, mostly, it's `master`. + +Then a release draft with a `.jar` file, it's your mod, will be generated on GitHub. ## Gradle DSL and Kotlin -You can select which `Gradle DSL` to use, by easily deleting `build.gradle` or `build.gradle.kts`. +You can select which `Gradle DSL` to use by easily deleting either `build.gradle` or `build.gradle.kts`. + If you kept both, it would use `build.gradle` as default. -If you want to make a Kotlin mod, please keep the `build.gradle.kts` and remove `build.gradle`. +If you want to make a Kotlin mod, please delete `build.gradle`. ## Licence + GNU General Public License v3.0 diff --git a/cleanup.py b/cleanup.py index 9e32fbc..d5a67db 100644 --- a/cleanup.py +++ b/cleanup.py @@ -3,10 +3,14 @@ import io args = sys.argv -full_name = args[1] +if len(args) == 1: + full_name = "example/ExampleMod" +else: + full_name = args[1] owner, repo = full_name.split('/') package_name = owner.replace("-", "") main_class_template = """package %PackageName%; + import mindustry.mod.*; public class %MainClassName% extends Mod { @@ -33,11 +37,10 @@ """ -def transform_repo_to_class_name() -> str: +def transform_repo_to_class_name(): with io.StringIO() as b: hyphen = False for i, c in enumerate(repo): - c: str if c == '-': hyphen = True else: @@ -50,7 +53,8 @@ def transform_repo_to_class_name() -> str: else: b.write(c) name: str = b.getvalue() - name = name.removesuffix("Mod") + if name.endswith("Mod"): + return name[:-len("Mod")] return name