add unfinished impl for quicksave

This commit is contained in:
Luna 2019-06-07 00:13:43 -03:00
parent 38e0a1a961
commit ceb812565f
2 changed files with 33 additions and 2 deletions

View file

@ -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."""

View file

@ -1,5 +1,6 @@
import sys
from pathlib import Path
from .error import InterpreterError
def load_file_path(arg: str) -> Path: