Skip to content

Commit

Permalink
add update function
Browse files Browse the repository at this point in the history
  • Loading branch information
fischer-hub committed Oct 16, 2024
1 parent 5d15553 commit bc70181
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/pyinstaller-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,18 @@ jobs:
generate_release_notes: true
overwrite: true
body: |
Pre-release versions are not consistent between tags. This is just used
Pre-release versions are not consistent between tags. This is used
as a way to automatically package the game as executables for different
operating systems. Each executable version is suffixed with its github
commit hash to identify versions. Pre-releases might be overwritten with
newer versions (differentiable by the github commit hash in the file
name).
operating systems.
- name: Upload Linux executable to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/vigilant-ubuntu-latest-${{ github.sha }}
asset_name: vigilant-ubuntu-latest-${{ github.sha }}
asset_path: ./dist/vigilant-ubuntu-latest
asset_name: vigilant-ubuntu-latest
asset_content_type: application/octet-stream

- name: Upload macOS executable to Release
Expand All @@ -115,8 +112,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/vigilant-macos-latest-${{ github.sha }}
asset_name: vigilant-macos-latest-${{ github.sha }}
asset_path: ./dist/vigilant-macos-latest
asset_name: vigilant-macos-latest
asset_content_type: application/octet-stream

- name: Upload Windows executable to Release
Expand All @@ -125,6 +122,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/vigilant-windows-latest-${{ github.sha }}.exe
asset_name: vigilant-windows-latest-${{ github.sha }}.exe
asset_path: ./dist/vigilant-windows-latest.exe
asset_name: vigilant-windows-latest.exe
asset_content_type: application/octet-stream
23 changes: 21 additions & 2 deletions lib/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import math, os, sys, yaml, datetime
import math, os, sys, yaml, datetime, urllib.request, platform
from scipy.interpolate import CubicSpline
import pickle
import numpy as np
Expand Down Expand Up @@ -219,4 +219,23 @@ def merge_dicts(a: dict, b: dict, path=[], level=1):
else:
print(f"Savegame key '{key}' not found in loaded savegame, defaulting to template value {b[key]}.")
a[key] = b[key]
return a
return a


def update_game():
osname = platform.system()

if 'Linux' in osname:
osname = 'ubuntu'
elif 'Darwin' in osname:
osname = 'macos'
elif 'Windows' in osname:
osname = 'windows'
else:
print(f"Failed to update game executable. Could not detect operating system since platform.system returns unknown value: {osname}.")
return

try:
urllib.request.urlretrieve(f"https://github.com/fischer-hub/vigilant-funicular/releases/latest/download/vigilant-{osname}", "vigilant")
except Exception as e:
print(f"Failed to update game executable, download returned: {e}.")
6 changes: 3 additions & 3 deletions scenes/start_screen/start.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from src.scene import Scene, Clickable, ChangeScene, Commentable
from src.text import Text
import pygame as pg
from lib.helper import path, save_config, check_update
from lib.helper import path, save_config, check_update, update_game
from src.animate import StripAnimate
from datetime import datetime
import os, sys
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(self, player, cursor, collision_file = None, scale_factor = 6, dev
save_config(self.config)

if 'update_available' not in self.config:
self.config['update_available'] = False
self.config['update_available'] = False

self.player_spawn = (-100, -100)

Expand All @@ -112,7 +112,7 @@ def __init__(self, player, cursor, collision_file = None, scale_factor = 6, dev
# clickables
start_button_clickable = Btn(pg.Rect(460, 120, 1050, 220), sound = path('sounds', 'button_click.ogg'), animation = start_button, scene = self, id = 'start_button', fct = lambda: (4,(0,0)))
new_game_button_clickable = Btn(pg.Rect((460, 440, 1050, 220)), sound = path('sounds', 'button_click.ogg'), animation = new_game, fct = lambda: (0,(0,0)), scene = self, id = 'new_game')
update_button_clickable = Btn(pg.Rect((460, 770, 1050, 220)), sound = path('sounds', 'button_click.ogg'), animation = update_button, scene = self, id = 'update_button')
update_button_clickable = Btn(pg.Rect((460, 770, 1050, 220)), sound = path('sounds', 'button_click.ogg'), animation = update_button, scene = self, id = 'update_button', fct = update_game)
caution_msg_clickable = Msg(pg.Rect((524, 708, 800, 150)), sound = path('sounds', 'button_click.ogg'), animation = caution_msg, scene = self)

self.clickable_lst = { '1': SizeMeter(pg.Rect(1670, 290, 90, 65), self, 1), '2': SizeMeter(pg.Rect(1670, 395, 90, 65), self, 2), '3': SizeMeter(pg.Rect(1670, 495, 90, 65), self, 3),
Expand Down

0 comments on commit bc70181

Please sign in to comment.