Commit 83ad5777 authored by nanahira's avatar nanahira

test deck code

parent c56628f5
......@@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using YGOSharp.OCGWrapper.Enums;
using YGOSharp.OCGWrapper.Enums;
public class selectDeck : WindowServantSP
{
......@@ -187,6 +187,41 @@ public class selectDeck : WindowServantSP
RMSshow_none(InterString.Get("非法输入!请检查输入的文件名。"));
}
}
if (hashCode == "onCode")
{
if(result[0].value != "") {
try
{
YGOSharp.Deck deck;
if(!deckManager.FromBase64toCodedDeck(result[0].value, deck))
{
RMSshow_none(InterString.Get("卡组代码无效。"));
return;
}
string value = "#created by ygopro2\r\n#main\r\n";
for (int i = 0; i < deck.Main.Count; i++)
{
value += deck.Main[i].ToString() + "\r\n";
}
value += "#extra\r\n";
for (int i = 0; i < deck.Extra.Count; i++)
{
value += deck.Extra[i].ToString() + "\r\n";
}
value += "!side\r\n";
for (int i = 0; i < deck.Side.Count; i++)
{
value += deck.Side[i].ToString() + "\r\n";
}
System.IO.File.WriteAllText("deck/" + superScrollView.selectedString + ".ydk", value, System.Text.Encoding.UTF8);
printSelected();
}
catch (Exception)
{
RMSshow_none(InterString.Get("卡组代码无效。"));
}
}
}
}
void onNew()
......@@ -255,6 +290,7 @@ public class selectDeck : WindowServantSP
string path = "deck/" + superScrollView.selectedString + ".ydk";
if (File.Exists(path))
{
/*
#if UNITY_EDITOR || UNITY_STANDALONE_WIN //编译器、Windows
System.Diagnostics.Process.Start("notepad.exe", path);
#elif UNITY_STANDALONE_OSX //Mac OS X
......@@ -266,6 +302,15 @@ public class selectDeck : WindowServantSP
jo.Call("openFile", Program.ANDROID_GAME_PATH + path);
//#elif UNITY_IPHONE //iPhone
#endif
*/
YGOSharp.Deck deck;
deckManager.FromYDKtoCodedDeck(path, deck);
string default_string;
if(deck.Main.Count > 0 || deck.Extra.Count > 0 || deck.Side.Count > 0)
default_string = deckManager.convertDeckToBase64(deck);
else
default_string = "";
RMSshow_input("onCode", InterString.Get("卡组代码"), default_string);
}
}
......
......@@ -1530,6 +1530,79 @@ public class DeckManager : ServantWithCardDescription
}
}
public static bool FromBase64toCodedDeck(string base64, out YGOSharp.Deck deck) {
deck = new YGOSharp.Deck();
bool res = true;
try
{
byte[] buffer = Convert.FromBase64String(base64);
int offset = 0;
int mainc = BitConverter.ToInt32(buffer, offset);
offset += 4;
int sidec = BitConverter.ToInt32(buffer, offset);
offset += 4;
for(int i = 0; i < mainc; ++i) {
int code = BitConverter.ToInt32(buffer, offset);
offset += 4;
if (code > 100)
{
YGOSharp.Card card = YGOSharp.CardsManager.Get(code);
if (card.Id > 0 && card.IsExtraCard())
{
deck.Extra.Add(code);
deck.Deck_O.Extra.Add(code);
}
else
{
deck.Main.Add(code);
deck.Deck_O.Main.Add(code);
}
}
}
for(int i = 0; i < sidec; ++i) {
int code = BitConverter.ToInt32(buffer, offset);
offset += 4;
if (code > 100)
{
deck.Side.Add(code);
deck.Deck_O.Side.Add(code);
}
}
}
catch (Exception e)
{
res = false;
}
return res;
}
public static string convertDeckToBase64(YGOSharp.Deck deck) {
List<byte> array_list = List<byte>();
writeInt32ToList(array_list, deck.Main.Count + deck.Extra.Count);
writeInt32ToList(array_list, deck.Side.Count);
for (int i = 0; i < deck.Main.Count; i++)
{
writeInt32ToList(array_list, deck.Main[i]);
}
for (int i = 0; i < deck.Extra.Count; i++)
{
writeInt32ToList(array_list, deck.Extra[i]);
}
for (int i = 0; i < deck.Side.Count; i++)
{
writeInt32ToList(array_list, deck.Side[i]);
}
byte[] buffer = array_list.ToArray();
return Convert.ToBase64String(buffer);
}
private void writeInt32ToList(List<byte> array_list, int value) {
byte[] int_buffer = BitConverter.GetBytes(value);
for(int i = 0; i < 4; ++i) {
array_list.Add(int_buffer[i]);
}
}
public YGOSharp.Deck getRealDeck()
{
if (canSave)
......
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