本文整理汇总了C#中Tokenizer.AddKeywords方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.AddKeywords方法的具体用法?C# Tokenizer.AddKeywords怎么用?C# Tokenizer.AddKeywords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.AddKeywords方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadItems
public static void LoadItems()
{
Game.Instance.Log("Loading items...");
string path = "../../System/items.txt";
Tokenizer t = new Tokenizer();
int errors = 0;
t.AddKeywords(new TupleList<string, Type>{
{"weapon", Type.Weapon},
{"gun", Type.Gun},
{"armor", Type.Armor},
{"potion", Type.Potion},
{"ammo", Type.Ammo},
{"other", Type.Other}
});
t.AddKeywords(new TupleList<string, Keyword>{
{"name", Keyword.Name},
{"desc", Keyword.Desc},
{"value", Keyword.Value},
{"weight", Keyword.Weight},
{"attack", Keyword.Attack},
{"defense", Keyword.Defense},
{"subtype", Keyword.Subtype},
{"material", Keyword.Material},
{"range", Keyword.Range},
{"capacity", Keyword.Capacity}
});
t.AddKeywords(new TupleList<string, WeaponType>{
{"slash", WeaponType.Slash},
{"pierce", WeaponType.Pierce},
{"blunt", WeaponType.Blunt}
});
t.AddKeywords(new TupleList<string, Material>{
{"wood", Material.Wood},
{"iron", Material.Iron},
{"steel", Material.Steel},
{"silver", Material.Silver}
});
t.AddKeywords(new TupleList<string, AmmoType>{
{"bullet9mm", AmmoType.Bullet9mm}
});
if (!t.FromFile(path))
throw new Exception(string.Format("Failed to open file \"{0}\".", path));
try
{
while(t.Next())
{
retry:
try
{
Item item = new Item();
// type
item.type = t.GetKeyword<Type>();
t.Next();
// id
item.id = t.GetItem();
t.Next();
// {
t.AssertSymbol('{');
t.Next();
bool[] have = new bool[(int)Keyword.Max];
while(true)
{
if (t.IsSymbol('}'))
break;
Keyword key = t.GetKeyword<Keyword>();
string key_name = t.GetKeywordName();
t.Next();
if(have[(int)key])
throw new Exception(string.Format("Item '{0}' already have {1}.", item.id, key_name));
have[(int)key] = true;
if(!CanHave(item.type, key))
throw new Exception(string.Format("Item '{0}' can't have {1}.", item.id, key_name));
switch(key)
{
case Keyword.Name:
item.name = t.GetString();
break;
case Keyword.Desc:
item.desc = t.GetString();
break;
case Keyword.Value:
//.........这里部分代码省略.........