mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Windows: improve resgen.py script
This commit is contained in:
committed by
EmilieNumworks
parent
f4b9635fee
commit
42cedf5b10
@@ -25,22 +25,13 @@ SFLAGS += -I$(BUILD_DIR)
|
||||
LDFLAGS += -lgdiplus
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
WINDOWS_ASSETS, \
|
||||
ion/src/simulator/windows/resources.h, \
|
||||
RESGEN, \
|
||||
ion/src/simulator/windows/resources_gen.rc ion/src/simulator/windows/images.h, \
|
||||
$(ion_simulator_assets_paths), \
|
||||
$$(PYTHON) ion/src/simulator/windows/assets.py --files $(ion_simulator_assets) --header-resource-rc $$@, \
|
||||
$$(PYTHON) ion/src/simulator/windows/resgen.py $(ion_simulator_assets) -o $$@, \
|
||||
global \
|
||||
))
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
WINDOWS_ASSETS, \
|
||||
ion/src/simulator/windows/resource_mapping.h, \
|
||||
$(ion_simulator_assets_paths), \
|
||||
$$(PYTHON) ion/src/simulator/windows/assets.py --files $(ion_simulator_assets) --header-resource-mapping $$@, \
|
||||
global \
|
||||
))
|
||||
|
||||
|
||||
$(BUILD_DIR)/ion/src/simulator/windows/images.o: $(BUILD_DIR)/ion/src/simulator/windows/resource_mapping.h
|
||||
$(BUILD_DIR)/ion/src/simulator/windows/resources.o: $(BUILD_DIR)/ion/src/simulator/windows/resources.h
|
||||
$(call object_for,ion/src/simulator/windows/images.cpp): $(BUILD_DIR)/ion/src/simulator/windows/images.h
|
||||
$(call object_for,ion/src/simulator/windows/resources.rc): $(BUILD_DIR)/ion/src/simulator/windows/resources_gen.rc
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
# This script generates two headers:
|
||||
# - the list of the resources to be included in resources.rc
|
||||
# - the mapping of the resource names and identifiers
|
||||
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
import io
|
||||
|
||||
parser = argparse.ArgumentParser(description="Process some windows resources.")
|
||||
parser.add_argument('--files', nargs='+', help='a list of file names')
|
||||
parser.add_argument('--header-resource-rc', help='the .h file to generate to be included in .rc')
|
||||
parser.add_argument('--header-resource-mapping', help='the .h file to generate mapping resource names and identifiers')
|
||||
args = parser.parse_args()
|
||||
|
||||
def process_line(f, line):
|
||||
rc_re = re.compile('^(\d{1,4}) RCDATA "\.\./assets/(.*)"')
|
||||
rc_match = rc_re.match(line)
|
||||
if rc_match:
|
||||
f.write('{"' + rc_match.groups()[1] + '", ' + rc_match.groups()[0] + '},\n')
|
||||
return True
|
||||
return False
|
||||
|
||||
identifier = 300
|
||||
|
||||
def print_declaration(f, asset, identifier):
|
||||
f.write(str(identifier) + " RCDATA " + "../assets/" + asset + "\n")
|
||||
|
||||
def print_mapping(f, asset, identifier):
|
||||
f.write('{"' + asset + '", ' + str(identifier) + '},\n')
|
||||
|
||||
def print_mapping_header(f):
|
||||
f.write("#ifndef ION_SIMULATOR_WINDOWS_RESOURCES_H\n")
|
||||
f.write("#define ION_SIMULATOR_WINDOWS_RESOURCES_H\n\n")
|
||||
f.write("// This file is auto-generated by assets.py\n\n")
|
||||
f.write("constexpr struct {const char * identifier; int id; } resourcesIdentifiers[] = {\n")
|
||||
|
||||
def print_mapping_footer(f):
|
||||
f.write("};\n\n")
|
||||
f.write("#endif\n")
|
||||
|
||||
def print(files, path, print_header, print_footer, process_asset):
|
||||
f = open(path, "w")
|
||||
print_header(f)
|
||||
identifier = 300
|
||||
for asset in files:
|
||||
process_asset(f, asset, identifier)
|
||||
identifier += 1
|
||||
print_footer(f)
|
||||
f.close()
|
||||
|
||||
|
||||
if (args.header_resource_rc):
|
||||
print(args.files, args.header_resource_rc, lambda f: None, lambda f: None, print_declaration)
|
||||
|
||||
if (args.header_resource_mapping):
|
||||
print(args.files, args.header_resource_mapping, print_mapping_header, print_mapping_footer, print_mapping)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "../shared/platform.h"
|
||||
#include <ion/src/simulator/windows/resource_mapping.h>
|
||||
#include <ion/src/simulator/windows/images.h>
|
||||
|
||||
#include <SDL.h>
|
||||
#include <windows.h>
|
||||
@@ -44,8 +44,8 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
LPSTREAM stream;
|
||||
int resourceID = -1;
|
||||
for (size_t i = 0; i < sizeof(resourcesIdentifiers)/sizeof(resourcesIdentifiers[0]); i++) {
|
||||
if (strcmp(identifier, resourcesIdentifiers[i].identifier) == 0) {
|
||||
resourceID = resourcesIdentifiers[i].id;
|
||||
if (strcmp(identifier, resourcesIdentifiers[i].identifier()) == 0) {
|
||||
resourceID = resourcesIdentifiers[i].id();
|
||||
}
|
||||
}
|
||||
assert(resourceID >= 0);
|
||||
|
||||
57
ion/src/simulator/windows/resgen.py
Normal file
57
ion/src/simulator/windows/resgen.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# This script generates two files:
|
||||
# - A .rc: the list of the resources to be included in resources.rc
|
||||
# - A C++ header: the mapping of the resource names and identifiers
|
||||
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
import io
|
||||
|
||||
parser = argparse.ArgumentParser(description="Process some windows resources.")
|
||||
parser.add_argument('assets', metavar='asset', type=str, nargs='+', help='The list of assets')
|
||||
parser.add_argument('-o', required=True, help='The file to generate')
|
||||
args = parser.parse_args()
|
||||
|
||||
def print_declaration(f, asset, identifier):
|
||||
f.write(str(identifier) + ' RCDATA ' + '"../assets/' + asset + '"\n')
|
||||
|
||||
def print_mapping(f, asset, identifier):
|
||||
f.write('ResourceID("' + asset + '", ' + str(identifier) + '),\n')
|
||||
|
||||
def print_mapping_header(f):
|
||||
f.write("#ifndef ION_SIMULATOR_WINDOWS_IMAGES_H\n")
|
||||
f.write("#define ION_SIMULATOR_WINDOWS_IMAGES_H\n\n")
|
||||
f.write("// This file is auto-generated by resgen.py\n\n")
|
||||
f.write("\nclass ResourceID {\n")
|
||||
f.write("public:\n")
|
||||
f.write(" constexpr ResourceID(const char * identifier, int id) : m_identifier(identifier), m_id(id) {}\n")
|
||||
f.write(" const char * identifier() const { return m_identifier; }\n")
|
||||
f.write(" int id() const { return m_id; }\n")
|
||||
f.write("private:\n")
|
||||
f.write(" const char * m_identifier;\n")
|
||||
f.write(" int m_id;\n")
|
||||
f.write("};\n\n")
|
||||
f.write("static constexpr ResourceID resourcesIdentifiers[] = {\n")
|
||||
|
||||
def print_mapping_footer(f):
|
||||
f.write("};\n\n")
|
||||
f.write("#endif\n")
|
||||
|
||||
def print(files, path, print_header, print_footer, process_asset):
|
||||
f = open(path, "w")
|
||||
print_header(f)
|
||||
identifier = 1000
|
||||
for asset in files:
|
||||
process_asset(f, asset, identifier)
|
||||
identifier += 1
|
||||
print_footer(f)
|
||||
f.close()
|
||||
|
||||
|
||||
if (args.o.endswith(".rc")):
|
||||
print(args.assets, args.o, lambda f: None, lambda f: None, print_declaration)
|
||||
|
||||
if (args.o.endswith(".h")):
|
||||
print(args.assets, args.o, print_mapping_header, print_mapping_footer, print_mapping)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <ion/src/simulator/windows/resources.h>
|
||||
#include <ion/src/simulator/windows/resources_gen.rc>
|
||||
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 1,0,0,0
|
||||
|
||||
Reference in New Issue
Block a user