Start of editor, basic CLI for now
This commit is contained in:
parent
a97080f8e1
commit
b868a5e08a
Binary file not shown.
|
@ -0,0 +1,90 @@
|
|||
import sys
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import curses
|
||||
|
||||
def fix(x):
|
||||
return int(x*65536)
|
||||
|
||||
class raycastMap:
|
||||
w = 0
|
||||
h = 0
|
||||
d = 0
|
||||
floor = []
|
||||
wall = []
|
||||
sprite_count = 0
|
||||
sprites = []
|
||||
|
||||
def parseout(self):
|
||||
out = json.JSONEncoder().encode({\
|
||||
"w":self.w,\
|
||||
"h":self.h,\
|
||||
"d":self.d,\
|
||||
"floor":self.floor,\
|
||||
"wall":self.wall,\
|
||||
"sprite_count":self.sprite_count,\
|
||||
"sprites":self.sprites\
|
||||
})
|
||||
|
||||
return out
|
||||
|
||||
def __init__(self, w, h, d):
|
||||
self.w = w
|
||||
self.h = h
|
||||
self.d = d
|
||||
for i in range(0, w*h):
|
||||
self.floor.append(0)
|
||||
for i in range(0, w*h*d):
|
||||
self.wall.append(0)
|
||||
|
||||
def helppage():
|
||||
print("usage : python3 raycastedit.py [options] [file]")
|
||||
print("If [file] exists and is in .rcmap format, il will be edited")
|
||||
print("Otherwise, the editor will attempt to create [file]")
|
||||
print("Options :")
|
||||
print("-h : display this page")
|
||||
print("-n W H D : Create a new empty map in [file], if it doesn't exist")
|
||||
print(" already, of width W, height H and depth D")
|
||||
|
||||
def seehelppls():
|
||||
print('See usage with "--help or "-h"')
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("No file provided !")
|
||||
seehelppls()
|
||||
os._exit(1)
|
||||
|
||||
def gen_ne(filename, w, h, d):
|
||||
try:
|
||||
nfile = open(filename, mode="x+t", buffering=1, encoding="utf-8", newline="\n")
|
||||
except:
|
||||
print("Error creating file !")
|
||||
return 1
|
||||
nmap = raycastMap(w, h ,d)
|
||||
nfile.write(nmap.parseout())
|
||||
nfile.write("\n")
|
||||
|
||||
for i in range(1, len(sys.argv)):
|
||||
option_set = -1
|
||||
if sys.argv[i] == "-h":
|
||||
helppage()
|
||||
os._exit(0)
|
||||
if sys.argv[i] == "-n":
|
||||
i+=3
|
||||
try:
|
||||
filename = sys.argv[-1]
|
||||
w = int(sys.argv[i-2])
|
||||
h = int(sys.argv[i-1])
|
||||
d = int(sys.argv[i])
|
||||
except:
|
||||
print("Invalid use of option -n !")
|
||||
seehelppls()
|
||||
os._exit(1)
|
||||
gen_ne(filename, w, h, d)
|
||||
os._exit(0)
|
||||
if option_set == -1:
|
||||
print('Invalid option "'+sys.argv[i]+'" !')
|
||||
seehelppls()
|
||||
|
||||
|
|
@ -28,9 +28,8 @@ except:
|
|||
folder = os.listdir(path=maps_path)
|
||||
|
||||
for i in range(0, len(folder)):
|
||||
flen = len(folder[i])-1
|
||||
extention = folder[i].split(".")
|
||||
extention = extention[len(extention)-1]
|
||||
extention = extention[-1]
|
||||
if extention == "rcmap":
|
||||
continue
|
||||
else:
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue