add unfinished impl for quicksave
This commit is contained in:
parent
38e0a1a961
commit
ceb812565f
|
@ -1,5 +1,8 @@
|
||||||
import sys
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from .utils import load_file_path
|
from .utils import load_file_path
|
||||||
from .error import InterpreterError
|
from .error import InterpreterError
|
||||||
|
|
||||||
|
@ -7,13 +10,40 @@ from .error import InterpreterError
|
||||||
class Interpreter:
|
class Interpreter:
|
||||||
"""Interpreter for scritcher instructions/statements."""
|
"""Interpreter for scritcher instructions/statements."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.orig_path = None
|
||||||
self.loaded_path = None
|
self.loaded_path = None
|
||||||
|
|
||||||
def _cmd_noop(self):
|
def _cmd_noop(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _cmd_load(self, loadpath: str):
|
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):
|
def run(self, line: str):
|
||||||
"""Run a single line."""
|
"""Run a single line."""
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .error import InterpreterError
|
from .error import InterpreterError
|
||||||
|
|
||||||
def load_file_path(arg: str) -> Path:
|
def load_file_path(arg: str) -> Path:
|
||||||
|
|
Loading…
Reference in New Issue