diff --git a/addons/godot-version-management/LICENSE b/addons/godot-version-management/LICENSE new file mode 100644 index 0000000..743520c --- /dev/null +++ b/addons/godot-version-management/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Tomek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/addons/godot-version-management/README.md b/addons/godot-version-management/README.md new file mode 100644 index 0000000..40a0123 --- /dev/null +++ b/addons/godot-version-management/README.md @@ -0,0 +1,70 @@ +# Godot Version Manager + + + +This addon is for developpers that want a centralized place for version naming / build number and then display it in game. + +It allow you to configure version and build in project settings. + +These configurations are synchronized to all existing export of your project. + +Moreover configurations can be loaded for in game display. + +## How to install it + +You can find this addon in Godot AssetLibrary +See the Godot Addon install section : https://docs.godotengine.org/en/stable/tutorials/plugins/editor/installing_plugins.html + +## How to use it for exports + +Once the addon activated it add two entry in your project configuration: + +- Application / Config / Version as String (application/config/version default to 0.0.1) +- Application / Config / Build as Integer (application/config/build default to 1) + +You can change the version and the build numbers. +It will update all your exports versions value to the project config value. +Then you need to reload the project (Project / Reload current project). + +See below section to know why you need to reload project. + +For Android exports: +* version is version/name +* build is version/code + +For iOS and MacOS exports: +* version is application/short_version +* build is application/version + +For Windows Desktop exports: +* version is application/file_version and application/product_version + +For HTML5 and UWP exports no versions specified. + +## How to use it for in game display + +The version and build numbers can be accessed for in game use like that: + + +```GDScript + # To get version string + var version = ProjectSettings.get_setting("application/config/version") + # To get build number + var build = ProjectSettings.get_setting("application/config/build") +``` + + + + +## Why I need to reload project ? + +The GodotVersionManager addon update the export-presets.cfg file. + +Because of Godot keep in memory ExportsSettings and do not reload it from export-presets.cfg file you will need to reload your project. + +When project is loaded Godot load in memory the export-presets.cfg . + +## Support Me + +You to buy me a coffee ? +Buy Me a Coffee diff --git a/addons/godot-version-management/godot_version_manager.gd b/addons/godot-version-management/godot_version_manager.gd new file mode 100644 index 0000000..d7fea72 --- /dev/null +++ b/addons/godot-version-management/godot_version_manager.gd @@ -0,0 +1,78 @@ +# By Erasor +tool +extends EditorPlugin + +const PLUGIN_NAME = "Godot-Version-Manager" +const DEBUG = true +# Use same name as https://github.com/godotengine/godot/pull/35555 +const PROJECT_VERSION_SETTING = "application/config/version" +const PROJECT_BUILD_SETTING = "application/config/build" +const EXPORT_PRESETS_FILE = "res://export_presets.cfg" +var current_version +var current_build + +func _enter_tree(): + if not ProjectSettings.has_setting(PROJECT_VERSION_SETTING): + ProjectSettings.set_setting(PROJECT_VERSION_SETTING, "0.0.1") + if not ProjectSettings.has_setting(PROJECT_BUILD_SETTING): + ProjectSettings.set_setting(PROJECT_BUILD_SETTING, 1) + current_version = ProjectSettings.get_setting(PROJECT_VERSION_SETTING) + current_build = ProjectSettings.get_setting(PROJECT_BUILD_SETTING) + + +func _exit_tree(): + # Do not remove the verson config, may conflict with https://github.com/godotengine/godot/pull/35555 + pass + + +func apply_changes(): + _update_export_presets() + + +func save_external_data(): + _update_export_presets() + + +func _update_export_presets(): + # If config version changed, update all exports + if ProjectSettings.get_setting(PROJECT_VERSION_SETTING) != current_version: + var export_config: ConfigFile = ConfigFile.new() + var err = export_config.load(EXPORT_PRESETS_FILE) + if err == OK: + # Loop limited to 100 exports + for i in range(0, 100): + var section = "preset." + str(i) + if export_config.has_section(section): + plugin_log("Update Export " + export_config.get_value(section, "platform")) + # Update Android exports configs + if export_config.get_value(section, "platform") == "Android": + export_config.set_value(section + ".options", 'version/name', ProjectSettings.get_setting(PROJECT_VERSION_SETTING)) + export_config.set_value(section + ".options", 'version/code', ProjectSettings.get_setting(PROJECT_BUILD_SETTING)) + if export_config.get_value(section, "platform") == "iOS" or export_config.get_value(section, "platform") == "Mac OSX": + export_config.set_value(section + ".options", 'application/short_version', ProjectSettings.get_setting(PROJECT_VERSION_SETTING)) + export_config.set_value(section + ".options", 'application/version', ProjectSettings.get_setting(PROJECT_BUILD_SETTING)) + if export_config.get_value(section, "platform") == "UWP": + # TODO parsing of version to minor/major + pass + if export_config.get_value(section, "platform") == "Windows Desktop": + export_config.set_value(section + ".options", 'application/file_version', ProjectSettings.get_setting(PROJECT_VERSION_SETTING)) + export_config.set_value(section + ".options", 'application/product_version', ProjectSettings.get_setting(PROJECT_VERSION_SETTING)) + else: + break + err = export_config.save(EXPORT_PRESETS_FILE) + ProjectSettings.save() + if err == OK: + plugin_log("All exports updated") + else: + plugin_log("Error saving " + EXPORT_PRESETS_FILE + ", exports not updated") + else: + plugin_log('Error open ' + EXPORT_PRESETS_FILE) + + +func plugin_log(message): + if (DEBUG): + var time : Dictionary = OS.get_datetime() + var date_string : String = "%02d:%02d" % [time.hour, time.minute] + print(date_string, " - ", PLUGIN_NAME, " - ", message) + + diff --git a/addons/godot-version-management/plugin.cfg b/addons/godot-version-management/plugin.cfg new file mode 100644 index 0000000..52c8d5a --- /dev/null +++ b/addons/godot-version-management/plugin.cfg @@ -0,0 +1,8 @@ +[plugin] + +name="Godot-Version-Manager" +description="Godot plugin to manage versions for exports. +It centralize the version number in project." +author="Erasor" +version="1.0.0" +script="godot_version_manager.gd" diff --git a/project.godot b/project.godot index 207342a..40e806f 100644 --- a/project.godot +++ b/project.godot @@ -115,6 +115,8 @@ run/main_scene="res://scenes/Game.tscn" config/icon="res://icon.png" config/macos_native_icon="res://icon.icns" config/windows_native_icon="res://icon.ico" +config/version="0.0.1" +config/build=1000 [autoload] @@ -132,7 +134,7 @@ window/stretch/aspect="keep" [editor_plugins] -enabled=PoolStringArray( "res://addons/beehave/plugin.cfg" ) +enabled=PoolStringArray( "res://addons/beehave/plugin.cfg", "res://addons/godot-version-management/plugin.cfg" ) [gdnative] diff --git a/scenes/game.tscn b/scenes/game.tscn index 137f9be..e471677 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -293,6 +293,16 @@ __meta__ = { "_edit_use_anchors_": true } +[node name="VersionLbl" type="Label" parent="Controls/Control Panel/Windows"] +anchor_left = 0.0146199 +anchor_top = 0.0271318 +anchor_right = 0.182261 +anchor_bottom = 0.0542636 +text = "Version" +__meta__ = { +"_edit_use_anchors_": true +} + [node name="Status" type="Panel" parent="Controls/Control Panel"] anchor_top = 12.95 anchor_right = 25.65 diff --git a/scripts/windows.gd b/scripts/windows.gd index 7044d86..c7b6dcd 100644 --- a/scripts/windows.gd +++ b/scripts/windows.gd @@ -5,7 +5,16 @@ onready var tax_window = $TaxWindow onready var advsior_meet_window = $AdvisorMeet onready var tools_window = $ToolsWindow +onready var verLabel = $VersionLbl + func _ready(): + # To get version string + var version = ProjectSettings.get_setting("application/config/version") + # To get build number + var build = ProjectSettings.get_setting("application/config/build") + + verLabel.text = version + " (Build " + str(build) + ")" + SimData.city_name = SimData.city_name.capitalize() SimData.mayor_name = SimData.mayor_name.capitalize()