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,20 +15,6 @@ ...@@ -15,20 +15,6 @@
namespace DataEditorX.Config 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> /// <summary>
/// Description of MSEConfig. /// Description of MSEConfig.
/// </summary> /// </summary>
...@@ -64,88 +50,60 @@ public void init(string path) ...@@ -64,88 +50,60 @@ public void init(string path)
string tmp = MyPath.Combine(path, FILE_CONFIG); string tmp = MyPath.Combine(path, FILE_CONFIG);
replaces = new List<RegStr>(); replaces = new Dictionary<string, string>();
typeDic = new Dictionary<long, string>(); typeDic = new Dictionary<long, string>();
raceDic = 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); string[] lines = File.ReadAllLines(tmp, 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("cn2tw")) if (line.StartsWith("cn2tw"))
Iscn2tw = (getValue(line).ToLower() == "true") ? true : false; Iscn2tw = ConfHelper.getBooleanValue(line);
else if (line.StartsWith("spell")) else if (line.StartsWith("spell"))
str_spell = getValue(line); str_spell = ConfHelper.getValue(line);
else if (line.StartsWith("trap")) else if (line.StartsWith("trap"))
str_trap = getValue(line); str_trap = ConfHelper.getValue(line);
else if (line.StartsWith("pendulum-text")) else if (line.StartsWith("pendulum-text"))
regx_pendulum = getRegex(getValue(line)); regx_pendulum = ConfHelper.getRegexValue(line);
else if (line.StartsWith("monster-text")) else if (line.StartsWith("monster-text"))
regx_monster = getRegex(getValue(line)); regx_monster = ConfHelper.getRegexValue(line);
else if (line.StartsWith("maxcount")) else if (line.StartsWith("maxcount"))
int.TryParse(getValue(line), out maxcount); maxcount = ConfHelper.getIntegerValue(line, 0);
else if (line.StartsWith("imagepath")) 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(" "); imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, "Images"));
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("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")) else if (line.StartsWith("race"))
{ {//种族
DicAdd(raceDic, line); ConfHelper.DicAdd(raceDic, line);
} }
else if (line.StartsWith("type")) else if (line.StartsWith("type"))
{ {//类型
DicAdd(typeDic, line); ConfHelper.DicAdd(typeDic, line);
} }
} }
//判断魔法标志是否为纯符号
if (str_spell == "%%" && str_trap == "%%") if (str_spell == "%%" && str_trap == "%%")
st_is_symbol = true; st_is_symbol = true;
else else
st_is_symbol = false; st_is_symbol = false;
} }
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());
}
}
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;
//图片路径 //图片路径
...@@ -159,7 +117,7 @@ string getValue(string line) ...@@ -159,7 +117,7 @@ string getValue(string line)
//简体转繁体? //简体转繁体?
public bool Iscn2tw; public bool Iscn2tw;
//特数字替换 //特数字替换
public List<RegStr> replaces; public Dictionary<string, string> replaces;
//效果文正则提取 //效果文正则提取
public string regx_pendulum; public string regx_pendulum;
public string regx_monster; public string regx_monster;
......
...@@ -24,7 +24,7 @@ namespace DataEditorX.Core ...@@ -24,7 +24,7 @@ namespace DataEditorX.Core
/// <summary> /// <summary>
/// Description of MSE. /// Description of MSE.
/// </summary> /// </summary>
public class MSE public class MseMaker
{ {
MSEConfig cfg; MSEConfig cfg;
...@@ -38,7 +38,7 @@ public string ImagePath ...@@ -38,7 +38,7 @@ public string ImagePath
get {return cfg.imagepath;} get {return cfg.imagepath;}
} }
public MSE(MSEConfig mcfg) public MseMaker(MSEConfig mcfg)
{ {
cfg = mcfg; cfg = mcfg;
} }
...@@ -46,9 +46,9 @@ public MSE(MSEConfig mcfg) ...@@ -46,9 +46,9 @@ public MSE(MSEConfig mcfg)
public string reItalic(string str) public string reItalic(string str)
{ {
str = cn2tw(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; return str;
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace DataEditorX.Core
{
public class MseReader
{
}
}
...@@ -41,7 +41,7 @@ public class TaskHelper ...@@ -41,7 +41,7 @@ public class TaskHelper
private Card[] cardlist; private Card[] cardlist;
private string[] mArgs; private string[] mArgs;
private ImageSet imgSet = new ImageSet(); private ImageSet imgSet = new ImageSet();
private MSE mseHelper; private MseMaker mseHelper;
private bool isCancel = false; private bool isCancel = false;
private bool isRun = false; private bool isRun = false;
private BackgroundWorker worker; private BackgroundWorker worker;
...@@ -49,7 +49,7 @@ public class TaskHelper ...@@ -49,7 +49,7 @@ public class TaskHelper
public TaskHelper(string datapath, BackgroundWorker worker, MSEConfig mcfg) public TaskHelper(string datapath, BackgroundWorker worker, MSEConfig mcfg)
{ {
this.worker = worker; this.worker = worker;
mseHelper = new MSE(mcfg); mseHelper = new MseMaker(mcfg);
imgSet.Init(); imgSet.Init();
} }
public bool IsRuning() public bool IsRuning()
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
<DependentUpon>CodeEditForm.cs</DependentUpon> <DependentUpon>CodeEditForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Common\CheckUpdate.cs" /> <Compile Include="Common\CheckUpdate.cs" />
<Compile Include="Config\ConfHelper.cs" />
<Compile Include="Controls\DoubleContorl.cs"> <Compile Include="Controls\DoubleContorl.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
...@@ -93,8 +94,9 @@ ...@@ -93,8 +94,9 @@
<Compile Include="Config\DataManager.cs" /> <Compile Include="Config\DataManager.cs" />
<Compile Include="Config\ImageSet.cs" /> <Compile Include="Config\ImageSet.cs" />
<Compile Include="Core\LuaFunction.cs" /> <Compile Include="Core\LuaFunction.cs" />
<Compile Include="Core\MSE.cs" /> <Compile Include="Core\MseMaker.cs" />
<Compile Include="Config\MSEConfig.cs" /> <Compile Include="Config\MSEConfig.cs" />
<Compile Include="Core\MseReader.cs" />
<Compile Include="Core\TaskHelper.cs" /> <Compile Include="Core\TaskHelper.cs" />
<Compile Include="Core\YGOUtil.cs" /> <Compile Include="Core\YGOUtil.cs" />
<Compile Include="DataEditForm.cs"> <Compile Include="DataEditForm.cs">
...@@ -202,7 +204,7 @@ ...@@ -202,7 +204,7 @@
<None Include="chinese\mse-template.txt"> <None Include="chinese\mse-template.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="chinese\single.lua"> <None Include="single.lua">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="chinese\strings.conf"> <None Include="chinese\strings.conf">
......
...@@ -23,6 +23,25 @@ monster-text = [果|介|述|報]】\n([\S\s]*) ...@@ -23,6 +23,25 @@ monster-text = [果|介|述|報]】\n([\S\s]*)
replace = ([鮟|鱇|・|·]) <i>$1</i> replace = ([鮟|鱇|・|·]) <i>$1</i>
#replace = \s <sym-auto>^</sym-auto> #replace = \s <sym-auto>^</sym-auto>
#replace = ([A-Z]) <i>$1</i> #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
race 0x1 战士族 race 0x1 战士族
race 0x2 魔法师族 race 0x2 魔法师族
...@@ -48,6 +67,7 @@ race 0x100000 念动力族 ...@@ -48,6 +67,7 @@ race 0x100000 念动力族
race 0x200000 幻神兽族 race 0x200000 幻神兽族
race 0x400000 创造神族 race 0x400000 创造神族
race 0x800000 幻龙族 race 0x800000 幻龙族
###########################
##type ##type
type 0x1 怪兽 type 0x1 怪兽
type 0x2 魔法 type 0x2 魔法
...@@ -74,3 +94,4 @@ type 0x200000 反转 ...@@ -74,3 +94,4 @@ type 0x200000 反转
type 0x400000 卡通 type 0x400000 卡通
type 0x800000 超量 type 0x800000 超量
type 0x1000000 灵摆 type 0x1000000 灵摆
##########################
\ No newline at end of file
No preview for this file type
...@@ -23,6 +23,25 @@ monster-text = [果|介|述|報]】\n([\S\s]*) ...@@ -23,6 +23,25 @@ monster-text = [果|介|述|報]】\n([\S\s]*)
replace = ([鮟|鱇|・|·]) <i>$1</i> replace = ([鮟|鱇|・|·]) <i>$1</i>
#replace = \s <sym-auto>^</sym-auto> #replace = \s <sym-auto>^</sym-auto>
#replace = ([A-Z]) <i>$1</i> #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
race 0x1 战士族 race 0x1 战士族
race 0x2 魔法师族 race 0x2 魔法师族
...@@ -48,6 +67,7 @@ race 0x100000 念动力族 ...@@ -48,6 +67,7 @@ race 0x100000 念动力族
race 0x200000 幻神兽族 race 0x200000 幻神兽族
race 0x400000 创造神族 race 0x400000 创造神族
race 0x800000 幻龙族 race 0x800000 幻龙族
###########################
##type ##type
type 0x1 怪兽 type 0x1 怪兽
type 0x2 魔法 type 0x2 魔法
...@@ -74,3 +94,4 @@ type 0x200000 反转 ...@@ -74,3 +94,4 @@ type 0x200000 反转
type 0x400000 卡通 type 0x400000 卡通
type 0x800000 超量 type 0x800000 超量
type 0x1000000 灵摆 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