528e22875d
- Rename enum GAUNTLET→CANDY_SURVIVAL, all gauntlet_*→candy_survival_* - Rename files: gauntlet_manager→candy_survival_manager, candy_cannon→candy_survival_npc, gauntlet.tscn→candy_survival.tscn - Rewrite candy_survival_manager.gd: blueprints, candy stack, Mekton delivery, Sugar Rush, knock/ghost charges, sticky-as-wall - Update player_movement_manager.gd: smack→knock system, ghost integration - All Candy Survival issues (#54-57, #65-70) retitled per boss design - Shared managers (goals_cycle, goal, player_race, playerboard, turn) untouched
103 lines
3.7 KiB
GDScript
103 lines
3.7 KiB
GDScript
extends RefCounted
|
|
class_name ModeConfig
|
|
|
|
# ModeConfig - Schema-driven validation for game mode settings
|
|
# Task [036]: Consolidates duplicated/inconsistent option toggles
|
|
|
|
# Schema definition for all mode-specific settings
|
|
const SCHEMA = {
|
|
"Freemode": {
|
|
"match_duration": {"type": TYPE_INT, "default": 180, "min": 60, "max": 600},
|
|
"randomize_spawn": {"type": TYPE_BOOL, "default": false},
|
|
"enable_cycle_timer": {"type": TYPE_BOOL, "default": false},
|
|
"scarcity_mode": {"type": TYPE_STRING, "default": "Normal", "allowed": ["Normal", "Aggressive", "Chaos"]}
|
|
},
|
|
"Stop n Go": {
|
|
"match_duration": {"type": TYPE_INT, "default": 180, "min": 60, "max": 600},
|
|
"sng_go_duration": {"type": TYPE_INT, "default": 20, "min": 10, "max": 60},
|
|
"sng_stop_duration": {"type": TYPE_INT, "default": 4, "min": 2, "max": 10},
|
|
"sng_required_goals": {"type": TYPE_INT, "default": 8, "min": 3, "max": 20}
|
|
},
|
|
"Candy Survival": {
|
|
"match_duration": {"type": TYPE_INT, "default": 180, "min": 60, "max": 600},
|
|
"candy_survival_growth_interval": {"type": TYPE_FLOAT, "default": 3.0, "min": 1.0, "max": 10.0},
|
|
"candy_survival_cells_per_tick": {"type": TYPE_DICTIONARY, "default": {"phase1": [4, 6], "phase2": [6, 8], "phase3": [8, 10]}}
|
|
}
|
|
}
|
|
|
|
# Get default config for a mode
|
|
static func get_defaults(mode: String) -> Dictionary:
|
|
if not SCHEMA.has(mode):
|
|
push_error("ModeConfig: Unknown mode '%s'" % mode)
|
|
return {}
|
|
|
|
var defaults = {}
|
|
for key in SCHEMA[mode]:
|
|
defaults[key] = SCHEMA[mode][key]["default"]
|
|
return defaults
|
|
|
|
# Validate a single setting
|
|
static func validate_setting(mode: String, key: String, value: Variant) -> Dictionary:
|
|
if not SCHEMA.has(mode):
|
|
return {"valid": false, "error": "Unknown mode: %s" % mode}
|
|
|
|
if not SCHEMA[mode].has(key):
|
|
return {"valid": false, "error": "Unknown setting '%s' for mode '%s'" % [key, mode]}
|
|
|
|
var schema = SCHEMA[mode][key]
|
|
|
|
# Type check
|
|
if typeof(value) != schema["type"]:
|
|
return {"valid": false, "error": "Setting '%s' expects type %s, got %s" % [key, schema["type"], typeof(value)]}
|
|
|
|
# Range check for numbers
|
|
if schema["type"] == TYPE_INT or schema["type"] == TYPE_FLOAT:
|
|
if schema.has("min") and value < schema["min"]:
|
|
return {"valid": false, "error": "Setting '%s' must be >= %s" % [key, schema["min"]]}
|
|
if schema.has("max") and value > schema["max"]:
|
|
return {"valid": false, "error": "Setting '%s' must be <= %s" % [key, schema["max"]]}
|
|
|
|
# Allowed values check for strings
|
|
if schema["type"] == TYPE_STRING and schema.has("allowed"):
|
|
if value not in schema["allowed"]:
|
|
return {"valid": false, "error": "Setting '%s' must be one of %s" % [key, schema["allowed"]]}
|
|
|
|
return {"valid": true}
|
|
|
|
# Validate entire config for a mode
|
|
static func validate_config(mode: String, config: Dictionary) -> Dictionary:
|
|
if not SCHEMA.has(mode):
|
|
return {"valid": false, "error": "Unknown mode: %s" % mode}
|
|
|
|
var errors = []
|
|
|
|
for key in config:
|
|
var result = validate_setting(mode, key, config[key])
|
|
if not result["valid"]:
|
|
errors.append(result["error"])
|
|
|
|
if errors.is_empty():
|
|
return {"valid": true}
|
|
else:
|
|
return {"valid": false, "errors": errors}
|
|
|
|
# Get all settings for a mode
|
|
static func get_mode_settings(mode: String) -> Array:
|
|
if not SCHEMA.has(mode):
|
|
return []
|
|
return SCHEMA[mode].keys()
|
|
|
|
# Get schema for a specific setting
|
|
static func get_setting_schema(mode: String, key: String) -> Dictionary:
|
|
if not SCHEMA.has(mode) or not SCHEMA[mode].has(key):
|
|
return {}
|
|
return SCHEMA[mode][key]
|
|
|
|
# Check if a mode has a specific setting
|
|
static func has_setting(mode: String, key: String) -> bool:
|
|
return SCHEMA.has(mode) and SCHEMA[mode].has(key)
|
|
|
|
# Get all supported modes
|
|
static func get_supported_modes() -> Array:
|
|
return SCHEMA.keys()
|