Commit 9d62faef authored by keyongyu's avatar keyongyu

mse

parent 3d359917
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
namespace DataEditorX.Config
{
public class ConfHelper
{
public const string SEP_LINE = " ";
public static string getValue(string line)
{
int t = line.IndexOf('=');
if (t > 0)
return line.Substring(t + 1).Trim();
return "";
}
public static string getValue1(string word)
{
int i = word.IndexOf(SEP_LINE);
if (i > 0)
return word.Substring(0, i);
return "";
}
public static string getValue2(string word)
{
int i = word.IndexOf(SEP_LINE);
if (i > 0)
return word.Substring(i + SEP_LINE.Length);
return "";
}
public static string getRegexValue(string line)
{
return getRegex(getValue(line));
}
public static string getRegex(string word)
{
return word.Replace("\\n", "\n").Replace("\\t", "\t").Replace("\\s", " ");
}
public static bool getBooleanValue(string line)
{
if (getValue(line).ToLower() == "true")
return true;
else
return false;
}
public static int getIntegerValue(string line, int defalut)
{
int i;
try
{
i = int.Parse(getValue(line));
return i;
}
catch{}
return defalut;
}
public static void DicAdd(Dictionary<long, string> dic, string line)
{
int i = line.IndexOf("0x");
int j = (i > 0) ? line.IndexOf(SEP_LINE, i + 1) : -1;
if (j > 0)
{
string strkey = line.Substring(i + 2, j - i - 1);
string strval = line.Substring(j + 1);
long key;
long.TryParse(strkey, NumberStyles.HexNumber, null, out key);
if (!dic.ContainsKey(key))
dic.Add(key, strval.Trim());
}
}
}
}
......@@ -15,25 +15,11 @@
namespace DataEditorX.Config
{
public class RegStr
{
public RegStr(string p,string r)
{
pstr=Re(p);
rstr=Re(r);
}
string Re(string str)
{
return str.Replace("\\n","\n").Replace("\\t","\t").Replace("\\s"," ");
}
public string pstr;
public string rstr;
}
/// <summary>
/// Description of MSEConfig.
/// </summary>
public class MSEConfig
{
/// <summary>
/// Description of MSEConfig.
/// </summary>
public class MSEConfig
{
public const string TAG_HEAD = "head";
public const string TAG_MONSTER = "monster";
public const string TAG_PENDULUM = "pendulum";
......@@ -42,10 +28,10 @@ public class MSEConfig
public const string FILE_TEMPLATE = "mse-template.txt";
public const string SEP_LINE = " ";
public MSEConfig(string path)
{
public MSEConfig(string path)
{
init(path);
}
}
public void init(string path)
{
Iscn2tw = false;
......@@ -64,111 +50,83 @@ public void init(string path)
string tmp = MyPath.Combine(path, FILE_CONFIG);
replaces = new List<RegStr>();
replaces = new Dictionary<string, string>();
typeDic = new Dictionary<long, string>();
raceDic = new Dictionary<long, string>();
//读取配置
if (File.Exists(tmp))
if (!File.Exists(tmp))
return;
string[] lines = File.ReadAllLines(tmp, Encoding.UTF8);
foreach (string line in lines)
{
string[] lines = File.ReadAllLines(tmp, Encoding.UTF8);
foreach (string line in lines)
if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
continue;
if (line.StartsWith("cn2tw"))
Iscn2tw = ConfHelper.getBooleanValue(line);
else if (line.StartsWith("spell"))
str_spell = ConfHelper.getValue(line);
else if (line.StartsWith("trap"))
str_trap = ConfHelper.getValue(line);
else if (line.StartsWith("pendulum-text"))
regx_pendulum = ConfHelper.getRegexValue(line);
else if (line.StartsWith("monster-text"))
regx_monster = ConfHelper.getRegexValue(line);
else if (line.StartsWith("maxcount"))
maxcount = ConfHelper.getIntegerValue(line, 0);
else if (line.StartsWith("imagepath"))
{
if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
continue;
if (line.StartsWith("cn2tw"))
Iscn2tw = (getValue(line).ToLower() == "true") ? true : false;
else if (line.StartsWith("spell"))
str_spell = getValue(line);
else if (line.StartsWith("trap"))
str_trap = getValue(line);
else if (line.StartsWith("pendulum-text"))
regx_pendulum = getRegex(getValue(line));
else if (line.StartsWith("monster-text"))
regx_monster = getRegex(getValue(line));
else if (line.StartsWith("maxcount"))
int.TryParse(getValue(line), out maxcount);
else if (line.StartsWith("imagepath"))
imagepath = MyPath.CheckDir(getValue(line), MyPath.Combine(path, "Images"));
else if (line.StartsWith("replace"))
{
string word = getValue(line);
int t = word.IndexOf(" ");
if (t > 0)
{
string p = word.Substring(0, t);
string r = word.Substring(t + 1);
if (!string.IsNullOrEmpty(p))
replaces.Add(new RegStr(p, r));
}
}
else if (line.StartsWith("race"))
{
DicAdd(raceDic, line);
}
else if (line.StartsWith("type"))
{
DicAdd(typeDic, line);
}
//如果路径不合法,则为后面的路径
imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, "Images"));
}
else if (line.StartsWith("replace"))
{//特数字替换
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("race"))
{//种族
ConfHelper.DicAdd(raceDic, line);
}
else if (line.StartsWith("type"))
{//类型
ConfHelper.DicAdd(typeDic, line);
}
if (str_spell == "%%" && str_trap == "%%")
st_is_symbol = true;
else
st_is_symbol = false;
}
//判断魔法标志是否为纯符号
if (str_spell == "%%" && str_trap == "%%")
st_is_symbol = true;
else
{
Iscn2tw = false;
}
}
void DicAdd(Dictionary<long,string> dic, string line)
{
int i = line.IndexOf("0x");
int j = (i>0)?line.IndexOf(SEP_LINE, i+1):-1;
if (j > 0)
{
string strkey = line.Substring(i + 2, j - i - 1);
string strval = line.Substring(j + 1);
long key;
long.TryParse(strkey, NumberStyles.HexNumber, null, out key);
if (!dic.ContainsKey(key))
dic.Add(key, strval.Trim());
}
st_is_symbol = false;
}
string getRegex(string word)
{
return word.Replace("\\n","\n").Replace("\\t","\t");
}
string getValue(string line)
{
int t=line.IndexOf('=');
if(t>0)
return line.Substring(t+1).Trim();
return "";
}
//每个存档最大数
public int maxcount;
public int maxcount;
//图片路径
public string imagepath;
public string imagepath;
//标志是符号
public bool st_is_symbol;
public bool st_is_symbol;
//魔法标志
public string str_spell;
public string str_spell;
//陷阱标志
public string str_trap;
public string str_trap;
//简体转繁体?
public bool Iscn2tw;
public bool Iscn2tw;
//特数字替换
public List<RegStr> replaces;
public Dictionary<string, string> replaces;
//效果文正则提取
public string regx_pendulum;
public string regx_monster;
public string regx_pendulum;
public string regx_monster;
//模版
public string head;
public string monster;
public string pendulum;
public string spelltrap;
public string head;
public string monster;
public string pendulum;
public string spelltrap;
public Dictionary<long, string> typeDic;
public Dictionary<long, string> raceDic;
}
}
}
......@@ -24,7 +24,7 @@ namespace DataEditorX.Core
/// <summary>
/// Description of MSE.
/// </summary>
public class MSE
public class MseMaker
{
MSEConfig cfg;
......@@ -38,7 +38,7 @@ public string ImagePath
get {return cfg.imagepath;}
}
public MSE(MSEConfig mcfg)
public MseMaker(MSEConfig mcfg)
{
cfg = mcfg;
}
......@@ -46,9 +46,9 @@ public MSE(MSEConfig mcfg)
public string reItalic(string str)
{
str = cn2tw(str);
foreach (RegStr rs in cfg.replaces)
foreach (string rs in cfg.replaces.Keys)
{
str = Regex.Replace(str, rs.pstr, rs.rstr);
str = Regex.Replace(str, rs, cfg.replaces[rs]);
}
return str;
}
......
using System;
using System.Collections.Generic;
using System.Text;
namespace DataEditorX.Core
{
public class MseReader
{
}
}
......@@ -41,7 +41,7 @@ public class TaskHelper
private Card[] cardlist;
private string[] mArgs;
private ImageSet imgSet = new ImageSet();
private MSE mseHelper;
private MseMaker mseHelper;
private bool isCancel = false;
private bool isRun = false;
private BackgroundWorker worker;
......@@ -49,7 +49,7 @@ public class TaskHelper
public TaskHelper(string datapath, BackgroundWorker worker, MSEConfig mcfg)
{
this.worker = worker;
mseHelper = new MSE(mcfg);
mseHelper = new MseMaker(mcfg);
imgSet.Init();
}
public bool IsRuning()
......
......@@ -68,6 +68,7 @@
<DependentUpon>CodeEditForm.cs</DependentUpon>
</Compile>
<Compile Include="Common\CheckUpdate.cs" />
<Compile Include="Config\ConfHelper.cs" />
<Compile Include="Controls\DoubleContorl.cs">
<SubType>Component</SubType>
</Compile>
......@@ -93,8 +94,9 @@
<Compile Include="Config\DataManager.cs" />
<Compile Include="Config\ImageSet.cs" />
<Compile Include="Core\LuaFunction.cs" />
<Compile Include="Core\MSE.cs" />
<Compile Include="Core\MseMaker.cs" />
<Compile Include="Config\MSEConfig.cs" />
<Compile Include="Core\MseReader.cs" />
<Compile Include="Core\TaskHelper.cs" />
<Compile Include="Core\YGOUtil.cs" />
<Compile Include="DataEditForm.cs">
......@@ -202,7 +204,7 @@
<None Include="chinese\mse-template.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="chinese\single.lua">
<None Include="single.lua">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="chinese\strings.conf">
......
......@@ -23,6 +23,25 @@ monster-text = [果|介|述|報]】\n([\S\s]*)
replace = ([鮟|鱇|・|·]) <i>$1</i>
#replace = \s <sym-auto>^</sym-auto>
#replace = ([A-Z]) <i>$1</i>
########################### Read MSE set
#
type = card type
name = name
attribute = attribute
level = level
image = image
type1 = type 1
type2 = type 2
type3 = type 3
type4 = type 4
rule = rule text
atk = attack
def = defense
pscale1 = pendulum scale 1
pscale2 = pendulum scale 2
prule = pendulum text
code = gamecode
###########################
##race
race 0x1 战士族
race 0x2 魔法师族
......@@ -48,6 +67,7 @@ race 0x100000 念动力族
race 0x200000 幻神兽族
race 0x400000 创造神族
race 0x800000 幻龙族
###########################
##type
type 0x1 怪兽
type 0x2 魔法
......@@ -73,4 +93,5 @@ type 0x100000 反击
type 0x200000 反转
type 0x400000 卡通
type 0x800000 超量
type 0x1000000 灵摆
\ No newline at end of file
type 0x1000000 灵摆
##########################
\ No newline at end of file
No preview for this file type
......@@ -23,6 +23,25 @@ monster-text = [果|介|述|報]】\n([\S\s]*)
replace = ([鮟|鱇|・|·]) <i>$1</i>
#replace = \s <sym-auto>^</sym-auto>
#replace = ([A-Z]) <i>$1</i>
########################### Read MSE set
#
type = card type
name = name
attribute = attribute
level = level
image = image
type1 = type 1
type2 = type 2
type3 = type 3
type4 = type 4
rule = rule text
atk = attack
def = defense
pscale1 = pendulum scale 1
pscale2 = pendulum scale 2
prule = pendulum text
code = gamecode
###########################
##race
race 0x1 战士族
race 0x2 魔法师族
......@@ -48,6 +67,7 @@ race 0x100000 念动力族
race 0x200000 幻神兽族
race 0x400000 创造神族
race 0x800000 幻龙族
###########################
##type
type 0x1 怪兽
type 0x2 魔法
......@@ -73,4 +93,5 @@ type 0x100000 反击
type 0x200000 反转
type 0x400000 卡通
type 0x800000 超量
type 0x1000000 灵摆
\ No newline at end of file
type 0x1000000 灵摆
##########################
\ No newline at end of file
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