Skip to content

Commit 5a378b1

Browse files
improve conventions
1 parent 20702b0 commit 5a378b1

File tree

14 files changed

+138
-47
lines changed

14 files changed

+138
-47
lines changed

.github/workflows/gdlint.yml renamed to .github/workflows/quality_check.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# Workflow to automatically lint gdscript code
2-
name: gdlint on push
1+
# Workflow to ensure quality of the code.
2+
name: quality-check
33

44
on:
55
[push, pull_request]
66

77
jobs:
8+
# Job to automatically lint gdscript code
89
gdlint:
9-
name: gdlint code
10+
name: checkstyle gdlint
1011
runs-on: ubuntu-latest
1112

1213
# The allowed amount of linter problems

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@
3636

3737
## 📜 Conventions
3838

39-
- Code
39+
- Readable Code
4040
- Use **snake_case** for files, folders, variables, functions.
4141
- Use **PascalCase** for nodes, classes, enums, types.
4242
- Use **typed** variables and functions.
4343
- Use **style** inspired by [GDScript Style](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_styleguide.html) (see *gdlintrc*).
44+
- Ensure **order of functions** (top to bottom of file):
45+
- [overrides](https://docs.godotengine.org/en/stable/tutorials/scripting/overridable_functions.html) > public > private
46+
- instance > static
47+
- Naming variables
48+
- consider class name suffix
49+
- consider `_id` suffix for `String` referencing a resource
4450

4551

4652
## 🧩 Plugins
@@ -93,7 +99,7 @@ Otherwise, Scenes must be loaded or added to the Scene Tree.
9399
- **SignalBus**
94100
- TODO
95101

96-
- **Wrapper**
102+
- **Wrapper** : *Extend functionality of a Plugin without modifying the original.*
97103
- **SceneManagerWrapper** - call SceneManager with options presets Resource.
98104

99105
### 🎬 Scenes
@@ -110,9 +116,11 @@ Otherwise, Scenes must be loaded or added to the Scene Tree.
110116
### 📄 Scripts
111117

112118
- **Objects**
113-
- **ConfigManager** - Use to persist (save & load) app settings, stats, etc.
114-
- **AppLogConfig** - TODO
115-
- TODO
119+
- **ConfigManager** - Persists (save & load) app settings (global app data).
120+
- **ConfigManagerAppLog**
121+
- **ConfigManagerSettingsAudio**
122+
- **ConfigManagerSettingsControl**
123+
- **ConfigManagerSettingsVideo**
116124

117125
- **Utils**
118126
- **FileSystemUtils**
@@ -132,8 +140,8 @@ Otherwise, Scenes must be loaded or added to the Scene Tree.
132140

133141
### ✅ Workflows
134142

135-
- **gdlint**
136-
- On git push, automatically check *gdlintrc* coding style standards.
143+
- **quality_check.yml**
144+
- Automatically check *gdlintrc* coding style standards.
137145

138146
### ⚡ Hacks
139147

@@ -149,7 +157,7 @@ Otherwise, Scenes must be loaded or added to the Scene Tree.
149157

150158
### ❓ FAQ
151159

152-
- I have errors/warnings when opening the project for the first time?
160+
- Opening the project for the first time, I have errors/warnings?
153161
- Try (re)enable all Plugins and then select "Reload Current Project".
154162

155163

godot/autoload/configuration/configuration.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ extends Node
44
func _ready() -> void:
55
Log.debug("AUTOLOAD READY: ", name)
66

7+
ConfigManagerAppLog.app_opened()
8+
79
if OS.is_debug_build():
810
_init_debug_configuration()
911
else:
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1+
## Preloads all resources (.tres files) in /resources.
2+
## Holds references to resources in dictionary by name as key.
3+
## The key also holds a prefix to avoid conflicts of equal names across different resources.
14
extends Node
25

36
const RESOURCE_EXTENSION = ".tres"
47

58
var _resource_references: Dictionary = {}
69

710

8-
func get_scene_manager_options(resource_name: String) -> SceneManagerOptions:
9-
return _get_resource(resource_name, SceneManagerOptions)
10-
11-
12-
func _get_resource(resource_name: String, type: Variant) -> Resource:
13-
var key: String = _get_key(resource_name, type)
14-
return _resource_references[key]
15-
16-
1711
func _ready() -> void:
1812
Log.debug("AUTOLOAD READY: ", name)
1913

2014
var paths: Array[String] = FileSystemUtils.get_paths(PathConsts.RESOURCES, RESOURCE_EXTENSION)
2115
_resource_references = _load_resources(paths)
2216

2317

18+
func get_scene_manager_options(resource_id: String) -> SceneManagerOptions:
19+
return get_resource(resource_id, SceneManagerOptions)
20+
21+
22+
func get_resource(resource_id: String, type: Variant) -> Resource:
23+
var key: String = _get_key(resource_id, type)
24+
return _resource_references[key]
25+
26+
2427
static func _load_resources(paths: Array[String]) -> Dictionary:
2528
var resource_references: Dictionary = {}
2629
for path: String in paths:
2730
var resource: Resource = load(path) as Resource
2831
if resource != null:
29-
var resource_name: String = FileSystemUtils.get_file_name(path)
30-
var key: String = _get_key(resource_name, _get_type(resource))
32+
var resource_id: String = FileSystemUtils.get_file_name(path)
33+
var key: String = _get_key(resource_id, _get_type(resource))
3134
if resource_references.has(key):
3235
Log.warn("Duplicate resource reference key: ", key)
3336
continue
@@ -42,5 +45,5 @@ static func _get_type(resource: Resource) -> Variant:
4245
return resource.get_script()
4346

4447

45-
static func _get_key(resource_name: String, type: Variant) -> String:
46-
return type.get_global_name() + "-" + resource_name
48+
static func _get_key(resource_id: String, type: Variant) -> String:
49+
return type.get_global_name() + "-" + resource_id

godot/autoload/wrapper/scene_manager_wrapper/scene_manager_wrapper.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ func _ready() -> void:
66

77

88
## Change scene using preset options.
9-
func change_scene(scene_name: String, scene_manager_options_name: String) -> void:
9+
func change_scene(scene_id: String, scene_manager_options_id: String) -> void:
1010
var scene_manager_options: SceneManagerOptions = Reference.get_scene_manager_options(
11-
scene_manager_options_name
11+
scene_manager_options_id
1212
)
1313
SceneManager.change_scene(
14-
scene_name,
14+
scene_id,
1515
scene_manager_options.create_fade_out_options(),
1616
scene_manager_options.create_fade_in_options(),
1717
scene_manager_options.create_general_options()

godot/project.godot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Log/break_on_error=false
2424
[application]
2525

2626
config/name="TakinGodotTemplate"
27+
config/version="0.0"
2728
run/main_scene="res://scenes/view/boot_splash/boot_splash.tscn"
2829
config/features=PackedStringArray("4.3", "GL Compatibility")
2930
boot_splash/bg_color=Color(0, 0, 0, 1)

godot/scenes/component/.gitkeep

Whitespace-only changes.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
extends Control
22

33
@export_group("Next Scene")
4-
@export var scene: String = "main_menu"
5-
@export var scene_manager_options: String = "fade_basic"
4+
@export var scene_id: String = "main_menu"
5+
@export var scene_manager_options_id: String = "fade_basic"
66

77
var _boot_splash_color: Color = ProjectSettings.get("application/boot_splash/bg_color")
8-
var _boot_splash_image: String = ProjectSettings.get("application/boot_splash/image")
9-
var _boot_splash_texture: Texture = load(_boot_splash_image)
8+
var _boot_splash_image_path: String = ProjectSettings.get("application/boot_splash/image")
9+
var _boot_splash_texture: Texture = load(_boot_splash_image_path)
1010

1111
@onready var boot_splash_color_rect: ColorRect = %BootSplashColorRect
1212
@onready var boot_splash_texture_rect: TextureRect = %BootSplashTextureRect
@@ -18,4 +18,4 @@ func _ready() -> void:
1818
boot_splash_color_rect.color = _boot_splash_color
1919
boot_splash_texture_rect.texture = _boot_splash_texture
2020

21-
SceneManagerWrapper.change_scene(scene, scene_manager_options)
21+
SceneManagerWrapper.change_scene(scene_id, scene_manager_options_id)

godot/scripts/objects/config_manager/config_manager.gd

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
## Modified File MIT License Copyright (c) 2024 TinyTakinTeller
22
## Original File MIT License Copyright (c) 2022-present Marek Belski
3+
4+
## Persists data in a INI-style file.
35
class_name ConfigManager
46
extends Object
57

6-
const CONFIG_FILE_NAME: String = "user_config"
8+
const CONFIG_FILE_NAME: String = "config"
79
const CONFIG_FILE_PATH: String = PathConsts.USER + CONFIG_FILE_NAME + ".cfg"
810

9-
static var config_file: ConfigFile
11+
static var config_file: ConfigFile = null
1012

1113

1214
static func _init() -> void:
1315
_load_config_file()
1416

1517

16-
static func _load_config_file(create_on_not_found: bool = true) -> void:
17-
if config_file != null:
18-
return
19-
config_file = ConfigFile.new()
20-
var err_file_cant_open: int = config_file.load(CONFIG_FILE_PATH)
21-
if err_file_cant_open and create_on_not_found:
22-
_save_config_file()
18+
static func increment_config(section: String, key: String) -> void:
19+
_load_config_file()
20+
var value: int = ConfigManager.get_config(section, key, 0)
21+
ConfigManager.set_config(section, key, value + 1)
22+
_save_config_file()
2323

2424

25-
static func _save_config_file() -> void:
26-
var save_error: int = config_file.save(CONFIG_FILE_PATH)
27-
if save_error:
28-
Log.err("Save config file failed with error ", save_error)
25+
static func set_empty_config(section: String, key: String, value: Variant) -> void:
26+
_load_config_file()
27+
config_file.set_value(section, key, value)
28+
_save_config_file()
2929

3030

3131
static func set_config(section: String, key: String, value: Variant) -> void:
@@ -50,12 +50,14 @@ static func has_section_key(section: String, key: String) -> bool:
5050

5151

5252
static func erase_section(section: String) -> void:
53+
_load_config_file()
5354
if has_section(section):
5455
config_file.erase_section(section)
5556
_save_config_file()
5657

5758

5859
static func erase_section_key(section: String, key: String) -> void:
60+
_load_config_file()
5961
if has_section_key(section, key):
6062
config_file.erase_section_key(section, key)
6163
_save_config_file()
@@ -66,3 +68,23 @@ static func get_section_keys(section: String) -> PackedStringArray:
6668
if config_file.has_section(section):
6769
return config_file.get_section_keys(section)
6870
return PackedStringArray()
71+
72+
73+
## reads config file from file system if it is not already read, ensuring we can write updates to it
74+
static func _load_config_file(create_on_not_found: bool = true) -> void:
75+
if config_file != null:
76+
return
77+
config_file = ConfigFile.new()
78+
var err_file_cant_open: int = config_file.load(CONFIG_FILE_PATH)
79+
if err_file_cant_open and create_on_not_found:
80+
_save_config_file()
81+
82+
83+
## writes config file to file system after it is updated
84+
static func _save_config_file() -> void:
85+
if config_file == null:
86+
Log.err("Save config file failed because it is not loaded.")
87+
return
88+
var save_error: int = config_file.save(CONFIG_FILE_PATH)
89+
if save_error:
90+
Log.err("Save config file failed with error ", save_error)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Modified File MIT License Copyright (c) 2024 TinyTakinTeller
2+
## Original File MIT License Copyright (c) 2022-present Marek Belski
3+
4+
class_name ConfigManagerAppLog
5+
extends Node
6+
7+
const APP_LOG_SECTION: String = "AppLog"
8+
9+
const APP_OPENED_COUNT_KEY: String = "AppOpenedCount"
10+
const APP_FIRST_VERSION_OPENED_KEY: String = "AppFirstVersionOpened"
11+
const APP_LAST_VERSION_OPENED_KEY: String = "AppLastVersionOpened"
12+
13+
14+
static func app_opened() -> void:
15+
_update_app_opened_count()
16+
17+
var app_version: String = ProjectSettings.get_setting("application/config/version", "0")
18+
_update_app_first_version_opened(app_version)
19+
_update_app_last_version_opened(app_version)
20+
21+
22+
static func _update_app_opened_count() -> void:
23+
ConfigManager.increment_config(APP_LOG_SECTION, APP_OPENED_COUNT_KEY)
24+
25+
26+
static func _update_app_first_version_opened(new_value: String) -> void:
27+
var value: String = ConfigManager.get_config(APP_LOG_SECTION, APP_FIRST_VERSION_OPENED_KEY, "")
28+
if value == "":
29+
ConfigManager.set_config(APP_LOG_SECTION, APP_FIRST_VERSION_OPENED_KEY, new_value)
30+
31+
32+
static func _update_app_last_version_opened(new_value: String) -> void:
33+
ConfigManager.set_config(APP_LOG_SECTION, APP_LAST_VERSION_OPENED_KEY, new_value)

0 commit comments

Comments
 (0)