Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Build and run
Browse files Browse the repository at this point in the history
  • Loading branch information
EmperorPenguin18 committed Sep 27, 2023
1 parent 0a37d04 commit b3faaf6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PyGObject>=3.46.0
GitPython>=3.1.37
47 changes: 47 additions & 0 deletions tidal-gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk, GLib, Gio
import git
import tarfile

def bin2header(data, var_name='var'):
out = []
out.append('unsigned char {var_name}[] = {{'.format(var_name=var_name))
l = [ data[i:i+12] for i in range(0, len(data), 12) ]
for i, x in enumerate(l):
line = ', '.join([ '0x{val:02x}'.format(val=c) for c in x ])
out.append(' {line}{end_comma}'.format(line=line, end_comma=',' if i<len(l)-1 else ''))
out.append('};')
out.append('unsigned int {var_name}_len = {data_len};'.format(var_name=var_name, data_len=len(data)))
return '\n'.join(out)

class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -34,6 +47,11 @@ def __init__(self, *args, **kwargs):
self.open_dialog = Gtk.FileDialog.new()
self.open_dialog.set_title("Select a Folder")

self.run_button = Gtk.Button(label="Build and Run")
self.header.pack_start(self.run_button)
self.run_button.connect('clicked', self.build_and_run)
self.run_button.set_icon_name("media-playback-start-symbolic")

menu = Gio.Menu.new()
self.popover = Gtk.PopoverMenu()
self.popover.set_menu_model(menu)
Expand Down Expand Up @@ -232,6 +250,35 @@ def event_collision(self, action, param):
def action_spawn(self, action, param):
self.obj["events"][self.event].append({"type": "spawn"})

def build_and_run(self, button):
datadir = os.getenv("XDG_DATA_HOME")
if datadir == None:
if os.name == 'posix':
datadir = "/home/"+os.getlogin()+"/.local/share"
else:
datadir = "%APPDATA%"
buildpath = datadir+os.sep+"tidal-gtk"#+os.sep+"build"
try:
os.mkdir(buildpath)
except FileExistsError:
pass
try:
repo = git.Repo.clone_from("https://github.com/EmperorPenguin18/tidal2d", buildpath, multi_options=['--depth 1', '--branch 0.3'])
except git.exc.GitCommandError:
pass
tar = tarfile.open(buildpath+os.sep+"assets.tar", "w")
tar.add(self.project_path)
tar.close()
tar = open(buildpath+os.sep+"assets.tar", "rb")
header = open(buildpath+os.sep+"src"+os.sep+"embedded_assets.h", "w")
header.write(bin2header(tar.read(), "embedded_binary"))
tar.close()
header.close()
os.chdir(buildpath)
os.system("cmake . -DCMAKE_BUILD_TYPE=Debug -DSTATIC=ON")
os.system("cmake --build .")
os.system(f".{os.sep}tidal2d")

class MyApp(Gtk.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down

0 comments on commit b3faaf6

Please sign in to comment.