diff --git a/tools/texture_editor.py b/tools/texture_editor.py new file mode 100644 index 000000000..1407df5ea --- /dev/null +++ b/tools/texture_editor.py @@ -0,0 +1,154 @@ +from http.server import BaseHTTPRequestHandler, HTTPServer +from pathlib import Path +import pprint +import time +import glob +import os + +hostName = "localhost" +serverPort = 8080 + +paths = {} + +def dump(obj): + s = '' + for attr in dir(obj): + s = s + "obj.%s = %r" % (attr, getattr(obj, attr)) + "\n" + return s + +def get_png(path): + if path in paths: + return Path(pahts[path]).read_bytes() + for file in glob.glob("../**/" + path, recursive = True): + paths[path] = file + return Path(file).read_bytes() + return + +def scan(): + for file in glob.glob("../**/*.png", recursive = True): + basename = os.path.basename(file) + if basename in paths: + print("Duplicate texture name, please fix:\n * %s:\n - %s\n - %s\n" % (basename, paths[basename], file)) + else: + paths[basename] = file + +def color_picker(): + return """ + +
+ + + """ + + +def get_html(path): + content = "

Request: %s

" % path + content += "" + content += color_picker() + content += "" + content += "" + return content + +class MyServer(BaseHTTPRequestHandler): + def do_GET(self): + path = self.path + if path.endswith(".png"): + content = get_png(path) + self.send_response(200) + self.send_header("Content-type", "image/png") + self.end_headers() + self.wfile.write(content) + else: + content = get_html(path) + self.send_response(200) + self.send_header("Content-type", "text/html") + self.end_headers() + self.wfile.write(bytes(content, "utf-8")) + +if __name__ == "__main__": + scan() + webServer = HTTPServer((hostName, serverPort), MyServer) + print("Server started http://%s:%s" % (hostName, serverPort)) + + try: + webServer.serve_forever() + except KeyboardInterrupt: + pass + + webServer.server_close() + print("Server stopped.")