Commit 3b1132f8 authored by keyongyu's avatar keyongyu

2.3.2.0

parent 522136b9
/*
* 由SharpDevelop创建。
* 用户: Acer
* 日期: 2015-5-24
* 时间: 10:55
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using System.Text;
using System.IO;
namespace DataEditorX.Common
{
/// <summary>
/// Description of MyUtils.
/// </summary>
public class MyUtils
{
/// <summary>
/// 计算文件的MD5校验
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string GetMD5HashFromFile(string fileName)
{
try
{
FileStream file = new FileStream(fileName, FileMode.Open);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
catch
{
}
return "";
}
public static bool Md5isEmpty(string md5){
return md5==null||md5.Length<16;
}
}
}
...@@ -8,7 +8,7 @@ public class StrUtil ...@@ -8,7 +8,7 @@ public class StrUtil
{ {
public static string AutoEnter(string str, int lineNum, char re) public static string AutoEnter(string str, int lineNum, char re)
{ {
if (str == null || str.Length == 0 || re == null) if (str == null || str.Length == 0)
return str; return str;
str = str.Replace("\r\n", "\n"); str = str.Replace("\r\n", "\n");
char[] ch = str.ToCharArray(); char[] ch = str.ToCharArray();
......
...@@ -17,143 +17,164 @@ ...@@ -17,143 +17,164 @@
namespace DataEditorX.Core.Mse namespace DataEditorX.Core.Mse
{ {
/// <summary> /// <summary>
/// Description of MSEConfig. /// Description of MSEConfig.
/// </summary> /// </summary>
public class MSEConfig public class MSEConfig
{ {
#region 常量 #region 常量
public const string TAG = "mse"; public const string TAG = "mse";
/// <summary>存档头部</summary> /// <summary>存档头部</summary>
public const string TAG_HEAD = "head"; public const string TAG_HEAD = "head";
/// <summary>存档尾部</summary> /// <summary>存档尾部</summary>
public const string TAG_END = "end"; public const string TAG_END = "end";
/// <summary>简体转繁体</summary> /// <summary>简体转繁体</summary>
public const string TAG_CN2TW = "cn2tw"; public const string TAG_CN2TW = "cn2tw";
/// <summary>魔法标志格式</summary> /// <summary>魔法标志格式</summary>
public const string TAG_SPELL = "spell"; public const string TAG_SPELL = "spell";
/// <summary>陷阱标志格式</summary> /// <summary>陷阱标志格式</summary>
public const string TAG_TRAP = "trap"; public const string TAG_TRAP = "trap";
public const string TAG_REG_PENDULUM = "pendulum-text"; public const string TAG_REG_PENDULUM = "pendulum-text";
public const string TAG_REG_MONSTER = "monster-text"; public const string TAG_REG_MONSTER = "monster-text";
public const string TAG_MAXCOUNT = "maxcount"; public const string TAG_MAXCOUNT = "maxcount";
public const string TAG_RACE = "race"; public const string TAG_RACE = "race";
public const string TAG_TYPE = "type"; public const string TAG_TYPE = "type";
public const string TAG_WIDTH="width";
public const string TAG_HEIGHT="height";
public const string TAG_IMAGE = "imagepath"; public const string TAG_IMAGE = "imagepath";
public const string TAG_REPALCE = "replace"; public const string TAG_REPALCE = "replace";
public const string TAG_TEXT = "text"; public const string TAG_TEXT = "text";
public const string TAG_REP = "%%"; public const string TAG_REP = "%%";
public const string SEP_LINE = " "; public const string SEP_LINE = " ";
//默认的配置 //默认的配置
public const string FILE_CONFIG_NAME = "Chinese-Simplified"; public const string FILE_CONFIG_NAME = "Chinese-Simplified";
public const string PATH_IMAGE = "Images"; public const string PATH_IMAGE = "Images";
public string configName = FILE_CONFIG_NAME; public string configName = FILE_CONFIG_NAME;
#endregion #endregion
public MSEConfig(string path) public MSEConfig(string path)
{ {
init(path); init(path);
} }
public void SetConfig(string config, string path) public void SetConfig(string config, string path)
{ {
if (!File.Exists(config)) if (!File.Exists(config))
return; return;
regx_monster = "(\\s\\S*?)"; regx_monster = "(\\s\\S*?)";
regx_pendulum = "(\\s\\S*?)"; regx_pendulum = "(\\s\\S*?)";
//设置文件名 //设置文件名
configName = MyPath.getFullFileName(MSEConfig.TAG, config); configName = MyPath.getFullFileName(MSEConfig.TAG, config);
replaces = new SortedList<string, string>(); replaces = new SortedList<string, string>();
typeDic = new SortedList<long, string>(); typeDic = new SortedList<long, string>();
raceDic = new SortedList<long, string>(); raceDic = new SortedList<long, string>();
string[] lines = File.ReadAllLines(config, Encoding.UTF8); string[] lines = File.ReadAllLines(config, Encoding.UTF8);
foreach (string line in lines) foreach (string line in lines)
{ {
if (string.IsNullOrEmpty(line) || line.StartsWith("#")) if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
continue; continue;
if (line.StartsWith(TAG_CN2TW)) if (line.StartsWith(TAG_CN2TW))
Iscn2tw = ConfHelper.getBooleanValue(line); Iscn2tw = ConfHelper.getBooleanValue(line);
else if (line.StartsWith(TAG_SPELL)) else if (line.StartsWith(TAG_SPELL))
str_spell = ConfHelper.getValue(line); str_spell = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_HEAD)) else if (line.StartsWith(TAG_HEAD))
head = ConfHelper.getMultLineValue(line); head = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_END)) else if (line.StartsWith(TAG_END))
end = ConfHelper.getMultLineValue(line); end = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_TEXT)) else if (line.StartsWith(TAG_TEXT))
temp_text = ConfHelper.getMultLineValue(line); temp_text = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_TRAP)) else if (line.StartsWith(TAG_TRAP))
str_trap = ConfHelper.getValue(line); str_trap = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_REG_PENDULUM)) else if (line.StartsWith(TAG_REG_PENDULUM))
regx_pendulum = ConfHelper.getValue(line); regx_pendulum = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_REG_MONSTER)) else if (line.StartsWith(TAG_REG_MONSTER))
regx_monster = ConfHelper.getValue(line); regx_monster = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_MAXCOUNT)) else if (line.StartsWith(TAG_MAXCOUNT))
maxcount = ConfHelper.getIntegerValue(line, 0); maxcount = ConfHelper.getIntegerValue(line, 0);
else if (line.StartsWith(TAG_IMAGE)) else if (line.StartsWith(TAG_WIDTH)){
{ width=ConfHelper.getIntegerValue(line,0);
//如果路径不合法,则为后面的路径 }
imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, PATH_IMAGE)); else if (line.StartsWith(TAG_HEIGHT)){
} height=ConfHelper.getIntegerValue(line,0);
else if (line.StartsWith(TAG_REPALCE)) }
{//特数字替换 else if (line.StartsWith(TAG_IMAGE))
string word = ConfHelper.getValue(line); {
string p = ConfHelper.getRegex(ConfHelper.getValue1(word)); //如果路径不合法,则为后面的路径
string r = ConfHelper.getRegex(ConfHelper.getValue2(word)); imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, PATH_IMAGE));
if (!string.IsNullOrEmpty(p)) //图片缓存目录
replaces.Add(p, r); imagecache = MyPath.Combine(imagepath, "cache");
MyPath.CreateDir(imagecache);
}
else if (line.StartsWith(TAG_REPALCE))
{//特数字替换
string word = ConfHelper.getValue(line);
string p = ConfHelper.getRegex(ConfHelper.getValue1(word));
string r = ConfHelper.getRegex(ConfHelper.getValue2(word));
if (!string.IsNullOrEmpty(p))
replaces.Add(p, r);
} }
else if (line.StartsWith(TAG_RACE)) else if (line.StartsWith(TAG_RACE))
{//种族 {//种族
ConfHelper.DicAdd(raceDic, line); ConfHelper.DicAdd(raceDic, line);
} }
else if (line.StartsWith(TAG_TYPE)) else if (line.StartsWith(TAG_TYPE))
{//类型 {//类型
ConfHelper.DicAdd(typeDic, line); ConfHelper.DicAdd(typeDic, line);
} }
} }
} }
public void init(string path) public void init(string path)
{ {
Iscn2tw = false; Iscn2tw = false;
//读取配置 //读取配置
string tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, MyConfig.readString(MyConfig.TAG_MSE))); string tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, MyConfig.readString(MyConfig.TAG_MSE)));
if (!File.Exists(tmp)) if (!File.Exists(tmp))
{ {
tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, FILE_CONFIG_NAME)); tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, FILE_CONFIG_NAME));
if(!File.Exists(tmp)) if(!File.Exists(tmp))
return;//如果默认的也不存在 return;//如果默认的也不存在
} }
SetConfig(tmp, path); SetConfig(tmp, path);
} }
/// <summary>
/// 中间图宽度
//每个存档最大数 /// </summary>
public int maxcount; public int width;
//图片路径 /// <summary>
public string imagepath; /// 中间图高度
//魔法标志 /// </summary>
public string str_spell; public int height;
//陷阱标志 //每个存档最大数
public string str_trap; public int maxcount;
//效果格式 //图片路径
public string temp_text; public string imagepath;
//简体转繁体? /// <summary>
public bool Iscn2tw; /// 图片缓存路径
//特数字替换 /// </summary>
public SortedList<string, string> replaces; public string imagecache;
//效果文正则提取 //魔法标志
public string regx_pendulum; public string str_spell;
public string regx_monster; //陷阱标志
//存档头部 public string str_trap;
public string head; //效果格式
//存档结尾 public string temp_text;
public string end; //简体转繁体?
public SortedList<long, string> typeDic; public bool Iscn2tw;
public SortedList<long, string> raceDic; //特数字替换
} public SortedList<string, string> replaces;
//效果文正则提取
public string regx_pendulum;
public string regx_monster;
//存档头部
public string head;
//存档结尾
public string end;
public SortedList<long, string> typeDic;
public SortedList<long, string> raceDic;
}
} }
...@@ -11,714 +11,736 @@ ...@@ -11,714 +11,736 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using System.Drawing;
using DataEditorX.Core.Info; using DataEditorX.Core.Info;
using DataEditorX.Config; using DataEditorX.Config;
using DataEditorX.Language; using DataEditorX.Language;
using DataEditorX.Common;
namespace DataEditorX.Core.Mse namespace DataEditorX.Core.Mse
{ {
/// <summary> /// <summary>
/// MSE制作 /// MSE制作
/// </summary> /// </summary>
public class MseMaker public class MseMaker
{ {
#region 常量 #region 常量
public const string TAG_CARD = "card"; public const string TAG_CARD = "card";
public const string TAG_CARDTYPE = "card type"; public const string TAG_CARDTYPE = "card type";
public const string TAG_NAME = "name"; public const string TAG_NAME = "name";
public const string TAG_ATTRIBUTE = "attribute"; public const string TAG_ATTRIBUTE = "attribute";
public const string TAG_LEVEL = "level"; public const string TAG_LEVEL = "level";
public const string TAG_IMAGE = "image"; public const string TAG_IMAGE = "image";
/// <summary>种族</summary> /// <summary>种族</summary>
public const string TAG_TYPE1 = "type 1"; public const string TAG_TYPE1 = "type 1";
/// <summary>效果1</summary> /// <summary>效果1</summary>
public const string TAG_TYPE2 = "type 2"; public const string TAG_TYPE2 = "type 2";
/// <summary>效果2/summary> /// <summary>效果2/summary>
public const string TAG_TYPE3 = "type 3"; public const string TAG_TYPE3 = "type 3";
/// <summary>效果3</summary> /// <summary>效果3</summary>
public const string TAG_TYPE4 = "type 4"; public const string TAG_TYPE4 = "type 4";
public const string TAG_TEXT = "rule text"; public const string TAG_TEXT = "rule text";
public const string TAG_ATK = "attack"; public const string TAG_ATK = "attack";
public const string TAG_DEF = "defense"; public const string TAG_DEF = "defense";
public const string TAG_PENDULUM = "pendulum"; public const string TAG_PENDULUM = "pendulum";
public const string TAG_PSCALE1 = "pendulum scale 1"; public const string TAG_PSCALE1 = "pendulum scale 1";
public const string TAG_PSCALE2 = "pendulum scale 2"; public const string TAG_PSCALE2 = "pendulum scale 2";
public const string TAG_PEND_TEXT = "pendulum text"; public const string TAG_PEND_TEXT = "pendulum text";
public const string TAG_CODE = "gamecode"; public const string TAG_CODE = "gamecode";
public const string UNKNOWN_ATKDEF = "?"; public const string UNKNOWN_ATKDEF = "?";
public const int UNKNOWN_ATKDEF_VALUE = -2; public const int UNKNOWN_ATKDEF_VALUE = -2;
public const string TAG_REP_TEXT = "%text%"; public const string TAG_REP_TEXT = "%text%";
public const string TAG_REP_PTEXT = "%ptext%"; public const string TAG_REP_PTEXT = "%ptext%";
#endregion #endregion
#region 成员,初始化 #region 成员,初始化
MSEConfig cfg; MSEConfig cfg;
public int MaxNum public int MaxNum
{ {
get { return cfg.maxcount; } get { return cfg.maxcount; }
} }
public string ImagePath public string ImagePath
{ {
get { return cfg.imagepath; } get { return cfg.imagepath; }
} }
public MseMaker(MSEConfig mcfg) public MseMaker(MSEConfig mcfg)
{ {
SetConfig(mcfg); SetConfig(mcfg);
} }
public void SetConfig(MSEConfig mcfg) public void SetConfig(MSEConfig mcfg)
{ {
cfg = mcfg; cfg = mcfg;
} }
public MSEConfig GetConfig() public MSEConfig GetConfig()
{ {
return cfg; return cfg;
} }
#endregion #endregion
#region 数据处理 #region 数据处理
//合并 //合并
public string GetLine(string key, string word) public string GetLine(string key, string word)
{ {
return " " + key + ": " + word; return " " + key + ": " + word;
} }
//特殊字 //特殊字
public string reItalic(string str) public string reItalic(string str)
{ {
str = cn2tw(str); str = cn2tw(str);
foreach (string rs in cfg.replaces.Keys) foreach (string rs in cfg.replaces.Keys)
{ {
str = Regex.Replace(str, rs, cfg.replaces[rs]); str = Regex.Replace(str, rs, cfg.replaces[rs]);
} }
return str; return str;
} }
//简体转繁体 //简体转繁体
public string cn2tw(string str) public string cn2tw(string str)
{ {
if (cfg.Iscn2tw) if (cfg.Iscn2tw)
{ {
str = Strings.StrConv(str, VbStrConv.TraditionalChinese, 0); str = Strings.StrConv(str, VbStrConv.TraditionalChinese, 0);
str = str.Replace("巖", "岩"); str = str.Replace("巖", "岩");
} }
return str; return str;
} }
//获取魔法陷阱的类型符号 //获取魔法陷阱的类型符号
public string GetSpellTrapSymbol(Card c, bool isSpell) public string GetSpellTrapSymbol(Card c, bool isSpell)
{ {
string level; string level;
if (c.IsType(CardType.TYPE_EQUIP)) if (c.IsType(CardType.TYPE_EQUIP))
level = MseSpellTrap.EQUIP; level = MseSpellTrap.EQUIP;
else if (c.IsType(CardType.TYPE_QUICKPLAY)) else if (c.IsType(CardType.TYPE_QUICKPLAY))
level = MseSpellTrap.QUICKPLAY; level = MseSpellTrap.QUICKPLAY;
else if (c.IsType(CardType.TYPE_FIELD)) else if (c.IsType(CardType.TYPE_FIELD))
level = MseSpellTrap.FIELD; level = MseSpellTrap.FIELD;
else if (c.IsType(CardType.TYPE_CONTINUOUS)) else if (c.IsType(CardType.TYPE_CONTINUOUS))
level = MseSpellTrap.CONTINUOUS; level = MseSpellTrap.CONTINUOUS;
else if (c.IsType(CardType.TYPE_RITUAL)) else if (c.IsType(CardType.TYPE_RITUAL))
level = MseSpellTrap.RITUAL; level = MseSpellTrap.RITUAL;
else if (c.IsType(CardType.TYPE_COUNTER)) else if (c.IsType(CardType.TYPE_COUNTER))
level = MseSpellTrap.COUNTER; level = MseSpellTrap.COUNTER;
else if (cfg.str_spell == MSEConfig.TAG_REP && cfg.str_trap == MSEConfig.TAG_REP) else if (cfg.str_spell == MSEConfig.TAG_REP && cfg.str_trap == MSEConfig.TAG_REP)
level = MseSpellTrap.NORMAL;//带文字的图片 level = MseSpellTrap.NORMAL;//带文字的图片
else else
level = ""; level = "";
if (isSpell) if (isSpell)
level = cfg.str_spell.Replace(MSEConfig.TAG_REP, level); level = cfg.str_spell.Replace(MSEConfig.TAG_REP, level);
else else
level = cfg.str_trap.Replace(MSEConfig.TAG_REP, level); level = cfg.str_trap.Replace(MSEConfig.TAG_REP, level);
return level; return level;
} }
//获取图片路径 //获取图片路径
public static string GetCardImagePath(string picpath, Card c) public static string GetCardImagePath(string picpath, Card c)
{ {
//密码,带0密码,卡名 //密码,带0密码,卡名
string jpg = MyPath.Combine(picpath, c.id + ".jpg"); string jpg = MyPath.Combine(picpath, c.id + ".jpg");
string jpg2 = MyPath.Combine(picpath, c.idString + ".jpg"); string jpg2 = MyPath.Combine(picpath, c.idString + ".jpg");
string jpg3 = MyPath.Combine(picpath, c.name + ".jpg"); string jpg3 = MyPath.Combine(picpath, c.name + ".jpg");
string png = MyPath.Combine(picpath, c.id + ".png"); string png = MyPath.Combine(picpath, c.id + ".png");
string png2 = MyPath.Combine(picpath, c.idString + ".png"); string png2 = MyPath.Combine(picpath, c.idString + ".png");
string png3 = MyPath.Combine(picpath, c.name + ".png"); string png3 = MyPath.Combine(picpath, c.name + ".png");
if (File.Exists(jpg)) if (File.Exists(jpg))
{ {
return jpg; return jpg;
} }
else if (File.Exists(jpg2)) else if (File.Exists(jpg2))
{ {
return jpg2; return jpg2;
} }
else if (File.Exists(jpg3)) else if (File.Exists(jpg3))
{ {
File.Copy(jpg3, jpg, true); File.Copy(jpg3, jpg, true);
if (File.Exists(jpg)) if (File.Exists(jpg))
{//复制失败 {//复制失败
return jpg; return jpg;
} }
} }
else if (File.Exists(png)) else if (File.Exists(png))
{ {
return png; return png;
} }
else if (File.Exists(png2)) else if (File.Exists(png2))
{ {
return png2; return png2;
} }
else if (File.Exists(png3)) else if (File.Exists(png3))
{ {
File.Copy(png3, png, true); File.Copy(png3, png, true);
if (File.Exists(png)) if (File.Exists(png))
{//复制失败 {//复制失败
return png; return png;
} }
} }
return ""; return "";
} }
//获取属性 //获取属性
public static string GetAttribute(int attr) public static string GetAttribute(int attr)
{ {
CardAttribute cattr = (CardAttribute)attr; CardAttribute cattr = (CardAttribute)attr;
string sattr = MseAttribute.NONE; string sattr = MseAttribute.NONE;
switch (cattr) switch (cattr)
{ {
case CardAttribute.ATTRIBUTE_DARK: case CardAttribute.ATTRIBUTE_DARK:
sattr = MseAttribute.DARK; sattr = MseAttribute.DARK;
break; break;
case CardAttribute.ATTRIBUTE_DEVINE: case CardAttribute.ATTRIBUTE_DEVINE:
sattr = MseAttribute.DIVINE; sattr = MseAttribute.DIVINE;
break; break;
case CardAttribute.ATTRIBUTE_EARTH: case CardAttribute.ATTRIBUTE_EARTH:
sattr = MseAttribute.EARTH; sattr = MseAttribute.EARTH;
break; break;
case CardAttribute.ATTRIBUTE_FIRE: case CardAttribute.ATTRIBUTE_FIRE:
sattr = MseAttribute.FIRE; sattr = MseAttribute.FIRE;
break; break;
case CardAttribute.ATTRIBUTE_LIGHT: case CardAttribute.ATTRIBUTE_LIGHT:
sattr = MseAttribute.LIGHT; sattr = MseAttribute.LIGHT;
break; break;
case CardAttribute.ATTRIBUTE_WATER: case CardAttribute.ATTRIBUTE_WATER:
sattr = MseAttribute.WATER; sattr = MseAttribute.WATER;
break; break;
case CardAttribute.ATTRIBUTE_WIND: case CardAttribute.ATTRIBUTE_WIND:
sattr = MseAttribute.WIND; sattr = MseAttribute.WIND;
break; break;
} }
return sattr; return sattr;
} }
//获取效果文本 //获取效果文本
public static string GetDesc(string cdesc, string regx) public static string GetDesc(string cdesc, string regx)
{ {
string desc = cdesc; string desc = cdesc;
desc = desc.Replace("\r\n", "\n"); desc = desc.Replace("\r\n", "\n");
desc = desc.Replace("\r", "\n"); desc = desc.Replace("\r", "\n");
Regex regex = new Regex(regx, RegexOptions.Multiline); Regex regex = new Regex(regx, RegexOptions.Multiline);
Match mc = regex.Match(desc); Match mc = regex.Match(desc);
if (mc.Success) if (mc.Success)
return ((mc.Groups.Count > 1) ? return ((mc.Groups.Count > 1) ?
mc.Groups[1].Value : mc.Groups[0].Value) mc.Groups[1].Value : mc.Groups[0].Value)
.Trim('\n').Replace("\n", "\n\t\t"); .Trim('\n').Replace("\n", "\n\t\t");
return ""; return "";
} }
public string ReText(string text) public string ReText(string text)
{ {
StringBuilder sb = new StringBuilder(text); StringBuilder sb = new StringBuilder(text);
sb.Replace("\r\n", "\n"); sb.Replace("\r\n", "\n");
sb.Replace("\r", "\n"); sb.Replace("\r", "\n");
sb.Replace("\n\n", "\n"); sb.Replace("\n\n", "\n");
sb.Replace("\n", "\n\t\t"); sb.Replace("\n", "\n\t\t");
return sb.ToString().Trim('\n'); return sb.ToString().Trim('\n');
} }
//获取星星 //获取星星
public static string GetStar(long level) public static string GetStar(long level)
{ {
long j = level & 0xff; long j = level & 0xff;
string star = ""; string star = "";
for (int i = 0; i < j; i++) for (int i = 0; i < j; i++)
{ {
star += "*"; star += "*";
} }
return star; return star;
} }
//获取种族 //获取种族
public string GetRace(long race) public string GetRace(long race)
{ {
if (cfg.raceDic.ContainsKey(race)) if (cfg.raceDic.ContainsKey(race))
return cfg.raceDic[race].Trim(); return cfg.raceDic[race].Trim();
return race.ToString("x"); return race.ToString("x");
} }
//获取类型文字 //获取类型文字
public string GetType(CardType ctype) public string GetType(CardType ctype)
{ {
long type = (long)ctype; long type = (long)ctype;
if (cfg.typeDic.ContainsKey(type)) if (cfg.typeDic.ContainsKey(type))
return cfg.typeDic[type].Trim(); return cfg.typeDic[type].Trim();
return type.ToString("x"); return type.ToString("x");
} }
//获取卡片类型 //获取卡片类型
public string[] GetTypes(Card c) public string[] GetTypes(Card c)
{ {
//卡片类型,效果1,效果2,效果3 //卡片类型,效果1,效果2,效果3
string[] types = new string[] { string[] types = new string[] {
MseCardType.CARD_NORMAL, "", "", "" }; MseCardType.CARD_NORMAL, "", "", "" };
if (c.IsType(CardType.TYPE_MONSTER)) if (c.IsType(CardType.TYPE_MONSTER))
{//卡片类型和第1效果 {//卡片类型和第1效果
if (c.IsType(CardType.TYPE_XYZ)) if (c.IsType(CardType.TYPE_XYZ))
{ {
types[0] = MseCardType.CARD_XYZ; types[0] = MseCardType.CARD_XYZ;
types[1] = GetType(CardType.TYPE_XYZ); types[1] = GetType(CardType.TYPE_XYZ);
} }
else if (c.IsType(CardType.TYPE_TOKEN)) else if (c.IsType(CardType.TYPE_TOKEN))
{ {
types[0] = (c.race == 0) ? types[0] = (c.race == 0) ?
MseCardType.CARD_TOKEN2 MseCardType.CARD_TOKEN2
: MseCardType.CARD_TOKEN; : MseCardType.CARD_TOKEN;
types[1] = GetType(CardType.TYPE_TOKEN); types[1] = GetType(CardType.TYPE_TOKEN);
} }
else if (c.IsType(CardType.TYPE_RITUAL)) else if (c.IsType(CardType.TYPE_RITUAL))
{ {
types[0] = MseCardType.CARD_RITUAL; types[0] = MseCardType.CARD_RITUAL;
types[1] = GetType(CardType.TYPE_RITUAL); types[1] = GetType(CardType.TYPE_RITUAL);
} }
else if (c.IsType(CardType.TYPE_FUSION)) else if (c.IsType(CardType.TYPE_FUSION))
{ {
types[0] = MseCardType.CARD_FUSION; types[0] = MseCardType.CARD_FUSION;
types[1] = GetType(CardType.TYPE_FUSION); types[1] = GetType(CardType.TYPE_FUSION);
} }
else if (c.IsType(CardType.TYPE_SYNCHRO)) else if (c.IsType(CardType.TYPE_SYNCHRO))
{ {
types[0] = MseCardType.CARD_SYNCHRO; types[0] = MseCardType.CARD_SYNCHRO;
types[1] = GetType(CardType.TYPE_SYNCHRO); types[1] = GetType(CardType.TYPE_SYNCHRO);
} }
else if (c.IsType(CardType.TYPE_EFFECT)) else if (c.IsType(CardType.TYPE_EFFECT))
{ {
types[0] = MseCardType.CARD_EFFECT; types[0] = MseCardType.CARD_EFFECT;
} }
else else
types[0] = MseCardType.CARD_NORMAL; types[0] = MseCardType.CARD_NORMAL;
//同调 //同调
if (types[0] == MseCardType.CARD_SYNCHRO if (types[0] == MseCardType.CARD_SYNCHRO
|| types[0] == MseCardType.CARD_TOKEN) || types[0] == MseCardType.CARD_TOKEN)
{ {
if (c.IsType(CardType.TYPE_TUNER) if (c.IsType(CardType.TYPE_TUNER)
&& c.IsType(CardType.TYPE_EFFECT)) && c.IsType(CardType.TYPE_EFFECT))
{//调整效果 {//调整效果
types[2] = GetType(CardType.TYPE_TUNER); types[2] = GetType(CardType.TYPE_TUNER);
types[3] = GetType(CardType.TYPE_EFFECT); types[3] = GetType(CardType.TYPE_EFFECT);
} }
else if (c.IsType(CardType.TYPE_TUNER)) else if (c.IsType(CardType.TYPE_TUNER))
{ {
types[2] = GetType(CardType.TYPE_TUNER); types[2] = GetType(CardType.TYPE_TUNER);
} }
else if (c.IsType(CardType.TYPE_EFFECT)) else if (c.IsType(CardType.TYPE_EFFECT))
{ {
types[2] = GetType(CardType.TYPE_EFFECT); types[2] = GetType(CardType.TYPE_EFFECT);
} }
} }
else if (types[0] == MseCardType.CARD_NORMAL) else if (types[0] == MseCardType.CARD_NORMAL)
{ {
if (c.IsType(CardType.TYPE_PENDULUM))//灵摆 if (c.IsType(CardType.TYPE_PENDULUM))//灵摆
types[1] = GetType(CardType.TYPE_PENDULUM); types[1] = GetType(CardType.TYPE_PENDULUM);
else if (c.IsType(CardType.TYPE_TUNER))//调整 else if (c.IsType(CardType.TYPE_TUNER))//调整
types[1] = GetType(CardType.TYPE_TUNER); types[1] = GetType(CardType.TYPE_TUNER);
} }
else if (types[0] != MseCardType.CARD_EFFECT) else if (types[0] != MseCardType.CARD_EFFECT)
{//效果 {//效果
if (c.IsType(CardType.TYPE_EFFECT)) if (c.IsType(CardType.TYPE_EFFECT))
types[2] = GetType(CardType.TYPE_EFFECT); types[2] = GetType(CardType.TYPE_EFFECT);
} }
else else
{//效果怪兽 {//效果怪兽
types[2] = GetType(CardType.TYPE_EFFECT); types[2] = GetType(CardType.TYPE_EFFECT);
if (c.IsType(CardType.TYPE_PENDULUM)) if (c.IsType(CardType.TYPE_PENDULUM))
types[1] = GetType(CardType.TYPE_PENDULUM); types[1] = GetType(CardType.TYPE_PENDULUM);
else if (c.IsType(CardType.TYPE_TUNER)) else if (c.IsType(CardType.TYPE_TUNER))
types[1] = GetType(CardType.TYPE_TUNER); types[1] = GetType(CardType.TYPE_TUNER);
else if (c.IsType(CardType.TYPE_SPIRIT)) else if (c.IsType(CardType.TYPE_SPIRIT))
types[1] = GetType(CardType.TYPE_SPIRIT); types[1] = GetType(CardType.TYPE_SPIRIT);
else if (c.IsType(CardType.TYPE_TOON)) else if (c.IsType(CardType.TYPE_TOON))
types[1] = GetType(CardType.TYPE_TOON); types[1] = GetType(CardType.TYPE_TOON);
else if (c.IsType(CardType.TYPE_UNION)) else if (c.IsType(CardType.TYPE_UNION))
types[1] = GetType(CardType.TYPE_UNION); types[1] = GetType(CardType.TYPE_UNION);
else if (c.IsType(CardType.TYPE_DUAL)) else if (c.IsType(CardType.TYPE_DUAL))
types[1] = GetType(CardType.TYPE_DUAL); types[1] = GetType(CardType.TYPE_DUAL);
else if (c.IsType(CardType.TYPE_FLIP)) else if (c.IsType(CardType.TYPE_FLIP))
types[1] = GetType(CardType.TYPE_FLIP); types[1] = GetType(CardType.TYPE_FLIP);
else else
{ {
types[1] = GetType(CardType.TYPE_EFFECT); types[1] = GetType(CardType.TYPE_EFFECT);
types[2] = ""; types[2] = "";
} }
} }
} }
if (c.race == 0)//如果没有种族 if (c.race == 0)//如果没有种族
{ {
types[1] = ""; types[1] = "";
types[2] = ""; types[2] = "";
} }
return types; return types;
} }
#endregion #endregion
#region 写存档 #region 写存档
//写存档 //写存档
public string[] WriteSet(string file, Card[] cards) public string[] WriteSet(string file, Card[] cards)
{ {
List<string> list = new List<string>(); List<string> list = new List<string>();
string pic = cfg.imagepath; string pic = cfg.imagepath;
using (FileStream fs = new FileStream(file, using (FileStream fs = new FileStream(file,
FileMode.Create, FileAccess.Write)) FileMode.Create, FileAccess.Write))
{ {
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine(cfg.head); sw.WriteLine(cfg.head);
foreach (Card c in cards) foreach (Card c in cards)
{ {
string jpg = GetCardImagePath(pic, c); string jpg = GetCardImagePath(pic, c);
if (!string.IsNullOrEmpty(jpg)) if (!string.IsNullOrEmpty(jpg))
{ {
list.Add(jpg); list.Add(jpg);
jpg = Path.GetFileName(jpg); jpg = Path.GetFileName(jpg);
} }
if (c.IsType(CardType.TYPE_SPELL) || c.IsType(CardType.TYPE_TRAP)) if (c.IsType(CardType.TYPE_SPELL) || c.IsType(CardType.TYPE_TRAP))
sw.WriteLine(getSpellTrap(c, jpg, c.IsType(CardType.TYPE_SPELL))); sw.WriteLine(getSpellTrap(c, jpg, c.IsType(CardType.TYPE_SPELL)));
else else
sw.WriteLine(getMonster(c, jpg, c.IsType(CardType.TYPE_PENDULUM))); sw.WriteLine(getMonster(c, jpg, c.IsType(CardType.TYPE_PENDULUM)));
} }
sw.WriteLine(cfg.end); sw.WriteLine(cfg.end);
sw.Close(); sw.Close();
} }
return list.ToArray(); return list.ToArray();
} }
//怪兽,pendulum怪兽 //怪兽,pendulum怪兽
string getMonster(Card c, string img, bool isPendulum) string getMonster(Card c, string img, bool isPendulum)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
string[] types = GetTypes(c); string[] types = GetTypes(c);
string race = GetRace(c.race); string race = GetRace(c.race);
sb.AppendLine(TAG_CARD + ":"); sb.AppendLine(TAG_CARD + ":");
sb.AppendLine(GetLine(TAG_CARDTYPE, types[0])); sb.AppendLine(GetLine(TAG_CARDTYPE, types[0]));
sb.AppendLine(GetLine(TAG_NAME, reItalic(c.name))); sb.AppendLine(GetLine(TAG_NAME, reItalic(c.name)));
sb.AppendLine(GetLine(TAG_ATTRIBUTE, GetAttribute(c.attribute))); sb.AppendLine(GetLine(TAG_ATTRIBUTE, GetAttribute(c.attribute)));
sb.AppendLine(GetLine(TAG_LEVEL, GetStar(c.level))); sb.AppendLine(GetLine(TAG_LEVEL, GetStar(c.level)));
sb.AppendLine(GetLine(TAG_IMAGE, img)); sb.AppendLine(GetLine(TAG_IMAGE, img));
sb.AppendLine(GetLine(TAG_TYPE1, cn2tw(race))); sb.AppendLine(GetLine(TAG_TYPE1, cn2tw(race)));
sb.AppendLine(GetLine(TAG_TYPE2, cn2tw(types[1]))); sb.AppendLine(GetLine(TAG_TYPE2, cn2tw(types[1])));
sb.AppendLine(GetLine(TAG_TYPE3, cn2tw(types[2]))); sb.AppendLine(GetLine(TAG_TYPE3, cn2tw(types[2])));
sb.AppendLine(GetLine(TAG_TYPE4, cn2tw(types[3]))); sb.AppendLine(GetLine(TAG_TYPE4, cn2tw(types[3])));
if (isPendulum)//P怪兽 if (isPendulum)//P怪兽
{ {
string text = GetDesc(c.desc, cfg.regx_monster); string text = GetDesc(c.desc, cfg.regx_monster);
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
text = ReText(c.desc); text = ReText(c.desc);
sb.AppendLine(" " + TAG_TEXT + ":"); sb.AppendLine(" " + TAG_TEXT + ":");
//sb.AppendLine(cfg.regx_monster + ":" + cfg.regx_pendulum); //sb.AppendLine(cfg.regx_monster + ":" + cfg.regx_pendulum);
sb.AppendLine(" " + reItalic(text)); sb.AppendLine(" " + reItalic(text));
sb.AppendLine(GetLine(TAG_PENDULUM, "medium")); sb.AppendLine(GetLine(TAG_PENDULUM, "medium"));
sb.AppendLine(GetLine(TAG_PSCALE1, ((c.level >> 0x18) & 0xff).ToString())); sb.AppendLine(GetLine(TAG_PSCALE1, ((c.level >> 0x18) & 0xff).ToString()));
sb.AppendLine(GetLine(TAG_PSCALE2, ((c.level >> 0x10) & 0xff).ToString())); sb.AppendLine(GetLine(TAG_PSCALE2, ((c.level >> 0x10) & 0xff).ToString()));
sb.AppendLine(" " + TAG_PEND_TEXT + ":"); sb.AppendLine(" " + TAG_PEND_TEXT + ":");
sb.AppendLine(" " + reItalic(GetDesc(c.desc, cfg.regx_pendulum))); sb.AppendLine(" " + reItalic(GetDesc(c.desc, cfg.regx_pendulum)));
} }
else//一般怪兽 else//一般怪兽
{ {
sb.AppendLine(" " + TAG_TEXT + ":"); sb.AppendLine(" " + TAG_TEXT + ":");
sb.AppendLine(" " + reItalic(ReText(c.desc))); sb.AppendLine(" " + reItalic(ReText(c.desc)));
} }
sb.AppendLine(GetLine(TAG_ATK, (c.atk < 0) ? UNKNOWN_ATKDEF : c.atk.ToString())); sb.AppendLine(GetLine(TAG_ATK, (c.atk < 0) ? UNKNOWN_ATKDEF : c.atk.ToString()));
sb.AppendLine(GetLine(TAG_DEF, (c.def < 0) ? UNKNOWN_ATKDEF : c.def.ToString())); sb.AppendLine(GetLine(TAG_DEF, (c.def < 0) ? UNKNOWN_ATKDEF : c.def.ToString()));
sb.AppendLine(GetLine(TAG_CODE, c.idString)); sb.AppendLine(GetLine(TAG_CODE, c.idString));
return sb.ToString(); return sb.ToString();
} }
//魔法陷阱 //魔法陷阱
string getSpellTrap(Card c, string img, bool isSpell) string getSpellTrap(Card c, string img, bool isSpell)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine(TAG_CARD + ":"); sb.AppendLine(TAG_CARD + ":");
sb.AppendLine(GetLine(TAG_CARDTYPE, isSpell ? "spell card" : "trap card")); sb.AppendLine(GetLine(TAG_CARDTYPE, isSpell ? "spell card" : "trap card"));
sb.AppendLine(GetLine(TAG_NAME, reItalic(c.name))); sb.AppendLine(GetLine(TAG_NAME, reItalic(c.name)));
sb.AppendLine(GetLine(TAG_ATTRIBUTE, isSpell ? "spell" : "trap")); sb.AppendLine(GetLine(TAG_ATTRIBUTE, isSpell ? "spell" : "trap"));
sb.AppendLine(GetLine(TAG_LEVEL, GetSpellTrapSymbol(c, isSpell))); sb.AppendLine(GetLine(TAG_LEVEL, GetSpellTrapSymbol(c, isSpell)));
sb.AppendLine(GetLine(TAG_IMAGE, img)); sb.AppendLine(GetLine(TAG_IMAGE, img));
sb.AppendLine(" " + TAG_TEXT + ":"); sb.AppendLine(" " + TAG_TEXT + ":");
sb.AppendLine(" " + reItalic(ReText(c.desc))); sb.AppendLine(" " + reItalic(ReText(c.desc)));
sb.AppendLine(GetLine(TAG_CODE, c.idString)); sb.AppendLine(GetLine(TAG_CODE, c.idString));
return sb.ToString(); return sb.ToString();
} }
#endregion #endregion
#region 读存档 #region 读存档
public static int GetAttributeInt(string cattr) public static int GetAttributeInt(string cattr)
{ {
int iattr = 0; int iattr = 0;
switch (cattr) switch (cattr)
{ {
case MseAttribute.DARK: case MseAttribute.DARK:
iattr = (int)CardAttribute.ATTRIBUTE_DARK; iattr = (int)CardAttribute.ATTRIBUTE_DARK;
break; break;
case MseAttribute.DIVINE: case MseAttribute.DIVINE:
iattr = (int)CardAttribute.ATTRIBUTE_DEVINE; iattr = (int)CardAttribute.ATTRIBUTE_DEVINE;
break; break;
case MseAttribute.EARTH: case MseAttribute.EARTH:
iattr = (int)CardAttribute.ATTRIBUTE_EARTH; iattr = (int)CardAttribute.ATTRIBUTE_EARTH;
break; break;
case MseAttribute.FIRE: case MseAttribute.FIRE:
iattr = (int)CardAttribute.ATTRIBUTE_FIRE; iattr = (int)CardAttribute.ATTRIBUTE_FIRE;
break; break;
case MseAttribute.LIGHT: case MseAttribute.LIGHT:
iattr = (int)CardAttribute.ATTRIBUTE_LIGHT; iattr = (int)CardAttribute.ATTRIBUTE_LIGHT;
break; break;
case MseAttribute.WATER: case MseAttribute.WATER:
iattr = (int)CardAttribute.ATTRIBUTE_WATER; iattr = (int)CardAttribute.ATTRIBUTE_WATER;
break; break;
case MseAttribute.WIND: case MseAttribute.WIND:
iattr = (int)CardAttribute.ATTRIBUTE_WIND; iattr = (int)CardAttribute.ATTRIBUTE_WIND;
break; break;
} }
return iattr; return iattr;
} }
long GetRaceInt(string race) long GetRaceInt(string race)
{ {
if (!string.IsNullOrEmpty(race)) if (!string.IsNullOrEmpty(race))
{ {
foreach (long key in cfg.raceDic.Keys) foreach (long key in cfg.raceDic.Keys)
{ {
if (race.Equals(cfg.raceDic[key])) if (race.Equals(cfg.raceDic[key]))
return key; return key;
} }
} }
return (long)CardRace.RACE_NONE; return (long)CardRace.RACE_NONE;
} }
long GetTypeInt(string type) long GetTypeInt(string type)
{ {
if (!string.IsNullOrEmpty(type)) if (!string.IsNullOrEmpty(type))
{ {
foreach (long key in cfg.typeDic.Keys) foreach (long key in cfg.typeDic.Keys)
{ {
if (type.Equals(cfg.typeDic[key])) if (type.Equals(cfg.typeDic[key]))
return key; return key;
} }
} }
return 0; return 0;
} }
static string GetValue(string content, string tag) static string GetValue(string content, string tag)
{ {
Regex regx = new Regex(@"^[\t]+?" + tag + @":([\s\S]*?)$", RegexOptions.Multiline); Regex regx = new Regex(@"^[\t]+?" + tag + @":([\s\S]*?)$", RegexOptions.Multiline);
Match m = regx.Match(content); Match m = regx.Match(content);
if (m.Success) if (m.Success)
{ {
if (m.Groups.Count >= 2) if (m.Groups.Count >= 2)
return RemoveTag(m.Groups[1].Value); return RemoveTag(m.Groups[1].Value);
} }
return ""; return "";
} }
//多行 //多行
static string GetMultiValue(string content, string tag) static string GetMultiValue(string content, string tag)
{ {
//TODO //TODO
content = content.Replace("\t\t", ""); content = content.Replace("\t\t", "");
Regex regx = new Regex(@"^[\t]+?" + tag + @":([\S\s]*?)^\t[\S\s]+?:", RegexOptions.Multiline); Regex regx = new Regex(@"^[\t]+?" + tag + @":([\S\s]*?)^\t[\S\s]+?:", RegexOptions.Multiline);
Match m = regx.Match(content); Match m = regx.Match(content);
if (m.Success) if (m.Success)
{ {
if (m.Groups.Count >= 2) if (m.Groups.Count >= 2)
{ {
string word = m.Groups[1].Value; string word = m.Groups[1].Value;
return RemoveTag(word).Replace("^", "").Replace("\t", ""); return RemoveTag(word).Replace("^", "").Replace("\t", "");
} }
} }
return ""; return "";
} }
long GetSpellTrapType(string level) long GetSpellTrapType(string level)
{ {
long type = 0; long type = 0;
//魔法陷阱 //魔法陷阱
if (level.Contains(MseSpellTrap.EQUIP)) if (level.Contains(MseSpellTrap.EQUIP))
type = (long)CardType.TYPE_EQUIP; type = (long)CardType.TYPE_EQUIP;
if (level.Contains(MseSpellTrap.QUICKPLAY)) if (level.Contains(MseSpellTrap.QUICKPLAY))
type = (long)CardType.TYPE_QUICKPLAY; type = (long)CardType.TYPE_QUICKPLAY;
if (level.Contains(MseSpellTrap.FIELD)) if (level.Contains(MseSpellTrap.FIELD))
type = (long)CardType.TYPE_FIELD; type = (long)CardType.TYPE_FIELD;
if (level.Contains(MseSpellTrap.CONTINUOUS)) if (level.Contains(MseSpellTrap.CONTINUOUS))
type = (long)CardType.TYPE_CONTINUOUS; type = (long)CardType.TYPE_CONTINUOUS;
if (level.Contains(MseSpellTrap.RITUAL)) if (level.Contains(MseSpellTrap.RITUAL))
type = (long)CardType.TYPE_RITUAL; type = (long)CardType.TYPE_RITUAL;
if (level.Contains(MseSpellTrap.COUNTER)) if (level.Contains(MseSpellTrap.COUNTER))
type = (long)CardType.TYPE_COUNTER; type = (long)CardType.TYPE_COUNTER;
return type; return type;
} }
long GetMonsterType(string cardtype) long GetMonsterType(string cardtype)
{ {
long type = 0; long type = 0;
if (cardtype.Equals(MseCardType.CARD_SPELL)) if (cardtype.Equals(MseCardType.CARD_SPELL))
type = (long)CardType.TYPE_SPELL; type = (long)CardType.TYPE_SPELL;
else if (cardtype.Equals(MseCardType.CARD_TRAP)) else if (cardtype.Equals(MseCardType.CARD_TRAP))
type = (long)CardType.TYPE_TRAP; type = (long)CardType.TYPE_TRAP;
else else
{ {
type = (long)CardType.TYPE_MONSTER; type = (long)CardType.TYPE_MONSTER;
switch (cardtype) switch (cardtype)
{ {
case MseCardType.CARD_NORMAL: case MseCardType.CARD_NORMAL:
type |= (long)CardType.TYPE_NORMAL; type |= (long)CardType.TYPE_NORMAL;
break; break;
case MseCardType.CARD_EFFECT: case MseCardType.CARD_EFFECT:
type |= (long)CardType.TYPE_EFFECT; type |= (long)CardType.TYPE_EFFECT;
break; break;
case MseCardType.CARD_XYZ: case MseCardType.CARD_XYZ:
type |= (long)CardType.TYPE_XYZ; type |= (long)CardType.TYPE_XYZ;
break; break;
case MseCardType.CARD_RITUAL: case MseCardType.CARD_RITUAL:
type |= (long)CardType.TYPE_RITUAL; type |= (long)CardType.TYPE_RITUAL;
break; break;
case MseCardType.CARD_FUSION: case MseCardType.CARD_FUSION:
type |= (long)CardType.TYPE_FUSION; type |= (long)CardType.TYPE_FUSION;
break; break;
case MseCardType.CARD_TOKEN: case MseCardType.CARD_TOKEN:
case MseCardType.CARD_TOKEN2: case MseCardType.CARD_TOKEN2:
type |= (long)CardType.TYPE_TOKEN; type |= (long)CardType.TYPE_TOKEN;
break; break;
case MseCardType.CARD_SYNCHRO: case MseCardType.CARD_SYNCHRO:
type |= (long)CardType.TYPE_SYNCHRO; type |= (long)CardType.TYPE_SYNCHRO;
break; break;
default: default:
type |= (long)CardType.TYPE_NORMAL; type |= (long)CardType.TYPE_NORMAL;
break; break;
} }
} }
return type; return type;
} }
//卡片类型 //卡片类型
long GetCardType(string cardtype, string level, string type1, long GetCardType(string cardtype, string level, string type1,
string type2, string type3) string type2, string type3)
{ {
long type = 0; long type = 0;
//魔法陷阱 //魔法陷阱
type |= GetSpellTrapType(level); type |= GetSpellTrapType(level);
//怪兽 //怪兽
type |= GetMonsterType(cardtype); type |= GetMonsterType(cardtype);
//type2-4是识别怪兽效果类型 //type2-4是识别怪兽效果类型
type |= GetTypeInt(type1); type |= GetTypeInt(type1);
type |= GetTypeInt(type2); type |= GetTypeInt(type2);
type |= GetTypeInt(type3); type |= GetTypeInt(type3);
return type; return type;
} }
static string RemoveTag(string word) static string RemoveTag(string word)
{ {
//移除标签<> //移除标签<>
word = Regex.Replace(word, "<[^>]+?>", ""); word = Regex.Replace(word, "<[^>]+?>", "");
return word.Trim().Replace("\t", ""); return word.Trim().Replace("\t", "");
} }
//解析卡片 //解析卡片
public Card ReadCard(string content, out string img) public Card ReadCard(string content, out string img)
{ {
string tmp; string tmp;
int itmp; int itmp;
Card c = new Card(); Card c = new Card();
c.ot = (int)CardRule.OCGTCG; c.ot = (int)CardRule.OCGTCG;
//卡名 //卡名
c.name = GetValue(content, TAG_NAME); c.name = GetValue(content, TAG_NAME);
tmp = GetValue(content, TAG_LEVEL); tmp = GetValue(content, TAG_LEVEL);
//卡片种族 //卡片种族
c.race = GetRaceInt(GetValue(content, TAG_TYPE1)); c.race = GetRaceInt(GetValue(content, TAG_TYPE1));
//卡片类型 //卡片类型
c.type = GetCardType(GetValue(content, TAG_CARDTYPE), tmp, c.type = GetCardType(GetValue(content, TAG_CARDTYPE), tmp,
GetValue(content, TAG_TYPE2), GetValue(content, TAG_TYPE2),
GetValue(content, TAG_TYPE3), GetValue(content, TAG_TYPE3),
GetValue(content, TAG_TYPE4)); GetValue(content, TAG_TYPE4));
long t = GetSpellTrapType(GetValue(content, TAG_LEVEL)); long t = GetSpellTrapType(GetValue(content, TAG_LEVEL));
//不是魔法,陷阱卡片的星数 //不是魔法,陷阱卡片的星数
if (!(c.IsType(CardType.TYPE_SPELL) if (!(c.IsType(CardType.TYPE_SPELL)
|| c.IsType(CardType.TYPE_TRAP)) && t == 0) || c.IsType(CardType.TYPE_TRAP)) && t == 0)
c.level = GetValue(content, TAG_LEVEL).Length; c.level = GetValue(content, TAG_LEVEL).Length;
//属性 //属性
c.attribute = GetAttributeInt(GetValue(content, TAG_ATTRIBUTE)); c.attribute = GetAttributeInt(GetValue(content, TAG_ATTRIBUTE));
//密码 //密码
long.TryParse(GetValue(content, TAG_CODE), out c.id); long.TryParse(GetValue(content, TAG_CODE), out c.id);
//ATK //ATK
tmp = GetValue(content, TAG_ATK); tmp = GetValue(content, TAG_ATK);
if (tmp == UNKNOWN_ATKDEF) if (tmp == UNKNOWN_ATKDEF)
c.atk = UNKNOWN_ATKDEF_VALUE; c.atk = UNKNOWN_ATKDEF_VALUE;
else else
int.TryParse(tmp, out c.atk); int.TryParse(tmp, out c.atk);
//DEF //DEF
tmp = GetValue(content, TAG_DEF); tmp = GetValue(content, TAG_DEF);
if (tmp == UNKNOWN_ATKDEF) if (tmp == UNKNOWN_ATKDEF)
c.def = UNKNOWN_ATKDEF_VALUE; c.def = UNKNOWN_ATKDEF_VALUE;
else else
int.TryParse(tmp, out c.def); int.TryParse(tmp, out c.def);
//图片 //图片
img = GetValue(content, TAG_IMAGE); img = GetValue(content, TAG_IMAGE);
//摇摆 //摇摆
if (c.IsType(CardType.TYPE_PENDULUM)) if (c.IsType(CardType.TYPE_PENDULUM))
{//根据预设的模版,替换内容 {//根据预设的模版,替换内容
tmp = cfg.temp_text.Replace(TAG_REP_TEXT, tmp = cfg.temp_text.Replace(TAG_REP_TEXT,
GetMultiValue(content,TAG_TEXT)); GetMultiValue(content,TAG_TEXT));
tmp = tmp.Replace(TAG_REP_PTEXT, tmp = tmp.Replace(TAG_REP_PTEXT,
GetMultiValue(content, TAG_PEND_TEXT)); GetMultiValue(content, TAG_PEND_TEXT));
c.desc = tmp; c.desc = tmp;
} }
else else
c.desc = GetMultiValue(content,TAG_TEXT); c.desc = GetMultiValue(content,TAG_TEXT);
//摇摆刻度 //摇摆刻度
int.TryParse(GetValue(content, TAG_PSCALE1), out itmp); int.TryParse(GetValue(content, TAG_PSCALE1), out itmp);
c.level += (itmp << 0x18); c.level += (itmp << 0x18);
int.TryParse(GetValue(content, TAG_PSCALE2), out itmp); int.TryParse(GetValue(content, TAG_PSCALE2), out itmp);
c.level += (itmp << 0x10); c.level += (itmp << 0x10);
return c; return c;
} }
//读取所有卡片 //读取所有卡片
public Card[] ReadCards(string set, bool repalceOld) public Card[] ReadCards(string set, bool repalceOld)
{ {
List<Card> cards = new List<Card>(); List<Card> cards = new List<Card>();
if (!File.Exists(set)) if (!File.Exists(set))
return null; return null;
string allcontent = File.ReadAllText(set, Encoding.UTF8); string allcontent = File.ReadAllText(set, Encoding.UTF8);
Regex regx = new Regex(@"^card:[\S\s]+?gamecode:[\S\s]+?$", Regex regx = new Regex(@"^card:[\S\s]+?gamecode:[\S\s]+?$",
RegexOptions.Multiline); RegexOptions.Multiline);
MatchCollection matchs = regx.Matches(allcontent); MatchCollection matchs = regx.Matches(allcontent);
int i = 0; int i = 0;
foreach (Match match in matchs) foreach (Match match in matchs)
{ {
string content = match.Groups[0].Value; string content = match.Groups[0].Value;
i++; i++;
string img; string img;
Card c = ReadCard(content, out img); Card c = ReadCard(content, out img);
if (c.id <= 0) if (c.id <= 0)
c.id = i; c.id = i;
//添加卡片 //添加卡片
cards.Add(c); cards.Add(c);
//已经解压出来的图片 //已经解压出来的图片
string saveimg = MyPath.Combine(cfg.imagepath, img); string saveimg = MyPath.Combine(cfg.imagepath, img);
if (!File.Exists(saveimg))//没有解压相应的图片 if (!File.Exists(saveimg))//没有解压相应的图片
continue; continue;
//改名后的图片 //改名后的图片
img = MyPath.Combine(cfg.imagepath, c.idString + ".jpg"); img = MyPath.Combine(cfg.imagepath, c.idString + ".jpg");
if (img == saveimg)//文件名相同 if (img == saveimg)//文件名相同
continue; continue;
if (File.Exists(img)) if (File.Exists(img))
{ {
if (repalceOld)//如果存在,则备份原图 if (repalceOld)//如果存在,则备份原图
{ {
File.Delete(img + ".bak");//删除备份 File.Delete(img + ".bak");//删除备份
File.Move(img, img + ".bak");//备份 File.Move(img, img + ".bak");//备份
File.Move(saveimg, img);//改名 File.Move(saveimg, img);//改名
} }
} }
else else
File.Move(saveimg, img); File.Move(saveimg, img);
} }
File.Delete(set); File.Delete(set);
return cards.ToArray(); return cards.ToArray();
} }
#endregion #endregion
}
public string getImageCache(string img){
if(cfg.width<=0 && cfg.height<=0)
return img;
string md5=MyUtils.GetMD5HashFromFile(img);
if(MyUtils.Md5isEmpty(md5)||cfg.imagecache==null){
//md5为空
return img;
}
string file = MyPath.Combine(cfg.imagecache, md5+".png");
if(!File.Exists(file)){
//生成缓存
Bitmap bmp=MyBitmap.readImage(file);
//缩放
bmp=MyBitmap.Zoom(bmp, cfg.width,cfg.height);
//保存文件
MyBitmap.SaveAsJPEG(bmp, file,100);
}
return img;
}
}
} }
...@@ -293,7 +293,8 @@ public void SaveMSE(int num, string file, Card[] cards, bool isUpdate) ...@@ -293,7 +293,8 @@ public void SaveMSE(int num, string file, Card[] cards, bool isUpdate)
break; break;
i++; i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}-{2}", i, count, num)); worker.ReportProgress(i / count, string.Format("{0}/{1}-{2}", i, count, num));
zips.AddFile(img, Path.GetFileName(img), ""); //TODO 先裁剪图片
zips.AddFile(mseHelper.getImageCache(img), Path.GetFileName(img), "");
} }
} }
File.Delete(setFile); File.Delete(setFile);
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
</Compile> </Compile>
<Compile Include="Common\CheckUpdate.cs" /> <Compile Include="Common\CheckUpdate.cs" />
<Compile Include="Common\ConfHelper.cs" /> <Compile Include="Common\ConfHelper.cs" />
<Compile Include="Common\MyUtils.cs" />
<Compile Include="Common\StrUtil.cs" /> <Compile Include="Common\StrUtil.cs" />
<Compile Include="Common\XMLReader.cs" /> <Compile Include="Common\XMLReader.cs" />
<Compile Include="Config\YgoPath.cs" /> <Compile Include="Config\YgoPath.cs" />
......
...@@ -28,4 +28,4 @@ ...@@ -28,4 +28,4 @@
// //
// You can specify all the values or you can use the default the Revision and // You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below: // Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("2.3.1.4")] [assembly: AssemblyVersion("2.3.2.0")]
★更新历史 ★更新历史
2.3.2.0
MSE存档的中间图缩放
2.3.1.4 2.3.1.4
增加灵摆刻度的搜索功能 增加灵摆刻度的搜索功能
关闭数据库时清理备份文件 关闭数据库时清理备份文件
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### 存档最大卡片数 ########################### 存档最大卡片数
maxcount = 0 maxcount = 0
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
#jp setting #jp setting
# spell = %% # spell = %%
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### Setting ########################### Setting
maxcount = 0 maxcount = 0
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
#jp setting #jp setting
# spell = %% # spell = %%
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### Setting ########################### Setting
maxcount = 200 maxcount = 200
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
spell = [Sepll Card%%] spell = [Sepll Card%%]
trap = [Trap Card%%] trap = [Trap Card%%]
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### Setting ########################### Setting
maxcount = 0 maxcount = 0
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
#jp setting #jp setting
spell = %% spell = %%
......
[DataEditorX]2.3.1.4[DataEditorX] [DataEditorX]2.3.2.0[DataEditorX]
[URL]https://github.com/247321453/DataEditorX/raw/master/win32/win32.zip[URL] [URL]https://github.com/247321453/DataEditorX/raw/master/win32/win32.zip[URL]
★运行环境(Environment) ★运行环境(Environment)
......
No preview for this file type
★更新历史 ★更新历史
2.3.2.0
MSE存档的中间图缩放
2.3.1.4 2.3.1.4
增加灵摆刻度的搜索功能 增加灵摆刻度的搜索功能
关闭数据库时清理备份文件 关闭数据库时清理备份文件
......
...@@ -157,4 +157,3 @@ MainForm.mainMenu.menuitem_closeall 关闭所有 ...@@ -157,4 +157,3 @@ MainForm.mainMenu.menuitem_closeall 关闭所有
0x47 读取MSE存档 0x47 读取MSE存档
0x48 读取MSE存档完成! 0x48 读取MSE存档完成!
0x49 请重启程序使更改生效 0x49 请重启程序使更改生效
0x4c 是否同时删除卡图、脚本等资源?
\ No newline at end of file
...@@ -156,4 +156,3 @@ MainForm.mainMenu.menuitem_closeall Close All ...@@ -156,4 +156,3 @@ MainForm.mainMenu.menuitem_closeall Close All
0x47 Read MSE-set 0x47 Read MSE-set
0x48 Read MSE-set is OK. 0x48 Read MSE-set is OK.
0x49 Please restart program to apply changes. 0x49 Please restart program to apply changes.
0x4c Also delete pics and scripts?
\ No newline at end of file
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### 存档最大卡片数 ########################### 存档最大卡片数
maxcount = 0 maxcount = 0
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
#jp setting #jp setting
# spell = %% # spell = %%
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### Setting ########################### Setting
maxcount = 0 maxcount = 0
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
#jp setting #jp setting
# spell = %% # spell = %%
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### Setting ########################### Setting
maxcount = 200 maxcount = 200
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
spell = [Sepll Card%%] spell = [Sepll Card%%]
trap = [Trap Card%%] trap = [Trap Card%%]
......
...@@ -7,6 +7,9 @@ cn2tw = false ...@@ -7,6 +7,9 @@ cn2tw = false
########################### Setting ########################### Setting
maxcount = 0 maxcount = 0
imagepath = ./Images imagepath = ./Images
########################### 中间图
width = 345
height = 346
########################### Spell/Trap ########################### Spell/Trap
#jp setting #jp setting
spell = %% spell = %%
......
[DataEditorX]2.3.1.4[DataEditorX] [DataEditorX]2.3.2.0[DataEditorX]
[URL]https://github.com/247321453/DataEditorX/raw/master/win32/win32.zip[URL] [URL]https://github.com/247321453/DataEditorX/raw/master/win32/win32.zip[URL]
★运行环境(Environment) ★运行环境(Environment)
......
No preview for this file type
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