diff --git a/pyproject.toml b/pyproject.toml index 6ef7e6e..98e6a34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,18 +1,23 @@ -[project] +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.dependencies] +python = "^3.0" + +[tool.poetry] name = "gester" -version = "1.2.1" +version = "1.3.2" description = "A game engine for console based text game" readme = "README.md" -keywords = ["games", "game development", "game engine", "console"] -license = {file = "LICENSE"} -authors = [ - {name = "etcetra7n", email = "greeknio@gmail.com"} -] -requires-python = ">=2.7" +keywords = ["games", "game development", "game engine", "text-game-engine", "console game engine"] +license = "BSL-1.0" +authors = ["John Anchery "] +repository = "https://github.com/etcetra7n/gest" + classifiers = [ "Topic :: Games/Entertainment", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", @@ -25,11 +30,15 @@ classifiers = [ "Programming Language :: Python :: 3.11", "License :: OSI Approved :: Boost Software License 1.0 (BSL-1.0)", "Operating System :: OS Independent", -] + "Topic :: Games/Entertainment" + ] + +[tool.poetry.scripts] +gest = 'gester.gest:main' -[project.scripts] -gest = "gest:main" +[tool.poetry.extras] +pygame = ["pygame"] -[project.urls] +[tool.poetry.urls] "Bug Tracker" = "https://github.com/etcetra7n/gest/issues" -repository = "https://github.com/etcetra7n/gest" +"Repository" = "https://github.com/etcetra7n/gest" diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index 3f262a6..0000000 --- a/src/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = '1.2.1' diff --git a/src/gest.py b/src/gest.py deleted file mode 100644 index 90bdab3..0000000 --- a/src/gest.py +++ /dev/null @@ -1,260 +0,0 @@ -from sys import argv, stdout, exit -from time import sleep -from os.path import isfile, abspath -import re -import pickle -from colorama import Fore -from os import environ -environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1' -from pygame.mixer import music, init -from win32api import GetAsyncKeyState -import win32con - -def init_in_game_vars(gest_file): - in_game_vars['gest_file'] = abspath(gest_file) - in_game_vars['line_index'] = 0 - in_game_vars['gsav_file'] = abspath(gest_file)[:-4] + 'gsav' - in_game_vars['_scene_return'] = [] - -def save(): - gsav_file.seek(0) - pickle.dump(in_game_vars, gsav_file) - -def trim(str): - begin = 0 - end = len(str) - for i, c in enumerate(str): - if(c != ' '): - begin = i - break - for i, c in enumerate(reversed(str)): - if(c != ' '): - end = len(str)-i - break - return str[begin:end] - -def block(str, lines): - jump_index = 0 - for i in range(in_game_vars['line_index']+1, len(lines)): - if re.match(r' *\[ *'+str+r' *\]', lines[i]): - jump_index = i+1 - break - else: - print(Fore.RED + "\n\nScript Error: " + Fore.RESET +"["+ str +"] not found") - exit() - return jump_index - -def txtout(txt): - - ''' - EMBEDDED VARIBLE - Syntax: - some text {var} some text... - for example: - My name is {name} - ''' - embedded_var = re.findall(r'\{ *([a-zA-Z0-9_]*) *\}', txt) - for var in embedded_var: - txt = re.sub(r'({ *'+var+' *})', in_game_vars[var], txt) - _fast_txt=False - for char in txt: - print(char, end='') - stdout.flush() - state = GetAsyncKeyState(win32con.VK_CONTROL) - _fast_txt = state not in [0, 1] - if _fast_txt: - sleep(0.008) - else: - sleep(0.03) - -def play(): - if '_bg_music' in in_game_vars: - music.load(in_game_vars['_bg_music'][0]) - music.play(in_game_vars['_bg_music'][1]) - with open(in_game_vars['gest_file'], 'r') as f: - lines = f.readlines() - line_index = in_game_vars['line_index'] - while(True): - in_game_vars['line_index'] = line_index - save() - if(line_index >= len(lines)): - break - line = lines[line_index] - - # COMMENTS - if('#' in line): - if (trim((lines[line_index])).startswith('#')): - line_index += 1 - continue - else: - chr_index = line.find('#') - line = line[:chr_index] + '\n' - - ''' - COMMAND WITH VARIABLE - Syntax: - [command: var] text - for example: - [input: name] Enter your name: - ''' - com = re.search(r'\[ *([a-zA-Z_]+) *: *(.+) *\] *(.*)', line) - if com: - command = com.group(1) - var = com.group(2) - prompt = com.group(3) - if(command == 'input'): - ''' - INPUT COMMAND - Syntax: - [input: var] some text - for example: - [input: name] Enter your name: - - The name will be stored in the varible 'name' which - can be accessed by `{name}` - ''' - txtout(prompt + ' ') - - in_game_vars[var] = input() - line_index += 1 - continue - - elif(command == 'yes_or_no'): - ''' - YES_OR_NO COMMAND - Syntax: - [yes_or_no: var] some question - for example: - [yes_or_no: p] Are you ready to proceed - while playing the above example yould be displayed - as: - Are you ready to proceed (y/n): - ''' - txtout(prompt + ' (y/n): ') - inp = input() - if inp == 'y': - in_game_vars[var] = 'yes' - elif inp == 'n': - in_game_vars[var] = 'no' - else: - txtout(Fore.YELLOW + "\nInvalid input:"+ Fore.RESET +" Try again\n\n") - continue - line_index += 1 - continue - elif command == 'musicloop': - if '_bg_music' in in_game_vars: - music.fadeout(1000) - music.load(var) - music.play(-1) - in_game_vars['_bg_music'] = [var, -1] - line_index += 1 - continue - elif command == 'music': - if '_bg_music' in in_game_vars: - music.fadeout(1000) - music.load(var) - music.play() - in_game_vars['_bg_music'] = [var, 0] - line_index += 1 - continue - elif command == 'play': - in_game_vars['_scene_return'].append(line_index+1) - for l in range(len(lines)): - if re.match(r' *\[ *scene *: *'+ var + r' *\]', lines[l]): - line_index = l+1 - break - else: - print(Fore.RED+"\nScript Error:"+Fore.RESET+" Scene `"+scene_name+"` is not defined") - exit() - continue - - ''' - VARIABLE EQUALITY CONDITION - Syntax: - [{var} value] - ... - [endblock] - - (OR) - - [{var} "value"] - ... - [endblock] - - (OR) - - [{var} 'value'] - ... - [endblock] - ''' - con = re.search(r'\[ *{ *([a-zA-Z0-9_]+) *} +(.+) *\]', line) - if con: - if in_game_vars[con.group(1)] == con.group(2): - line_index += 1 - continue - - else: - line_index = block('endblock', lines)+1 - continue - - directive = re.search(r'\[ *([a-zA-Z_]*) *\]', line) - if directive: - name = directive.group(1) - if name == 'endscene': - line_index = in_game_vars['_scene_return'].pop() - # pop() returns and removes the last indice - continue - elif name == 'endblock': - line_index += 1 - continue - elif name == 'abort': - break - elif name == 'stopmusic': - music.fadeout(1000) - in_game_vars.pop('_bg_music') - line_index += 1 - continue - - if re.match(r' *\[ *scene *: *([a-zA-Z0-9_-]*) *\]', line): - line_index = block('endscene', lines)+1 - continue - - txtout(trim(line)) - line_index += 1 - save() - -def main(): - global in_game_vars - global gsav_file - in_game_vars = {} - if len(argv)<2: - print(Fore.RED + "\nError:" + Fore.RESET + " Argument not provided") - exit() - file = argv[1] - if not(isfile(file)): - print(Fore.RED + "\nError:" + Fore.RESET + " This file cannot be located") - exit() - try: - if(file.endswith('.gest')): - init_in_game_vars(file) - gsav_file = open(in_game_vars['gsav_file'], 'wb') - init() # for music - play() - gsav_file.close() - elif(file.endswith('.gsav')): - with open(file, 'rb') as sf: - in_game_vars = pickle.load(sf) - gsav_file = open(in_game_vars['gsav_file'], 'wb') - init() # for music - play() - gsav_file.close() - else: - print(Fore.RED + "\nError:" + Fore.RESET + " Unrecognized file type. \ -Only .gest and .gsav file extentions are supported") - except KeyboardInterrupt: - gsav_file.close() - exit() - # exit the game in case the user press `ctrl+C` which raises a KeyboardInterrupt - -if __name__=='__main__': - main()