mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-01-12 23:04:13 +01:00
Merge branch 'translate_gettext' into v070
This commit is contained in:
1
AndorsTrail/.gitignore
vendored
1
AndorsTrail/.gitignore
vendored
@@ -1,7 +1,6 @@
|
||||
# Android ignores
|
||||
gen/
|
||||
bin/
|
||||
assets/
|
||||
target/
|
||||
local.properties
|
||||
|
||||
|
||||
@@ -557,5 +557,10 @@
|
||||
<string name="preferences_dialog_overwrite_savegame_title">Bestätige das Überschreiben von Spielständen</string>
|
||||
<string name="preferences_dialog_overwrite_savegame">Zeigt eine Frage an ob beim Speichern auf einen bereits existierenden Spielstand dieser überschrieben werden soll.</string>
|
||||
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">de.mo</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -485,4 +485,8 @@
|
||||
<string name="actorinfo_immune_criticals">Immunise contre les coups critiques</string>
|
||||
<string name="traitsinfo_criticalhit_effectivechance">Taux de coups critiques : </string>
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">fr.mo</string>
|
||||
</resources>
|
||||
|
||||
@@ -320,4 +320,9 @@
|
||||
<item>2.0f</item>
|
||||
</string-array>
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">it.mo</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -513,4 +513,10 @@
|
||||
<string name="skill_longdescription_concussion">あなたの命中率より %1$d 以上回避率が低い敵に攻撃するたび、その攻撃は %2$d%% の確率で対象に脳震盪(concussion)を起こします。concussionは攻撃に関する戦闘能力を劇的に下げ、対象は有効な攻撃を当てることが難しくなります。</string>
|
||||
|
||||
<string name="about_button4">About</string>
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">ja.mo</string>
|
||||
|
||||
</resources>
|
||||
@@ -559,5 +559,10 @@ Translated by toudi5-bełchatów
|
||||
<string name="preferences_dialog_overwrite_savegame_title">Potwierdź nadpisanie gry</string>
|
||||
<string name="preferences_dialog_overwrite_savegame">Zadaje pytanie zawsze, gdy chcesz nadpisać grę na slocie, który jest już zajęty.</string>
|
||||
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">pl.mo</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -559,4 +559,9 @@
|
||||
<string name="preferences_dialog_overwrite_savegame_title">Confirma re-escrita de salvamento</string>
|
||||
<string name="preferences_dialog_overwrite_savegame">Pergunta o que deve ser feito caso tente-se gravar sobre um salvamento anterior.</string>
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">pt-rBR.mo</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -475,4 +475,9 @@
|
||||
<string name="preferences_optimized_drawing_title">Optimized drawing</string>
|
||||
<string name="preferences_optimized_drawing">Desactiva esta opção caso apareçam artefactos gráficos. Ao activar esta opção apenas serão redesenhados no écrã os blocos alterados em cada fotograma.</string>
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">pt.mo</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -558,5 +558,9 @@
|
||||
<string name="preferences_dialog_overwrite_savegame_title">Перезаписать сохранение</string>
|
||||
<string name="preferences_dialog_overwrite_savegame">Настройка диалога подтверждения при попытке перезаписать сохранение</string>
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Added in v0.7.0 -->
|
||||
|
||||
<string name="localize_resources_from_mo_filename">ru.mo</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -564,6 +564,7 @@
|
||||
<string name="heroinfo_useitem_cost">Use item cost (AP):</string>
|
||||
<string name="combat_result_monstermoved">%1$s moves.</string>
|
||||
<string name="combat_log_title">Combat log</string>
|
||||
<string name="localize_resources_from_mo_filename"></string>
|
||||
<string name="conversation_reward_quest_finished">[Quest completed: \"%1$s\"]</string>
|
||||
<string name="conversation_reward_quest_updated">[Quest updated: \"%1$s\"]</string>
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.resource.ResourceLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.ConversationListParser;
|
||||
|
||||
public final class ConversationLoader {
|
||||
@@ -19,11 +20,13 @@ public final class ConversationLoader {
|
||||
if (conversationCollection.hasPhrase(phraseID)) {
|
||||
return conversationCollection.getPhrase(phraseID);
|
||||
}
|
||||
|
||||
ConversationListParser conversationListParser = new ConversationListParser();
|
||||
|
||||
TranslationLoader translationLoader = new TranslationLoader(r.getAssets(), r);
|
||||
ConversationListParser conversationListParser = new ConversationListParser(translationLoader);
|
||||
int resourceID = resourceIDsPerPhraseID.get(phraseID);
|
||||
conversationCollection.initialize(conversationListParser, ResourceLoader.readStringFromRaw(r, resourceID));
|
||||
|
||||
translationLoader.close();
|
||||
|
||||
return conversationCollection.getPhrase(phraseID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ public final class ResourceLoader {
|
||||
taskStart = start;
|
||||
|
||||
final int mTileSize = world.tileManager.tileSize;
|
||||
|
||||
|
||||
TranslationLoader translationLoader = new TranslationLoader(r.getAssets(), r);
|
||||
|
||||
DynamicTileLoader loader = new DynamicTileLoader(world.tileManager.tileCache);
|
||||
prepareTilesets(loader, mTileSize);
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) timingCheckpoint("prepareTilesets");
|
||||
@@ -75,7 +77,7 @@ public final class ResourceLoader {
|
||||
|
||||
// ========================================================================
|
||||
// Load item categories
|
||||
final ItemCategoryParser itemCategoryParser = new ItemCategoryParser();
|
||||
final ItemCategoryParser itemCategoryParser = new ItemCategoryParser(translationLoader);
|
||||
final TypedArray categoriesToLoad = r.obtainTypedArray(itemCategoriesResourceId);
|
||||
for (int i = 0; i < categoriesToLoad.length(); ++i) {
|
||||
world.itemCategories.initialize(itemCategoryParser, readStringFromRaw(r, categoriesToLoad, i));
|
||||
@@ -85,7 +87,7 @@ public final class ResourceLoader {
|
||||
|
||||
// ========================================================================
|
||||
// Load condition types
|
||||
final ActorConditionsTypeParser actorConditionsTypeParser = new ActorConditionsTypeParser(loader);
|
||||
final ActorConditionsTypeParser actorConditionsTypeParser = new ActorConditionsTypeParser(loader, translationLoader);
|
||||
final TypedArray conditionsToLoad = r.obtainTypedArray(actorConditionsResourceId);
|
||||
for (int i = 0; i < conditionsToLoad.length(); ++i) {
|
||||
world.actorConditionsTypes.initialize(actorConditionsTypeParser, readStringFromRaw(r, conditionsToLoad, i));
|
||||
@@ -101,7 +103,7 @@ public final class ResourceLoader {
|
||||
|
||||
// ========================================================================
|
||||
// Load items
|
||||
final ItemTypeParser itemTypeParser = new ItemTypeParser(loader, world.actorConditionsTypes, world.itemCategories);
|
||||
final ItemTypeParser itemTypeParser = new ItemTypeParser(loader, world.actorConditionsTypes, world.itemCategories, translationLoader);
|
||||
final TypedArray itemsToLoad = r.obtainTypedArray(itemsResourceId);
|
||||
for (int i = 0; i < itemsToLoad.length(); ++i) {
|
||||
world.itemTypes.initialize(itemTypeParser, readStringFromRaw(r, itemsToLoad, i));
|
||||
@@ -123,7 +125,7 @@ public final class ResourceLoader {
|
||||
|
||||
// ========================================================================
|
||||
// Load quests
|
||||
final QuestParser questParser = new QuestParser();
|
||||
final QuestParser questParser = new QuestParser(translationLoader);
|
||||
final TypedArray questsToLoad = r.obtainTypedArray(questsResourceId);
|
||||
for (int i = 0; i < questsToLoad.length(); ++i) {
|
||||
world.quests.initialize(questParser, readStringFromRaw(r, questsToLoad, i));
|
||||
@@ -134,7 +136,7 @@ public final class ResourceLoader {
|
||||
|
||||
// ========================================================================
|
||||
// Load conversations
|
||||
final ConversationListParser conversationListParser = new ConversationListParser();
|
||||
final ConversationListParser conversationListParser = new ConversationListParser(translationLoader);
|
||||
final TypedArray conversationsListsToLoad = r.obtainTypedArray(conversationsListsResourceId);
|
||||
for (int i = 0; i < conversationsListsToLoad.length(); ++i) {
|
||||
ConversationCollection conversations = new ConversationCollection();
|
||||
@@ -147,7 +149,7 @@ public final class ResourceLoader {
|
||||
|
||||
// ========================================================================
|
||||
// Load monsters
|
||||
final MonsterTypeParser monsterTypeParser = new MonsterTypeParser(world.dropLists, world.actorConditionsTypes, loader);
|
||||
final MonsterTypeParser monsterTypeParser = new MonsterTypeParser(world.dropLists, world.actorConditionsTypes, loader, translationLoader);
|
||||
final TypedArray monstersToLoad = r.obtainTypedArray(monstersResourceId);
|
||||
for (int i = 0; i < monstersToLoad.length(); ++i) {
|
||||
world.monsterTypes.initialize(monsterTypeParser, readStringFromRaw(r, monstersToLoad, i));
|
||||
@@ -186,7 +188,8 @@ public final class ResourceLoader {
|
||||
WorldMapParser.read(r, R.xml.worldmap, world.maps);
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) timingCheckpoint("WorldMapParser");
|
||||
// ========================================================================
|
||||
|
||||
|
||||
translationLoader.close();
|
||||
|
||||
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
|
||||
@@ -227,7 +230,7 @@ public final class ResourceLoader {
|
||||
final Size src_sz20x12 = new Size(20, 12);
|
||||
final Size src_mapTileSize = new Size(16, 8);
|
||||
final Size src_mapTileSize7 = new Size(16, 7);
|
||||
|
||||
|
||||
loader.prepareTileset(R.drawable.char_hero, "char_hero", src_sz1x1, defaultTileSize);
|
||||
|
||||
loader.prepareTileset(R.drawable.ui_selections, "ui_selections", new Size(5, 1), defaultTileSize);
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.gpl.rpg.AndorsTrail.resource;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.util.L;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public final class TranslationLoader {
|
||||
private final BinaryMoFileParser parser;
|
||||
|
||||
public TranslationLoader(AssetManager mgr, Resources res) {
|
||||
this.parser = createParser(mgr, res);
|
||||
}
|
||||
public TranslationLoader(AssetManager mgr, String filename) {
|
||||
this.parser = createParser(mgr, filename);
|
||||
}
|
||||
|
||||
private static final String translationDir = "translation" + File.separator;
|
||||
private static BinaryMoFileParser createParser(AssetManager mgr, Resources res) {
|
||||
String translationFilename = res.getString(R.string.localize_resources_from_mo_filename);
|
||||
if (translationFilename == null || translationFilename.length() <= 0) return null;
|
||||
|
||||
return createParser(mgr, translationDir + translationFilename);
|
||||
}
|
||||
|
||||
private static BinaryMoFileParser createParser(AssetManager mgr, String translationFilename) {
|
||||
try {
|
||||
InputStream is = mgr.open(translationFilename);
|
||||
return new BinaryMoFileParser(is);
|
||||
} catch (IOException e) {
|
||||
L.log("ERROR: Reading from translation asset \"" + translationFilename + "\" failed: " + e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String tr(String s) {
|
||||
if (s == null) return null;
|
||||
if (parser == null) return s;
|
||||
if (s.length() <= 1) return s;
|
||||
try {
|
||||
//String t = parser.translate(s);
|
||||
//L.log(translations.size() + " : " + s + " -> " + t);
|
||||
//return t;
|
||||
return parser.translate(s);
|
||||
} catch (IOException e) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (parser == null) return;
|
||||
try {
|
||||
parser.close();
|
||||
} catch (IOException e) { }
|
||||
}
|
||||
|
||||
public String translateItemCategoryName(String s) { return tr(s); }
|
||||
public String translateActorConditionName(String s) { return tr(s); }
|
||||
public String translateItemTypeName(String s) { return tr(s); }
|
||||
public String translateItemTypeDescription(String s) {return tr(s); }
|
||||
public String translateMonsterTypeName(String s) { return tr(s); }
|
||||
public String translateQuestName(String s) { return tr(s); }
|
||||
public String translateQuestLogEntry(String s) { return tr(s); }
|
||||
public String translateConversationPhrase(String s) { return tr(s); }
|
||||
public String translateConversationReply(String s) { return tr(s); }
|
||||
|
||||
private static final class BinaryMoFileParser {
|
||||
private final InputStream is;
|
||||
private final BufferedInputStream reader;
|
||||
private final int numStrings;
|
||||
private final int offsetOriginalStrings;
|
||||
private final int offsetTranslatedStrings;
|
||||
|
||||
public BinaryMoFileParser(InputStream is) throws IOException {
|
||||
this.is = is;
|
||||
this.reader = new BufferedInputStream(is);
|
||||
this.reader.mark(9999999);
|
||||
int magic = readIntLE();
|
||||
if (magic != 0x950412de) throw new IOException("Invalid magic in MO file");
|
||||
this.reader.skip(4);
|
||||
numStrings = readIntLE();
|
||||
offsetOriginalStrings = readIntLE();
|
||||
offsetTranslatedStrings = readIntLE();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
reader.close();
|
||||
is.close();
|
||||
}
|
||||
|
||||
private static final String charset = "utf-8";
|
||||
|
||||
public String translate(String s) throws IOException {
|
||||
if (numStrings <= 0) return s;
|
||||
|
||||
byte[] bytes = s.getBytes(charset);
|
||||
byte[] translation = find(bytes);
|
||||
if (translation == null || translation.length <= 0) return s;
|
||||
return new String(translation, charset);
|
||||
}
|
||||
|
||||
private byte[] find(byte[] bytes) throws IOException {
|
||||
return find(bytes, 0, numStrings);
|
||||
}
|
||||
|
||||
private byte[] find(byte[] bytes, int minIndex, int maxIndex) throws IOException {
|
||||
int middleIndex;
|
||||
while(minIndex != maxIndex) {
|
||||
if (minIndex+1 == maxIndex) middleIndex = minIndex;
|
||||
else if (minIndex+2 == maxIndex) middleIndex = minIndex;
|
||||
else middleIndex = (minIndex + maxIndex) / 2;
|
||||
|
||||
int c = compare(bytes, middleIndex);
|
||||
if (c == 0) return getTranslatedStringAt(middleIndex);
|
||||
|
||||
if (minIndex+1 == maxIndex) {
|
||||
return null;
|
||||
} else if (c > 0) {
|
||||
maxIndex = middleIndex;
|
||||
} else {
|
||||
minIndex = middleIndex+1;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final byte[] buf = new byte[8];
|
||||
public final int readIntLE() throws IOException
|
||||
{
|
||||
reader.read(buf, 0, 4);
|
||||
return
|
||||
(buf[3]) << 24 |
|
||||
(buf[2]&0xff) << 16 |
|
||||
(buf[1]&0xff) << 8 |
|
||||
(buf[0]&0xff);
|
||||
}
|
||||
|
||||
private void seek(int pos) throws IOException {
|
||||
reader.reset();
|
||||
reader.skip(pos);
|
||||
}
|
||||
|
||||
private byte[] getTranslatedStringAt(int idx) throws IOException {
|
||||
seek(offsetTranslatedStrings + idx*8);
|
||||
int length = readIntLE();
|
||||
int offset = readIntLE();
|
||||
seek(offset);
|
||||
byte[] result = new byte[length];
|
||||
reader.read(result, 0, length);
|
||||
return result;
|
||||
}
|
||||
|
||||
private int compare(byte[] bytes, int idx) throws IOException {
|
||||
seek(offsetOriginalStrings + idx*8);
|
||||
int length = readIntLE();
|
||||
int offset = readIntLE();
|
||||
seek(offset);
|
||||
int maxLength = bytes.length;
|
||||
for(int i = 0; i < length; ++i) {
|
||||
if (i == maxLength) return 1;
|
||||
int b = reader.read();
|
||||
if (b == bytes[i]) continue;
|
||||
return (b < bytes[i]) ? -1 : 1;
|
||||
}
|
||||
if (length < maxLength) return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.gpl.rpg.AndorsTrail.resource.parsers;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionType;
|
||||
import com.gpl.rpg.AndorsTrail.resource.DynamicTileLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonCollectionParserFor;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonFieldNames;
|
||||
import com.gpl.rpg.AndorsTrail.util.Pair;
|
||||
@@ -11,17 +12,19 @@ import org.json.JSONObject;
|
||||
public final class ActorConditionsTypeParser extends JsonCollectionParserFor<ActorConditionType> {
|
||||
|
||||
private final DynamicTileLoader tileLoader;
|
||||
|
||||
public ActorConditionsTypeParser(final DynamicTileLoader tileLoader) {
|
||||
private final TranslationLoader translationLoader;
|
||||
|
||||
public ActorConditionsTypeParser(final DynamicTileLoader tileLoader, TranslationLoader translationLoader) {
|
||||
this.tileLoader = tileLoader;
|
||||
}
|
||||
this.translationLoader = translationLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, ActorConditionType> parseObject(JSONObject o) throws JSONException {
|
||||
final String conditionTypeID = o.getString(JsonFieldNames.ActorCondition.conditionTypeID);
|
||||
ActorConditionType result = new ActorConditionType(
|
||||
conditionTypeID
|
||||
,o.getString(JsonFieldNames.ActorCondition.name)
|
||||
,translationLoader.translateActorConditionName(o.getString(JsonFieldNames.ActorCondition.name))
|
||||
,ResourceParserUtils.parseImageID(tileLoader, o.getString(JsonFieldNames.ActorCondition.iconID))
|
||||
,o.getInt(JsonFieldNames.ActorCondition.category)
|
||||
,o.optInt(JsonFieldNames.ActorCondition.isStacking) > 0
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.gpl.rpg.AndorsTrail.conversation.Phrase;
|
||||
import com.gpl.rpg.AndorsTrail.conversation.Phrase.Reply;
|
||||
import com.gpl.rpg.AndorsTrail.conversation.Phrase.Reward;
|
||||
import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonCollectionParserFor;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonFieldNames;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonParserFor;
|
||||
@@ -16,8 +17,10 @@ import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class ConversationListParser extends JsonCollectionParserFor<Phrase> {
|
||||
|
||||
private final JsonParserFor<Reply> replyParser = new JsonParserFor<Reply>() {
|
||||
|
||||
private final TranslationLoader translationLoader;
|
||||
|
||||
private final JsonParserFor<Reply> replyParser = new JsonParserFor<Reply>() {
|
||||
@Override
|
||||
protected Reply parseObject(JSONObject o) throws JSONException {
|
||||
JSONObject requires = o.optJSONObject(JsonFieldNames.Reply.requires);
|
||||
@@ -35,7 +38,7 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
|
||||
}
|
||||
}
|
||||
return new Reply(
|
||||
o.optString(JsonFieldNames.Reply.text, "")
|
||||
translationLoader.translateConversationReply(o.optString(JsonFieldNames.Reply.text, ""))
|
||||
,o.getString(JsonFieldNames.Reply.nextPhraseID)
|
||||
,QuestProgress.parseQuestProgress(requiresProgress)
|
||||
,requiresItemTypeID
|
||||
@@ -55,8 +58,12 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
public ConversationListParser(TranslationLoader translationLoader) {
|
||||
this.translationLoader = translationLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, Phrase> parseObject(JSONObject o) throws JSONException {
|
||||
final String id = o.getString(JsonFieldNames.Phrase.phraseID);
|
||||
|
||||
@@ -76,7 +83,7 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
|
||||
if (_rewards.length == 0) _rewards = null;
|
||||
|
||||
return new Pair<String, Phrase>(id, new Phrase(
|
||||
o.optString(JsonFieldNames.Phrase.message, null)
|
||||
translationLoader.translateConversationPhrase(o.optString(JsonFieldNames.Phrase.message, null))
|
||||
, _replies
|
||||
, _rewards
|
||||
));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gpl.rpg.AndorsTrail.resource.parsers;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.model.item.ItemCategory;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonCollectionParserFor;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonFieldNames;
|
||||
import com.gpl.rpg.AndorsTrail.util.Pair;
|
||||
@@ -9,12 +10,19 @@ import org.json.JSONObject;
|
||||
|
||||
public final class ItemCategoryParser extends JsonCollectionParserFor<ItemCategory> {
|
||||
|
||||
@Override
|
||||
private final TranslationLoader translationLoader;
|
||||
|
||||
public ItemCategoryParser(TranslationLoader translationLoader) {
|
||||
|
||||
this.translationLoader = translationLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, ItemCategory> parseObject(JSONObject o) throws JSONException {
|
||||
final String id = o.getString(JsonFieldNames.ItemCategory.itemCategoryID);
|
||||
ItemCategory result = new ItemCategory(
|
||||
id
|
||||
,o.getString(JsonFieldNames.ItemCategory.name)
|
||||
,translationLoader.translateItemCategoryName(o.getString(JsonFieldNames.ItemCategory.name))
|
||||
,o.optInt(JsonFieldNames.ItemCategory.actionType, 0)
|
||||
,o.optInt(JsonFieldNames.ItemCategory.inventorySlot, -1)
|
||||
,o.optInt(JsonFieldNames.ItemCategory.size, 0)
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnEquip;
|
||||
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnUse;
|
||||
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
|
||||
import com.gpl.rpg.AndorsTrail.resource.DynamicTileLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonCollectionParserFor;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonFieldNames;
|
||||
import com.gpl.rpg.AndorsTrail.util.Pair;
|
||||
@@ -15,19 +16,26 @@ import org.json.JSONObject;
|
||||
public final class ItemTypeParser extends JsonCollectionParserFor<ItemType> {
|
||||
|
||||
private final DynamicTileLoader tileLoader;
|
||||
private final ItemTraitsParser itemTraitsParser;
|
||||
private final TranslationLoader translationLoader;
|
||||
private final ItemTraitsParser itemTraitsParser;
|
||||
private final ItemCategoryCollection itemCategories;
|
||||
|
||||
public ItemTypeParser(DynamicTileLoader tileLoader, ActorConditionTypeCollection actorConditionsTypes, ItemCategoryCollection itemCategories) {
|
||||
public ItemTypeParser(
|
||||
DynamicTileLoader tileLoader,
|
||||
ActorConditionTypeCollection actorConditionsTypes,
|
||||
ItemCategoryCollection itemCategories,
|
||||
TranslationLoader translationLoader) {
|
||||
this.tileLoader = tileLoader;
|
||||
this.itemTraitsParser = new ItemTraitsParser(actorConditionsTypes);
|
||||
this.translationLoader = translationLoader;
|
||||
this.itemTraitsParser = new ItemTraitsParser(actorConditionsTypes);
|
||||
this.itemCategories = itemCategories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<String, ItemType> parseObject(JSONObject o) throws JSONException {
|
||||
final String id = o.getString(JsonFieldNames.ItemType.itemTypeID);
|
||||
final String itemTypeName = o.getString(JsonFieldNames.ItemType.name);
|
||||
final String itemTypeName = translationLoader.translateItemTypeName(o.getString(JsonFieldNames.ItemType.name));
|
||||
final String description = translationLoader.translateItemTypeDescription(o.optString(JsonFieldNames.ItemType.description, null));
|
||||
final ItemTraits_OnEquip equipEffect = itemTraitsParser.parseItemTraits_OnEquip(o.optJSONObject(JsonFieldNames.ItemType.equipEffect));
|
||||
final ItemTraits_OnUse useEffect = itemTraitsParser.parseItemTraits_OnUse(o.optJSONObject(JsonFieldNames.ItemType.useEffect));
|
||||
final ItemTraits_OnUse hitEffect = itemTraitsParser.parseItemTraits_OnUse(o.optJSONObject(JsonFieldNames.ItemType.hitEffect));
|
||||
@@ -39,7 +47,7 @@ public final class ItemTypeParser extends JsonCollectionParserFor<ItemType> {
|
||||
id
|
||||
, ResourceParserUtils.parseImageID(tileLoader, o.getString(JsonFieldNames.ItemType.iconID))
|
||||
, itemTypeName
|
||||
, o.optString(JsonFieldNames.ItemType.description, null)
|
||||
, description
|
||||
, itemCategories.getItemCategory(o.getString(JsonFieldNames.ItemType.category))
|
||||
, o.optInt(JsonFieldNames.ItemType.displaytype, ItemType.DISPLAYTYPE_ORDINARY)
|
||||
, hasManualPrice
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.gpl.rpg.AndorsTrail.model.actor.MonsterType;
|
||||
import com.gpl.rpg.AndorsTrail.model.item.DropListCollection;
|
||||
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnUse;
|
||||
import com.gpl.rpg.AndorsTrail.resource.DynamicTileLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonCollectionParserFor;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonFieldNames;
|
||||
import com.gpl.rpg.AndorsTrail.util.ConstRange;
|
||||
@@ -21,9 +22,15 @@ public final class MonsterTypeParser extends JsonCollectionParserFor<MonsterType
|
||||
private final DropListCollection droplists;
|
||||
private final ItemTraitsParser itemTraitsParser;
|
||||
private final DynamicTileLoader tileLoader;
|
||||
|
||||
public MonsterTypeParser(final DropListCollection droplists, final ActorConditionTypeCollection actorConditionTypes, final DynamicTileLoader tileLoader) {
|
||||
this.itemTraitsParser = new ItemTraitsParser(actorConditionTypes);
|
||||
private final TranslationLoader translationLoader;
|
||||
|
||||
public MonsterTypeParser(
|
||||
final DropListCollection droplists,
|
||||
final ActorConditionTypeCollection actorConditionTypes,
|
||||
final DynamicTileLoader tileLoader,
|
||||
final TranslationLoader translationLoader) {
|
||||
this.translationLoader = translationLoader;
|
||||
this.itemTraitsParser = new ItemTraitsParser(actorConditionTypes);
|
||||
this.droplists = droplists;
|
||||
this.tileLoader = tileLoader;
|
||||
}
|
||||
@@ -47,7 +54,7 @@ public final class MonsterTypeParser extends JsonCollectionParserFor<MonsterType
|
||||
|
||||
return new Pair<String, MonsterType>(monsterTypeID, new MonsterType(
|
||||
monsterTypeID
|
||||
, o.getString(JsonFieldNames.Monster.name)
|
||||
, translationLoader.translateMonsterTypeName(o.getString(JsonFieldNames.Monster.name))
|
||||
, o.optString(JsonFieldNames.Monster.spawnGroup, monsterTypeID)
|
||||
, exp
|
||||
, droplists.getDropList(o.optString(JsonFieldNames.Monster.droplistID, null))
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.gpl.rpg.AndorsTrail.resource.parsers;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.model.quest.Quest;
|
||||
import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonCollectionParserFor;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonFieldNames;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonParserFor;
|
||||
@@ -14,14 +15,15 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
public final class QuestParser extends JsonCollectionParserFor<Quest> {
|
||||
private int sortOrder = 0;
|
||||
private final TranslationLoader translationLoader;
|
||||
private int sortOrder = 0;
|
||||
|
||||
private final JsonParserFor<QuestLogEntry> questLogEntryParser = new JsonParserFor<QuestLogEntry>() {
|
||||
@Override
|
||||
protected QuestLogEntry parseObject(JSONObject o) throws JSONException {
|
||||
return new QuestLogEntry(
|
||||
o.getInt(JsonFieldNames.QuestLogEntry.progress)
|
||||
,o.optString(JsonFieldNames.QuestLogEntry.logText, null)
|
||||
,translationLoader.translateQuestLogEntry(o.optString(JsonFieldNames.QuestLogEntry.logText, null))
|
||||
,o.optInt(JsonFieldNames.QuestLogEntry.rewardExperience, 0)
|
||||
,o.optInt(JsonFieldNames.QuestLogEntry.finishesQuest, 0) > 0
|
||||
);
|
||||
@@ -34,7 +36,11 @@ public final class QuestParser extends JsonCollectionParserFor<Quest> {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public QuestParser(TranslationLoader translationLoader) {
|
||||
this.translationLoader = translationLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, Quest> parseObject(JSONObject o) throws JSONException {
|
||||
final String id = o.getString(JsonFieldNames.Quest.questID);
|
||||
|
||||
@@ -47,7 +53,7 @@ public final class QuestParser extends JsonCollectionParserFor<Quest> {
|
||||
|
||||
return new Pair<String, Quest>(id, new Quest(
|
||||
id
|
||||
, o.getString(JsonFieldNames.Quest.name)
|
||||
, translationLoader.translateQuestName(o.getString(JsonFieldNames.Quest.name))
|
||||
, stages_
|
||||
, o.optInt(JsonFieldNames.Quest.showInLog, 0) > 0
|
||||
, sortOrder
|
||||
|
||||
Reference in New Issue
Block a user