Initial commit — Godot space roguelite source
- Touch controls: direct InputEventScreenTouch in shop_ui (bypass relay) - ItemDB: static preload list instead of DirAccess scan (export fix) - All 18 items with EN localisation (name_en, desc_en, category_en) - Ship playstyles: NOVA-1 shield, INFERNO ram, AURORA agile/tank - Quasar: SMBH visual, jet boost, merge, push, BH-eating - Atlas & UI text updated EN+DE Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
extends Node
|
||||
|
||||
const MAX_ENTRIES := 10
|
||||
const SAVE_PATH := "user://leaderboard.cfg"
|
||||
|
||||
var _scores: Array = []
|
||||
|
||||
func _ready() -> void:
|
||||
_load()
|
||||
|
||||
func add_score(player_name: String, score: int, wave: int) -> void:
|
||||
var entry := {
|
||||
"name": player_name.strip_edges().left(12),
|
||||
"score": score,
|
||||
"wave": wave,
|
||||
"date": Time.get_date_string_from_system()
|
||||
}
|
||||
_scores.append(entry)
|
||||
_scores.sort_custom(func(a: Dictionary, b: Dictionary) -> bool:
|
||||
return a["score"] > b["score"])
|
||||
if _scores.size() > MAX_ENTRIES:
|
||||
_scores.resize(MAX_ENTRIES)
|
||||
_save()
|
||||
|
||||
func get_scores() -> Array:
|
||||
return _scores
|
||||
|
||||
func is_highscore(score: int) -> bool:
|
||||
if _scores.size() < MAX_ENTRIES:
|
||||
return true
|
||||
return score > (_scores[-1] as Dictionary).get("score", 0)
|
||||
|
||||
func _save() -> void:
|
||||
var cfg := ConfigFile.new()
|
||||
for i: int in _scores.size():
|
||||
var e: Dictionary = _scores[i]
|
||||
cfg.set_value("entry_%d" % i, "name", e.get("name", "???"))
|
||||
cfg.set_value("entry_%d" % i, "score", e.get("score", 0))
|
||||
cfg.set_value("entry_%d" % i, "wave", e.get("wave", 1))
|
||||
cfg.set_value("entry_%d" % i, "date", e.get("date", ""))
|
||||
cfg.save(SAVE_PATH)
|
||||
|
||||
func _load() -> void:
|
||||
_scores = []
|
||||
var cfg := ConfigFile.new()
|
||||
if cfg.load(SAVE_PATH) != OK:
|
||||
return
|
||||
var i := 0
|
||||
while cfg.has_section("entry_%d" % i):
|
||||
_scores.append({
|
||||
"name": cfg.get_value("entry_%d" % i, "name", "???"),
|
||||
"score": cfg.get_value("entry_%d" % i, "score", 0),
|
||||
"wave": cfg.get_value("entry_%d" % i, "wave", 1),
|
||||
"date": cfg.get_value("entry_%d" % i, "date", "")
|
||||
})
|
||||
i += 1
|
||||
Reference in New Issue
Block a user