From ceb812565fb014d64cb2b715d93dfbfa107d329d Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 7 Jun 2019 00:13:43 -0300 Subject: [PATCH] add unfinished impl for quicksave --- scritcher/executer.py | 34 ++++++++++++++++++++++++++++++++-- scritcher/utils.py | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/scritcher/executer.py b/scritcher/executer.py index a0b2ba4..ab405d1 100644 --- a/scritcher/executer.py +++ b/scritcher/executer.py @@ -1,5 +1,8 @@ -import sys +import os import shlex +import tempfile +from pathlib import Path + from .utils import load_file_path from .error import InterpreterError @@ -7,13 +10,40 @@ from .error import InterpreterError class Interpreter: """Interpreter for scritcher instructions/statements.""" def __init__(self): + self.orig_path = None self.loaded_path = None def _cmd_noop(self): pass def _cmd_load(self, loadpath: str): - path = load_file_path(loadpath) + source_path = load_file_path(loadpath) + self.orig_path = source_path + + # create a temporary file to hold bmp data + handle, bmp_path = tempfile.mkstemp('.bmp') + os.close(handle) + + self.loaded_path = Path(bmp_path) + + def _cmd_quicksave(self): + suffix = self.orig_path.suffix + name = self.orig_path.name.replace(suffix, '') + parent_folder = self.orig_path.parents[0] + + # we need to search all files that match the pattern NAME_g* + index = 0 + for glitched_out in parent_folder.glob(f'{name}*'): + try: + idx = int(glitched_out.name.strip(name + '_g')[0]) + index = idx + except (IndexError, ValueError): + continue + + # create our next glitched iteration + glitched_path = parent_folder / f'{name}_g{index + 1}.raw' + print(glitched_path) + def run(self, line: str): """Run a single line.""" diff --git a/scritcher/utils.py b/scritcher/utils.py index 64554bb..fe5d775 100644 --- a/scritcher/utils.py +++ b/scritcher/utils.py @@ -1,5 +1,6 @@ import sys from pathlib import Path + from .error import InterpreterError def load_file_path(arg: str) -> Path: