Skip to content

Commit

Permalink
Add support for Jak 2 (#4)
Browse files Browse the repository at this point in the history
* jak2: add jak2 assets for shortcut

* jak2: add support for installing and running jak2

* ci: setup a CI workflow
  • Loading branch information
xTVaser authored Nov 3, 2023
1 parent 9b26a97 commit d598ec2
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 87 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 🏭 Build Plugin

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: write

jobs:
build-plugin:
if: github.repository == 'open-goal/decky-plugin'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: "main"

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: true

- name: Install Decky CLI
run: |
mkdir ./cli
curl -L -o ./cli/decky "https://github.com/SteamDeckHomebrew/cli/releases/latest/download/decky"
chmod +x ./cli/decky
- name: Create Plugin
run: sudo ./cli/decky plugin build ./
104 changes: 104 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: 🏭 Create Release

on:
workflow_dispatch:
inputs:
bump:
description: "Semver Bump Type"
required: true
default: "patch"
type: choice
options:
- "patch"
- "minor"
- "major"

permissions:
contents: write

jobs:
create-tag:
if: github.repository == 'open-goal/decky-plugin'
name: "Create New Tag"
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.version_bump.outputs.new_tag }}
steps:
- uses: actions/checkout@v4
# TODO - still have to use PAT to bypass branch protections
# https://github.com/orgs/community/discussions/13836
with:
token: ${{ secrets.BOT_PAT }}

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Bump Version
id: version_bump
run: |
npm version ${{ github.event.inputs.bump }}
NEW_VERSION=$(awk '/version/{gsub(/("|",)/,"",$2);print $2}' package.json)
echo "new_tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Commit Version Bump
uses: EndBug/add-and-commit@v9
with:
default_author: github_actor
author_name: "OpenGOALBot"
author_email: "OpenGOALBot@users.noreply.github.com"
message: "release: bump to version - ${{ steps.version_bump.outputs.new_tag }}"
tag: "${{ steps.version_bump.outputs.new_tag }}"

- name: Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create ${{needs.create-tag.outputs.new_tag}} --generate-notes --draft --repo open-goal/decky-plugin
build-and-release-plugin:
if: github.repository == 'open-goal/decky-plugin'
needs: [create-tag]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: "main"
# TODO - still have to use PAT to bypass branch protections
# https://github.com/orgs/community/discussions/13836
token: ${{ secrets.BOT_PAT }}

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: true

- name: Install Decky CLI
run: |
mkdir ./cli
curl -L -o ./cli/decky "https://github.com/SteamDeckHomebrew/cli/releases/latest/download/decky"
chmod +x ./cli/decky
- name: Create Plugin
run: |
sudo ./cli/decky plugin build ./
mv ./out/OpenGOAL.zip ./out/OpenGOAL-${{needs.create-tag.outputs.new_tag}}.zip
- name: Upload Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{needs.create-tag.outputs.new_tag}} ${{ github.WORKSPACE }}/out/*.zip --repo open-goal/decky-plugin --clobber
- name: Publish Release
env:
GITHUB_TOKEN: ${{ secrets.BOT_PAT }}
run: |
gh release edit ${{needs.create-tag.outputs.new_tag}} --draft=false --repo open-goal/decky-plugin
Binary file added defaults/img/jak2/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaults/img/jak2/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaults/img/jak2/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaults/img/jak2/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defaults/img/jak2/wide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 32 additions & 26 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def shortcut_already_exists(shortcuts, name):
return True
return False


def version_supports_game_flag(version):
parts = version.replace("v", "").split(".")
if int(parts[0]) > 0 or int(parts[1]) > 1:
return True
elif int(parts[1]) == 0 and int(parts[2]) >= 44:
return True
return False


def _install_game_impl(game):
try:
decky_plugin.logger.info("installing game: {}".format(game))
Expand All @@ -59,12 +69,11 @@ def _install_game_impl(game):
release_url = "https://api.github.com/repos/{}/{}/releases/latest".format(
owner, repo
)
release_resp = urllib.request.urlopen(
release_url, context=get_ssl_context()
)
release_resp = urllib.request.urlopen(release_url, context=get_ssl_context())

if release_resp.status == 200:
release_info = json.loads(release_resp.read().decode("utf-8"))
use_game_flag = version_supports_game_flag(release_info["tag_name"])
decky_plugin.logger.info(
"received response from github: {}".format(release_info)
)
Expand All @@ -83,9 +92,7 @@ def _install_game_impl(game):
asset_url = asset_to_download["browser_download_url"]

# Download the asset
asset_file = os.path.join(
extract_directory, asset_to_download["name"]
)
asset_file = os.path.join(extract_directory, asset_to_download["name"])
asset_resp = urllib.request.urlopen(
asset_url, context=get_ssl_context()
)
Expand All @@ -112,15 +119,19 @@ def _install_game_impl(game):
"isos",
"{}.iso".format(game),
)
args = [
"./extractor",
iso_path,
"--extract",
"--validate",
"--decompile",
"--compile",
]
if use_game_flag:
args.append("--game")
args.append(game)
completed_process = subprocess.run(
[
"./extractor",
iso_path,
"--extract",
"--validate",
"--decompile",
"--compile",
],
args,
cwd=extract_directory,
check=True,
stdout=subprocess.PIPE,
Expand Down Expand Up @@ -148,9 +159,7 @@ def _install_game_impl(game):
os.path.join(extract_directory, "data", "decompiler_out")
):
shutil.rmtree(
os.path.join(
extract_directory, "data", "decompiler_out"
)
os.path.join(extract_directory, "data", "decompiler_out")
)
if os.path.exists(
os.path.join(extract_directory, "data", "iso_data")
Expand All @@ -177,19 +186,16 @@ def _install_game_impl(game):
return None
except Exception as error:
decky_plugin.logger.error(
"[install_game] An exception occurred: {}".format(
traceback.format_exc()
)
"[install_game] An exception occurred: {}".format(traceback.format_exc())
)
return None


def _remove_game_impl(game):
try:
if game == "jak1":
if os.path.exists(
os.path.join(
decky_plugin.DECKY_USER_HOME, "OpenGOAL", "games", "jak1"
)
os.path.join(decky_plugin.DECKY_USER_HOME, "OpenGOAL", "games", "jak1")
):
shutil.rmtree(
os.path.join(
Expand All @@ -198,9 +204,7 @@ def _remove_game_impl(game):
)
elif game == "jak2":
if os.path.exists(
os.path.join(
decky_plugin.DECKY_USER_HOME, "OpenGOAL", "games", "jak2"
)
os.path.join(decky_plugin.DECKY_USER_HOME, "OpenGOAL", "games", "jak2")
):
shutil.rmtree(
os.path.join(
Expand All @@ -216,6 +220,7 @@ def _remove_game_impl(game):
)
return False


class Plugin:
async def create_shortcut(self, owner_id, game):
try:
Expand Down Expand Up @@ -293,6 +298,7 @@ async def create_shortcut(self, owner_id, game):
"jak2",
"gk",
),
"LaunchOptions": "--game jak2",
"StartDir": os.path.join(
decky_plugin.DECKY_USER_HOME, "OpenGOAL", "games", "jak2"
),
Expand Down
Loading

0 comments on commit d598ec2

Please sign in to comment.