Commit d54e6d6c authored by fallenstardust's avatar fallenstardust

DeckInfo readDeck将密码替换

第一张卡id密码替换
parent 6806cea8
...@@ -25,8 +25,8 @@ public class DeckFile extends TextSelect { ...@@ -25,8 +25,8 @@ public class DeckFile extends TextSelect {
if(index > 0) { if(index > 0) {
name = name.substring(0, index); name = name.substring(0, index);
} }
typeName= DeckUtil.getDeckTypeName(path.getAbsolutePath()); typeName = DeckUtil.getDeckTypeName(path.getAbsolutePath());
firstCode=DeckUtil.getFirstCardCode(path.getAbsolutePath()); firstCode = DeckUtil.getFirstCardCode(path.getAbsolutePath());
super.setName(name); super.setName(name);
setObject(this); setObject(this);
} }
......
...@@ -13,11 +13,14 @@ import java.io.FileInputStream; ...@@ -13,11 +13,14 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import cn.garymb.ygomobile.Constants; import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.Deck; import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.bean.DeckInfo; import cn.garymb.ygomobile.bean.DeckInfo;
import cn.garymb.ygomobile.ui.cards.deck.DeckItemType; import cn.garymb.ygomobile.ui.cards.deck.DeckItemType;
import cn.garymb.ygomobile.ui.cards.deck.DeckUtils;
import cn.garymb.ygomobile.utils.IOUtils; import cn.garymb.ygomobile.utils.IOUtils;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import ocgcore.data.Card; import ocgcore.data.Card;
...@@ -26,17 +29,17 @@ import ocgcore.data.LimitList; ...@@ -26,17 +29,17 @@ import ocgcore.data.LimitList;
public class DeckLoader { public class DeckLoader {
public static DeckInfo readDeck(CardLoader cardLoader, File file, LimitList limitList) { public static DeckInfo readDeck(CardLoader cardLoader, File file, LimitList limitList) {
DeckInfo deckInfo = null; DeckInfo deckInfo = null;
FileInputStream inputStream = null; FileInputStream fileinputStream = null;
try { try {
inputStream = new FileInputStream(file); fileinputStream = new FileInputStream(file);
deckInfo = readDeck(cardLoader, inputStream, limitList); deckInfo = readDeck(cardLoader, fileinputStream, limitList);
if (deckInfo != null) { if (deckInfo != null) {
deckInfo.source = file; deckInfo.source = file;
} }
} catch (Exception e) { } catch (Exception e) {
Log.e("deckreader", "read 1", e); Log.e("deckreader", "read 1", e);
} finally { } finally {
IOUtils.close(inputStream); IOUtils.close(fileinputStream);
} }
return deckInfo; return deckInfo;
} }
...@@ -76,10 +79,6 @@ public class DeckLoader { ...@@ -76,10 +79,6 @@ public class DeckLoader {
if (type == DeckItemType.MainCard && deck.getMainCount() < Constants.DECK_MAIN_MAX) { if (type == DeckItemType.MainCard && deck.getMainCount() < Constants.DECK_MAIN_MAX) {
Integer i = mIds.get(id); Integer i = mIds.get(id);
if (i == null) { if (i == null) {
if (ArrayUtil.contains(oldIDsArray, id)) {
id = ArrayUtil.get(newIDsArray,id);
Log.i("3.10.1","看看id="+id);
}
mIds.put(id, 1); mIds.put(id, 1);
deck.addMain(id); deck.addMain(id);
} else if (i < Constants.CARD_MAX_COUNT) { } else if (i < Constants.CARD_MAX_COUNT) {
...@@ -113,18 +112,41 @@ public class DeckLoader { ...@@ -113,18 +112,41 @@ public class DeckLoader {
} }
DeckInfo deckInfo = new DeckInfo(); DeckInfo deckInfo = new DeckInfo();
SparseArray<Card> tmp = cardLoader.readCards(deck.getMainlist(), true); SparseArray<Card> tmp = cardLoader.readCards(deck.getMainlist(), true);
int code;
boolean isChanged = false;
for (Integer id : deck.getMainlist()) { for (Integer id : deck.getMainlist()) {
if (ArrayUtil.contains(oldIDsArray, tmp.get(id).getCode())) {
code = ArrayUtil.get(newIDsArray, ArrayUtil.indexOf(oldIDsArray, tmp.get(id).getCode()));
tmp.remove(id);
tmp.put(id, cardLoader.readAllCardCodes().get(code));
isChanged = true;
}
deckInfo.addMainCards(tmp.get(id)); deckInfo.addMainCards(tmp.get(id));
} }
tmp = cardLoader.readCards(deck.getExtraList(), true); tmp = cardLoader.readCards(deck.getExtraList(), true);
for (Integer id : deck.getExtraList()) { for (Integer id : deck.getExtraList()) {
if (ArrayUtil.contains(oldIDsArray, tmp.get(id).getCode())) {
code = ArrayUtil.get(newIDsArray, ArrayUtil.indexOf(oldIDsArray, tmp.get(id).getCode()));
tmp.remove(id);
tmp.put(id, cardLoader.readAllCardCodes().get(code));
isChanged = true;
}
deckInfo.addExtraCards(tmp.get(id)); deckInfo.addExtraCards(tmp.get(id));
} }
tmp = cardLoader.readCards(deck.getSideList(), true); tmp = cardLoader.readCards(deck.getSideList(), true);
// Log.i("kk", "desk:" + tmp.size()+"/"+side.size()); // Log.i("kk", "desk:" + tmp.size()+"/"+side.size());
for (Integer id : deck.getSideList()) { for (Integer id : deck.getSideList()) {
if (ArrayUtil.contains(oldIDsArray, tmp.get(id).getCode())) {
code = ArrayUtil.get(newIDsArray, ArrayUtil.indexOf(oldIDsArray, tmp.get(id).getCode()));
tmp.remove(id);
tmp.put(id, cardLoader.readAllCardCodes().get(code));
isChanged = true;
}
deckInfo.addSideCards(tmp.get(id)); deckInfo.addSideCards(tmp.get(id));
} }
if (isChanged) {
//DeckUtils.save(deckInfo,inputStream.read());
}
return deckInfo; return deckInfo;
} }
} }
package cn.garymb.ygomobile.utils; package cn.garymb.ygomobile.utils;
import static cn.garymb.ygomobile.Constants.newIDsArray;
import static cn.garymb.ygomobile.Constants.oldIDsArray;
import android.content.Context; import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
...@@ -24,6 +27,7 @@ import cn.garymb.ygomobile.bean.DeckType; ...@@ -24,6 +27,7 @@ import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.DeckFile; import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.cards.deck.DeckItemType; import cn.garymb.ygomobile.ui.cards.deck.DeckItemType;
import cn.hutool.core.util.ArrayUtil;
public class DeckUtil { public class DeckUtil {
...@@ -212,6 +216,9 @@ public class DeckUtil { ...@@ -212,6 +216,9 @@ public class DeckUtil {
continue; continue;
} }
Integer id = Integer.parseInt(line); Integer id = Integer.parseInt(line);
if (ArrayUtil.contains(oldIDsArray, id)) {
id = ArrayUtil.get(newIDsArray, ArrayUtil.indexOf(oldIDsArray, id));
}
return id; return id;
} }
} catch (IOException e) { } catch (IOException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment