Kürzel-Änderung gilt auch für Trainer- und Staff-Codes

Codes ohne Rückennummer (z. B. „htr“ Trainer, „h-co“ Co-Trainer) werden beim Umstellen h → hs mit
umbenannt (hstr, hs-co) und auch beim Nachladen der TXT umgestellt; Codes, die schon mit dem neuen
Kürzel beginnen, bleiben unverändert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
Lichtkasten DevandClaude Opus 5.5 committed 2026-11-17 19:51:01 +00:00
1 parent 7efaa74678
commit d559a4f182
2 files changed
+33 -5

No files matched your search

@@ -67,10 +67,24 @@ public struct CodeSet: Codable, Hashable, Identifiable, Sendable {
return (p, rest)
}
/// The code as this team uses it (own short code applied).
/// The code as this team uses it (own short code applied) – players and trainer/staff codes alike.
public func mapped(_ code: String) -> String {
guard let (p, rest) = CodeSet.split(code), let to = prefixMap[p.lowercased()] else { return code }
return to + rest
// longest matching old prefix wins ("hs" before "h")
for (from, to) in prefixMap.sorted(by: { $0.key.count > $1.key.count }) {
if let r = CodeSet.renamed(code, from: from, to: to) { return r }
}
return code
}
/// One code with the short code changed, nil if it does not use `from`:
/// players "h10" → "hs10" (letters must be exactly the prefix), and codes without a number –
/// trainer "htr", "h-co" … → "hstr", "hs-co" (start with the prefix).
static func renamed(_ code: String, from: String, to: String) -> String? {
if let (p, rest) = split(code) { return p.lowercased() == from ? to + rest : nil }
let lc = code.lowercased()
guard lc.hasPrefix(from), lc.count > from.count else { return nil }
if to.hasPrefix(from) && lc.hasPrefix(to) { return nil } // already has the new prefix
return to + String(code.dropFirst(from.count))
}
/// Short code of the team as it is now ("h" for h10, h7 …).
@@ -85,8 +99,7 @@ public struct CodeSet: Codable, Hashable, Identifiable, Sendable {
let existing = Set(entries.map { $0.code.lowercased() })
var n = 0
for i in entries.indices {
guard let (p, rest) = CodeSet.split(entries[i].code), p.lowercased() == from else { continue }
let renamed = to + rest
guard let renamed = CodeSet.renamed(entries[i].code, from: from, to: to) else { continue }
if existing.contains(renamed.lowercased()) { continue } // never two players on one code
entries[i].code = renamed
n += 1