From 15ecb3d6b821c5909ee649935027d204fa271d47 Mon Sep 17 00:00:00 2001 From: Marek Maskarinec Date: Thu, 20 Jan 2022 21:33:38 +0100 Subject: [PATCH] add few more cmd options --- Makefile | 8 +-- cmd/init.bat | 3 - cmd/package.bat | 14 ---- cmd/run.bat | 1 - cmd/tophat-cli | 168 ------------------------------------------------ src/Makefile | 8 ++- src/main.c | 15 ++++- src/staembed.c | 34 ++++++++++ version | 2 +- 9 files changed, 54 insertions(+), 199 deletions(-) delete mode 100644 cmd/init.bat delete mode 100644 cmd/package.bat delete mode 100644 cmd/run.bat delete mode 100755 cmd/tophat-cli diff --git a/Makefile b/Makefile index 4d6f601b..e0688d43 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,13 @@ ifeq ($(PLATFORM), Linux) CROSS_CC=x86_64-w64-mingw32-gcc CROSS_FLAGS = -lm -Ldl -Ilib/rawdraw -lopengl32 -lgdi32 -Wl,-Bstatic -lpthread $(WARNS) $(DEFS) -DNO_OPENGL_HEADERS TARGET=tophat + UMKA_BIN = ./lib/umka/build/umka else ifeq ($(SHORT_PLATFORM), MINGW64_NT) LDLIBS += -lm -lopengl32 -lgdi32 -Wl,-Bstatic -lpthread lib/rawdraw/chew.c TARGET=tophat.exe DEFS += -DNO_OPENGL_HEADERS + UMKA_BIN = ./lib/umka/build/umka.exe endif endif @@ -38,12 +40,6 @@ include src/Makefile deepclean:: clean -install: $(TARGET) cross - ./package.sh - cp cmd/tophat-cli /usr/bin - ./cmd/tophat-cli install tophat-linux.zip - rm tophat-linux.zip tophat-win.zip - clean:: $(RM) $(TARGET) $(RM) $(TARGET).exe diff --git a/cmd/init.bat b/cmd/init.bat deleted file mode 100644 index dee260dd..00000000 --- a/cmd/init.bat +++ /dev/null @@ -1,3 +0,0 @@ -set /p Name=Enter name of the game: -mkdir %Name% -copy /Y preset\*.* %Name% diff --git a/cmd/package.bat b/cmd/package.bat deleted file mode 100644 index 582766e0..00000000 --- a/cmd/package.bat +++ /dev/null @@ -1,14 +0,0 @@ -set /p Name=Target: - -mkdir %Name%-windows -mkdir %Name%-windows\tophat.dat -xcopy /s /e /Y %Name%\*.* %Name%-windows\tophat.dat -copy /Y bin\tophat-win.exe %Name%-windows -rename %Name%-windows\tophat-win.exe %Name%.exe - -mkdir %Name%-linux -mkdir %Name%-linux\tophat.dat -xcopy /s /e /Y %Name%\*.* %Name%-linux\tophat.dat -copy /Y bin\tophat-linux %Name%-linux -rename %Name%-linux\tophat-linux %Name% - diff --git a/cmd/run.bat b/cmd/run.bat deleted file mode 100644 index 60b0d2ae..00000000 --- a/cmd/run.bat +++ /dev/null @@ -1 +0,0 @@ -..\bin\tophat-win.exe diff --git a/cmd/tophat-cli b/cmd/tophat-cli deleted file mode 100755 index 577e4460..00000000 --- a/cmd/tophat-cli +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env sh - -Path=/usr/share/tophat - -clean () { - rm -rf $Path - rm -rf tophat.zip -} - -setup () { - if [ ! $(whoami) = "root" ]; then - echo "not running as root" - exit 1 - fi - - rm -rf $Path - mkdir $Path - unzip $1 -d $Path - mv $Path/linux/* $Path - rm -r $Path/linux -} - -check-update() { - echo "checking for new versions" - upversion=$(curl -s "https://raw.githubusercontent.com/marekmaskarinec/tophat/main/version") - if [ $upversion = $(cat $Path/version) ]; then - echo "tophat is up to date" - exit 0 - fi - - echo $(upversion) is available -} - -package() { - if [ "$2" == "" ]; then - echo "specify os" - exit 1 - fi - - if [ "$3" == "" ]; then - Name=game - else - Name=$3 - fi - - if [ "$2" == "linux" ]; then - Bin=tophat-linux - elif [ "$2" == "windows" ]; then - Bin=tophat-win.exe - Sufix=.exe - elif [ "$2" == "all" ]; then - echo "packaging for linux" - package $Name linux $Name - echo "packaging for windows" - package $Name windows $Name - exit 0 - else - echo "invalid platform. choose: linux, windows or all" - exit 1 - fi - - if [ "$Bin" == "" ]; then - echo "invalid os specified. only windows and linux currently supported" - exit 1 - fi - - rm -rf $Name-$2.zip - - mkdir ../$Name-$2 - mkdir ../$Name-$2/tophat.dat - cp -r ./* ../$Name-$2/tophat.dat - cp -r $Path/bin/$Bin ../$Name-$2/$Name$Sufix - - Ignore="-x tophat.dat/*.zip -x tophat.dat/*.git* -x tophat.dat/" - - if [ -f ".thignore" ]; then - Ignore="$Ignore $(sed ':a;N;$!ba;s/\n/ -x tophat.dat\//g' .thignore)" - fi - - if [ "$2" == "windows" ]; then - mv ../$Name-$2 ./ - zip -Z store -y -q -r ../$Name-$2.zip $Name-$2 - else - zip -q -r ../$Name-$2.zip ../$Name-$2 - fi - - rm -rf ../$Name-$2 - rm -rf ./$Name-$2 - mv ../$Name-$2.zip ./ - - echo "done" -} - -check() { - installed=FAILED - linux_bin=FAILED - windows_bin=FAILED - presets=FAILED - - if [ -f $Path/version ]; then - installed=OK - echo "version..........$(cat $Path/version)" - fi - - if [ -f $Path/bin/tophat-linux ]; then - linux_bin=OK - fi - - if [ -f $Path/bin/tophat-win.exe ]; then - windows_bin=OK - fi - - if [ -f $Path/main.um ]; then - presets=OK - fi - - echo "tophat install...$installed" - echo "linux bin........$linux_bin" - echo "windows bin......$windows_bin" - echo "presets..........$presets" -} - -case $1 in - ("run") - $Path/bin/tophat-linux - ;; - ("package") - package "" $2 $3 - ;; - ("install") - setup $2 - ;; - ("update") - check-update - ;; - ("uninstall") - clean - ;; - ("get") - get - ;; - ("init") - cp $Path/*.um ./ - ;; - ("version") - if [ -f "/usr/share/tophat/version" ]; then - cat $Path/version - else - echo "tophat is not installed" - fi - ;; - ("check") - check - ;; - *) - echo "tophat v20 cli tool" - echo "invalid arguments. usage:" - echo " run: runs the game in current directory" - echo " init: initializes current directory with hello world preset" - echo " package [ platform all/windows/linux ] [ game name ]: makes a package of the game in current directory" - echo " install [ package path ]: installs tophat from archive specified by path" - echo " update: checks for update." - echo " uninstall: removes tophat data." - echo "more info on discord server: https://discord.gg/PcT7cn59h9" - ;; -esac - - diff --git a/src/Makefile b/src/Makefile index d403d190..337aa7d5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,13 +7,15 @@ SRCS = $(shell find src/ -name \*.c -print) OBJS = $(sort $(SRCS:.c=.o)) DEPS = $(OBJS:.o=.d) +HELPER_SCRIPT = cmd/buildhelper.um EM_TARGET = src/staembed.c UMKA_MODULES = umka/anim.um umka/audio.um umka/csv.um umka/ent.um umka/image.um umka/input.um umka/misc.um umka/canvas.um umka/ray.um umka/rect.um umka/tilemap.um umka/window.um umka/ui.um umka/std/std.um umka/particles.um umka/light.um umka/lerp.um umka/std/map.um umka/std/utf8.um umka/font.um umka/th.um umka/signal.um umka/atlas.um -$(EM_TARGET): $(UMKA_MODULES) +$(EM_TARGET): $(UMKA_MODULES) LICENSE version @echo EM $@ - @./lib/umka/build/umka cmd/buildhelper.um em th_em_modulesrc $(UMKA_MODULES) > $(EM_TARGET) - @./lib/umka/build/umka cmd/buildhelper.um argarr th_em_modulenames $(notdir $(UMKA_MODULES)) >> $(EM_TARGET) + $(UMKA_BIN) $(HELPER_SCRIPT) em th_em_modulesrc $(UMKA_MODULES) > $(EM_TARGET) + @$(UMKA_BIN) $(HELPER_SCRIPT) argarr th_em_modulenames $(notdir $(UMKA_MODULES)) >> $(EM_TARGET) + @$(UMKA_BIN) $(HELPER_SCRIPT) em th_em_misc LICENSE version >> $(EM_TARGET) rm -f src/bindings.o %.o: %.c diff --git a/src/main.c b/src/main.c index 9d6fd727..19d1e5a3 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,7 @@ int died = 0; extern char *th_em_modulenames[]; extern char *th_em_modulesrc[]; +extern char *th_em_misc[]; extern int th_em_modulenames_count; void die() { @@ -36,7 +37,7 @@ int main(int argc, char *argv[]) { int umkaOK; if (argc != 1) { - if (strcmp(argv[1], "-modsrc") == 0) { + if (strcmp(argv[1], "modsrc") == 0) { if (argc != 3) { printf("modsrc takes one argument\n"); return 1; @@ -50,12 +51,20 @@ int main(int argc, char *argv[]) { } printf("No module named %s\n", argv[2]); + } else if (strcmp(argv[1], "license") == 0) { + printf("%s\n", th_em_misc[0]); + return 0; + } else if (strcmp(argv[1], "version") == 0) { + printf("%s\n", th_em_misc[1]); } else { printf( "tophat - a minimalist game engine for making games in umka.\n" "Just launching tophat without flags will run main.um or tophat.dat/main.um\n" - "Available flags:\n" - " -modsrc : print source of a builtin module\n"); + "Available modes:\n" + " modsrc - print source of a builtin module\n" + " license - print the license\n" + " version - print the version\n" + "Visit mrms.cz/tophat.html for more info."); return 0; } diff --git a/src/staembed.c b/src/staembed.c index 9a93636e..9038088f 100644 --- a/src/staembed.c +++ b/src/staembed.c @@ -2052,3 +2052,37 @@ const char *th_em_modulesrc[] = { }; const char *th_em_modulenames[] = { "anim.um", "audio.um", "csv.um", "ent.um", "image.um", "input.um", "misc.um", "canvas.um", "ray.um", "rect.um", "tilemap.um", "window.um", "ui.um", "std.um", "particles.um", "light.um", "lerp.um", "map.um", "utf8.um", "font.um", "th.um", "signal.um", "atlas.um", }; int th_em_modulenames_count = 23; +const char *th_em_misc[] = { +"BSD 3-Clause License\n" +"\n" +"Copyright (c) 2021, Marek Maskarinec\n" +"All rights reserved.\n" +"\n" +"Redistribution and use in source and binary forms, with or without\n" +"modification, are permitted provided that the following conditions are met:\n" +"\n" +"1. Redistributions of source code must retain the above copyright notice, this\n" +" list of conditions and the following disclaimer.\n" +"\n" +"2. Redistributions in binary form must reproduce the above copyright notice,\n" +" this list of conditions and the following disclaimer in the documentation\n" +" and/or other materials provided with the distribution.\n" +"\n" +"3. Neither the name of the copyright holder nor the names of its\n" +" contributors may be used to endorse or promote products derived from\n" +" this software without specific prior written permission.\n" +"\n" +"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n" +"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n" +"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n" +"DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n" +"FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n" +"DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n" +"SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n" +"CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n" +"OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" +"OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" +"", +"v20-fde324a\n" +"", +}; diff --git a/version b/version index 9951e91f..83b4ac55 100644 --- a/version +++ b/version @@ -1 +1 @@ -v20-fde324a +v0.5