Skip to content

Commit

Permalink
ADF-29 | misc. settings (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyTakinTeller authored Jul 14, 2024
1 parent 6ab0bbb commit b3a25ef
Show file tree
Hide file tree
Showing 54 changed files with 671 additions and 225 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/gdlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ jobs:
name: gdlint code
runs-on: ubuntu-latest

# workaround for locally running 'act -j gdlint' : https://github.com/nektos/act/issues/1856#issuecomment-1679427871
#container:
# image: ghcr.io/catthehacker/ubuntu:act-latest

# The allowed amount of linter problems
env:
PROBLEMS_THRESHOLD: 88 # The allowed amount of linter problems
PROBLEMS_THRESHOLD: 0

steps:
# Check out the repository
- name: Checkout
uses: actions/checkout@v4

#- name: LSB
# run: apt-get update && apt-get install -y lsb-release && apt-get clean all

# Ensure python is installed
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"

# Install gdtoolkit
- name: Install Dependencies
Expand All @@ -40,8 +48,9 @@ jobs:
- name: Check linter results
run: |
PROBLEMS=$(grep -oP 'Failure: \K\d+' gdlint_output.txt || echo "0")
echo "Problems found: $PROBLEMS"
echo "Problems found: $PROBLEMS, threshold is: $PROBLEMS_THRESHOLD"
if [ "$PROBLEMS" -gt "$PROBLEMS_THRESHOLD" ]; then
echo "Too many linter problems"
echo "Too many linter problems!"
exit 1
fi
2 changes: 1 addition & 1 deletion global/autoload/resources.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ var enemy_image: Dictionary = FileSystemUtils.get_image_resources("enemy", true)


func _ready() -> void:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("_AUTOLOAD _READY: " + self.get_name())
64 changes: 46 additions & 18 deletions global/autoload/save_file/save_file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Node

const SIGNATURE = "$$$"
const SAVE_FILE_EXTENSION = ".json"
const AUTOSAVE_SECONDS: int = Game.params["autosave_seconds"]
const AUTOSAVE_SECONDS: int = Game.PARAMS["autosave_seconds"]

var active_file_name: String = "default"
var save_datas: Dictionary = {}
Expand All @@ -15,12 +15,17 @@ var resource_generator_unlocks: Array = ["land"]
var worker_role_unlocks: Array = []
var tab_unlocks: Array = ["world", "settings"]
var tab_levels: Dictionary = {"world": 0}
var settings: Dictionary = {"theme": "dark"}
var settings: Dictionary = {
"theme": "dark", "display_mode": "windowed", "display_resolution": [960, 540]
}
var audio_settings: Dictionary = {
"master": {"value": 1.00, "toggle": true},
"music": {"value": 0.80, "toggle": true},
"sfx": {"value": 0.50, "toggle": true}
}
var effect_settings: Dictionary = {
"shake": {"value": 0.20, "toggle": true}, "typing": {"value": 0.40, "toggle": true}
}
var npc_events: Dictionary = {}
var enemy: Dictionary = {"level": "rabbit", "rabbit": {"damage": 0}}
var metadata: Dictionary = {}
Expand All @@ -37,7 +42,7 @@ func _ready() -> void:
_load_save_files()
_connect_signals()

if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("_AUTOLOAD _READY: " + self.get_name())


Expand Down Expand Up @@ -76,7 +81,7 @@ func get_enemy_damage(enemy_id: String = "") -> int:


func get_settings_theme(save_file_name: String) -> Resource:
var theme_id: String = Game.params["default_theme"]
var theme_id: String = Game.PARAMS["default_theme"]
if !save_datas.has(save_file_name):
return Resources.theme.get(theme_id, null)

Expand All @@ -90,6 +95,13 @@ func get_settings_population_scale() -> int:
return settings.get("population_scale", 1)


func is_typing_effect_enabled() -> bool:
return (
effect_settings.get("typing", {}).get("toggle", false)
and effect_settings.get("typing", {}).get("value", 0.0) > 0.0
)


#############
## setters ##
#############
Expand Down Expand Up @@ -142,7 +154,7 @@ func set_metadata_name(save_file_name: String, value: String) -> void:


func initialize(save_file_name: String, metadata_name: String) -> void:
if !Game.params["save_system_enabled"]:
if !Game.PARAMS["save_system_enabled"]:
return

var file_name: String = save_file_name + SAVE_FILE_EXTENSION
Expand All @@ -161,7 +173,7 @@ func initialize(save_file_name: String, metadata_name: String) -> void:
func delete(save_file_name: String) -> void:
var file_name: String = save_file_name + SAVE_FILE_EXTENSION
var error: Error = DirAccess.remove_absolute(FileSystemUtils.USER_PATH + file_name)
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("Delete save file '" + save_file_name + "' response: " + str(error))
save_datas.erase(save_file_name)

Expand Down Expand Up @@ -212,15 +224,15 @@ func _get_seconds_since_last_autosave() -> int:


func _load_save_files() -> void:
if !Game.params["save_system_enabled"]:
if !Game.PARAMS["save_system_enabled"]:
return

for file_name: String in FileSystemUtils.get_user_files():
if !file_name.ends_with(SAVE_FILE_EXTENSION):
continue
var save_data: Dictionary = _read(file_name)
_check_backward_compatibility(save_data)
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__LOAD_SAVE_DATA: " + file_name)
print(save_data)
if save_data == null or save_data.is_empty():
Expand All @@ -241,6 +253,7 @@ func _export_save_data() -> Dictionary:
save_data["tab_levels"] = tab_levels
save_data["settings"] = settings
save_data["audio_settings"] = audio_settings
save_data["effect_settings"] = effect_settings
save_data["npc_events"] = npc_events
save_data["enemy"] = enemy
save_data["metadata"] = metadata
Expand All @@ -259,6 +272,7 @@ func _import_save_data(save_data: Dictionary) -> void:
tab_levels = _get_tab_levels(save_data)
settings = _get_settings(save_data)
audio_settings = _get_audio_settings(save_data)
effect_settings = _get_effect_settings(save_data)
npc_events = _get_npc_events(save_data)
enemy = _get_enemy(save_data)
metadata = _get_metadata(save_data)
Expand Down Expand Up @@ -305,6 +319,10 @@ func _get_audio_settings(save_data: Dictionary) -> Dictionary:
return save_data.get("audio_settings", audio_settings)


func _get_effect_settings(save_data: Dictionary) -> Dictionary:
return save_data.get("effect_settings", effect_settings)


func _get_npc_events(save_data: Dictionary) -> Dictionary:
return save_data.get("npc_events", npc_events)

Expand Down Expand Up @@ -353,6 +371,14 @@ func _check_backward_compatibility(save_data: Dictionary) -> void:
_check_backward_week_7(save_data)
_check_backward_week_10(save_data)
_check_backward_corrupt_worker_role(save_data)
_check_backward_week_11(save_data)


func _check_backward_week_11(save_data: Dictionary) -> void:
if !save_data["settings"].has("display_mode"):
save_data["settings"]["display_mode"] = settings["display_mode"]
if !save_data["settings"].has("display_resolution"):
save_data["settings"]["display_resolution"] = settings["display_resolution"]


## [WORKAROUND] for #ADF-27 | https://trello.com/c/7VNXK6xW
Expand All @@ -373,7 +399,7 @@ func _check_backward_corrupt_worker_role(save_data: Dictionary) -> void:
var worker_resources: int = save_data["resources"].get(Game.WORKER_RESOURCE_ID, 0)
var error: int = worker_resources - total_roles
if error != 0:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print(
(
"[WORKAROUND] workers error: "
Expand Down Expand Up @@ -434,7 +460,7 @@ func _connect_signals() -> void:


func _connect_autosave_timer() -> void:
if Game.params["autosave_enabled"]:
if Game.PARAMS["autosave_enabled"]:
autosave_timer.wait_time = 0.1
autosave_timer.timeout.connect(_on_timeout)
autosave_timer.start()
Expand All @@ -452,7 +478,9 @@ func _on_offline_progress_processed(
_seconds_delta: int, _worker_progress: Dictionary, _enemy_progress: Dictionary, _factor: float
) -> void:
_autosave(true, true)
SignalBus.worker_updated.emit(Game.WORKER_RESOURCE_ID, workers[Game.WORKER_RESOURCE_ID], 0)
SignalBus.worker_updated.emit(
Game.WORKER_RESOURCE_ID, workers.get(Game.WORKER_RESOURCE_ID, 0), 0
)


##############
Expand All @@ -476,31 +504,31 @@ func _write(file_name: String) -> void:

func _read(file_name: String) -> Dictionary:
var path: String = FileSystemUtils.USER_PATH + file_name
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print()
print("__READ_FILE: " + file_name)

var save_file: FileAccess = FileAccess.open(path, FileAccess.READ)
if save_file == null:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__READ_NULL")
return {}
var content: String = save_file.get_as_text()
save_file.close()

content = _handle_corrupt_end_of_file(content)
content = content.replace(SIGNATURE, "")
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__READ_CONTENT: " + content)

var json_object: JSON = _parse(content)
if json_object == null:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__READ_PARSE_FAILED")
return {}
var save_data: Dictionary = json_object.get_data()

if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__READ_DONE")

return save_data
Expand All @@ -510,11 +538,11 @@ func _parse(content: String, retry: bool = true) -> JSON:
var json_object: JSON = JSON.new()
var parse_err: Error = json_object.parse(content)
if parse_err != Error.OK:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__READ_PARSE_ERROR: " + str(parse_err))
if retry:
var retry_content: String = StringUtils.sanitize_text(content, StringUtils.ASCII)
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("__READ_RETRY_PARSE_WITH_FORCE_ASCII_CONTENT: " + retry_content)
return _parse(retry_content, false)
return null
Expand Down
8 changes: 7 additions & 1 deletion global/autoload/signal_bus/signal_bus.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ signal resource_storage_unhover(resource: ResourceGenerator)
signal deaths_door_open(enemy_data: EnemyData)
signal deaths_door(enemy_data: EnemyData, option: int)
signal audio_settings_update(toggle: bool, value: float, id: String)
signal effect_settings_update(toggle: bool, value: float, id: String)
signal display_mode_settings_toggle
signal display_resolution_settings_toggle

## CONTROLLER
signal main_ready
Expand Down Expand Up @@ -52,6 +55,9 @@ signal offline_progress_processed(
seconds_delta: int, worker_progress: Dictionary, enemy_progress: Dictionary, factor: float
)
signal audio_settings_updated(toggle: bool, value: float, id: String)
signal effect_settings_updated(toggle: bool, value: float, id: String)
signal display_mode_settings_updated(display_mode: String)
signal display_resolution_settings_updated(width: int, height: int)

## MANAGER
signal resource_updated(id: String, total: int, amount: int, source_id: String)
Expand All @@ -69,5 +75,5 @@ signal deaths_door_resolved(enemy_data: EnemyData, new_enemy_data: EnemyData, op


func _ready() -> void:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("_AUTOLOAD _READY: " + self.get_name())
2 changes: 1 addition & 1 deletion global/const/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WORKER_ROLE_RESOURCE: Array[String] = [WORKER_RESOURCE_ID, "swordsman"]
const VERSION_MAJOR: String = "prototype"
const VERSION_MINOR: String = "week 11"

const params: Dictionary = PARAMS_PROD #PARAMS_PROD #PARAMS_DEBUG
const PARAMS: Dictionary = PARAMS_PROD #PARAMS_PROD #PARAMS_DEBUG

const PARAMS_DEBUG: Dictionary = {
"cycle_seconds": 2,
Expand Down
6 changes: 5 additions & 1 deletion global/const/locale/locale_en.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const UI_LABEL: Dictionary = {
"offline_4": "Since your last activity, population generated: ",
"master": "Master",
"music": "Music",
"sfx": "SFX"
"sfx": "SFX",
"shake": "Shake",
"typing": " Typing ",
"windowed": "Windowed",
"fullscreen": "Fullscreen"
}

const NPC_HOVER_TITLE: Dictionary = {}
Expand Down
4 changes: 2 additions & 2 deletions global/utils/file_system_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IMAGE_RESOURCES_PATH: String = "res://assets/image/"

static func get_files_at(path: String) -> PackedStringArray:
var files: PackedStringArray = DirAccess.get_files_at(path)
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("CALL get_files: " + path)
print(files)
return files
Expand Down Expand Up @@ -65,7 +65,7 @@ static func fix_web_build_file_extension(file: String, force_one_extension: bool
if force_one_extension:
var file_split: PackedStringArray = file.split(".")
if file_split.size() > 2:
if Game.params["debug_logs"]:
if Game.PARAMS["debug_logs"]:
print("!! FORCE ONE EXTENSION: " + file)
file = file_split[0] + "." + file_split[1]
return file
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ window/size/viewport_width=960
window/size/viewport_height=540
window/size/window_width_override=960
window/size/window_height_override=540
window/stretch/mode="viewport"
window/stretch/mode="canvas_items"

[dotnet]

Expand Down
6 changes: 3 additions & 3 deletions resources/game_data/resource_generator/resource_generator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func get_display_name() -> String:

func get_display_info(total: String, eff: String) -> String:
return "{total}, {eff} / {seconds} seconds".format(
{"total": total, "eff": eff, "seconds": Game.params["cycle_seconds"]}
{"total": total, "eff": eff, "seconds": Game.PARAMS["cycle_seconds"]}
)


Expand Down Expand Up @@ -90,8 +90,8 @@ func get_amount() -> int:


func get_cooldown() -> float:
if Game.params["debug_cooldown"] != 0:
return Game.params["debug_cooldown"]
if Game.PARAMS["debug_cooldown"] != 0:
return Game.PARAMS["debug_cooldown"]
return cooldown


Expand Down
2 changes: 1 addition & 1 deletion resources/game_data/worker_role/worker_role.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func get_info() -> String:
var worker_names: Array = WorkerRole.get_display_names_of(worker_consume.keys())
info += (", -%s " + (", -%s ".join(worker_names))) % worker_consume.values()

info += " / %s seconds" % Game.params["cycle_seconds"]
info += " / %s seconds" % Game.PARAMS["cycle_seconds"]
if StringUtils.is_not_empty(flavor):
info += " - " + flavor
return info
Expand Down
4 changes: 2 additions & 2 deletions resources/shader/wiggle/wiggle.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ void vertex()
VERTEX_OFFSET.x += (
random(
( trunc( VERTEX_OFFSET.y))
+ TIME
+ mod(TIME, 60.0)
) - offset
) * Strength ;

VERTEX_OFFSET.y += (
random(
( trunc( VERTEX_OFFSET.x))
+ TIME
+ mod(TIME, 60.0)
) - offset
) * Strength;

Expand Down
Loading

0 comments on commit b3a25ef

Please sign in to comment.