Commit 76406cf5 authored by nanahira's avatar nanahira

Merge branch 'deck_code' into Android

parents c56628f5 85d0d79b
......@@ -1068,7 +1068,7 @@ public class Program : MonoBehaviour
_padScroll = 0;
}
GUI.Label(new Rect(10, 5, 200, 200), "[Ver 1.034.9-7] " + "FPS: " + m_FPS);
GUI.Label(new Rect(10, 5, 200, 200), "[Ver 1.034.9-8] " + "FPS: " + m_FPS);
}
void Update()
......
......@@ -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, out 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, out 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 = new 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 static 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)
......
......@@ -1415,7 +1415,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 12800000, guid: f775853fdfd14bb47934543e95c3bae3, type: 3}
mFont: {fileID: 0}
mText: KoishiPro2 iOS 1.034.9-7
mText: KoishiPro2 iOS 1.034.9-8
mFontSize: 18
mFontStyle: 0
mAlignment: 1
......
......@@ -123,7 +123,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.034.9-7
bundleVersion: 1.034.9-8
preloadedAssets: []
metroInputSource: 0
m_HolographicPauseOnTrackingLoss: 1
......
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