mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-22 18:52:30 +01:00
67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
import json
|
|
import os.path
|
|
|
|
def createEnum(name,valueList):
|
|
enum_string_values = "\n"
|
|
|
|
for value in valueList:
|
|
# QML enums must start with uppercase Qt < 6
|
|
value_name = value["name"]
|
|
value_name = value_name[0].upper() + value_name[1:]
|
|
enum_string_values += "\t" + value_name + " = " + value["value"]
|
|
enum_string_values += ",\n"
|
|
|
|
enum_string = "enum class "
|
|
enum_string += name
|
|
enum_string += "\n{"
|
|
enum_string += "\t"+ enum_string_values
|
|
enum_string += " };"
|
|
enum_string += "\nQ_ENUM_NS(" + name +")"
|
|
enum_string += "\n\n"
|
|
return enum_string
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print("Update enums")
|
|
my_path = os.path.abspath(os.path.dirname(__file__))
|
|
path = os.path.join(my_path, "public/steam/steam_api.json")
|
|
|
|
file_begin = """// GENERATED FILE DO NOT EDIT
|
|
// TO REGENERATE run ScreenPlayInternal\SteamSDK
|
|
// > python.exe updateEnums.py
|
|
|
|
#pragma once
|
|
#include <QObject>
|
|
|
|
namespace ScreenPlayWorkshopSteamEnums {
|
|
|
|
Q_NAMESPACE
|
|
|
|
"""
|
|
|
|
file_end = """
|
|
|
|
}
|
|
"""
|
|
|
|
with open(path) as json_file:
|
|
data = json.load(json_file)
|
|
enum_list = data["enums"]
|
|
|
|
list = []
|
|
file_content = ""
|
|
for enumObj in enum_list:
|
|
file_content += createEnum(enumObj["enumname"],enumObj["values"])
|
|
|
|
file_complete = file_begin
|
|
file_complete += file_content
|
|
file_complete += file_end
|
|
|
|
with open('public/steam/steam_qt_enums_generated.h', 'w') as outfile:
|
|
outfile.write(file_complete)
|
|
|
|
print("Update write")
|
|
|
|
|