mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-05-06 14:24:15 +02:00
feat(i18n): localized quest text and per-lang quest cache
Phase B of #188. Quest JSON title/description/text_main/text_sub_a/ text_sub_b/success_cond/fail_cond/contractor now accept either a plain string (existing behaviour) or a language-keyed object like "title": { "jp": "...", "en": "...", "fr": "..." } CompileQuestJSON takes the compiling session's language and resolves each field through a fallback chain (requested -> plain -> jp -> en -> any non-empty), so existing single-language quest JSONs keep working byte-for-byte unchanged. The quest cache is re-keyed on (questID, language) so compiled binaries for different languages never leak between sessions on a multi-language server. loadQuestBinary and loadQuestFile now pass s.Lang() into both the compiler and the cache. ParseQuestBinary emits plain-string LocalizedStrings, so the binary -> JSON -> binary round-trip still produces identical output. The new LocalizedString type lives in its own file and is reusable by phase C (scenarios, mail templates, shop text). Shift-JIS encoding still applies to the wire format, so localized values must use characters representable in Shift-JIS — ASCII, kana, CJK — which is documented on the type.
This commit is contained in:
@@ -161,7 +161,7 @@ func loadQuestBinary(s *Session, filename string) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
compiled, err := CompileQuestJSON(jsonData)
|
||||
compiled, err := CompileQuestJSON(jsonData, s.Lang())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("compile quest JSON %s: %w", filename, err)
|
||||
}
|
||||
@@ -248,7 +248,8 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
|
||||
}
|
||||
|
||||
func loadQuestFile(s *Session, questId int) []byte {
|
||||
if cached, ok := s.server.questCache.Get(questId); ok {
|
||||
lang := s.Lang()
|
||||
if cached, ok := s.server.questCache.Get(questId, lang); ok {
|
||||
return cached
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ func loadQuestFile(s *Session, questId int) []byte {
|
||||
if data, err := os.ReadFile(base + ".bin"); err == nil {
|
||||
decrypted = decryption.UnpackSimple(data)
|
||||
} else if jsonData, err := os.ReadFile(base + ".json"); err == nil {
|
||||
compiled, err := CompileQuestJSON(jsonData)
|
||||
compiled, err := CompileQuestJSON(jsonData, lang)
|
||||
if err != nil {
|
||||
s.logger.Error("loadQuestFile: failed to compile quest JSON",
|
||||
zap.Int("questId", questId), zap.Error(err))
|
||||
@@ -313,7 +314,7 @@ func loadQuestFile(s *Session, questId int) []byte {
|
||||
questBody.WriteBytes(newStrings.Data())
|
||||
|
||||
result := questBody.Data()
|
||||
s.server.questCache.Put(questId, result)
|
||||
s.server.questCache.Put(questId, lang, result)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user