private static Dictionary <string, Double> luaOrderTable2DictionaryDouble(LuaTable lTable) { Dictionary <string, Double> ht = new Dictionary <string, Double>(); //probably any mod can do its custom format for the order config file //but the standard seems to be to return two tables ("order" and "data"); //CA uses a dedicated order file returning the order table directly (like in older spring) LuaTable orderTab = (LuaTable)lTable.GetValue("order"); LuaTable dataTab = (LuaTable)lTable.GetValue("data"); if (orderTab != null && dataTab != null) { //we have standard format IDictionaryEnumerator ienum = (IDictionaryEnumerator)orderTab.GetEnumerator(); while (ienum.MoveNext()) { ht.Add((String)ienum.Key, (Double)ienum.Value); } } else { //we have CA-format: dedicated order file IDictionaryEnumerator ienum = (IDictionaryEnumerator)lTable.GetEnumerator(); while (ienum.MoveNext()) { ht.Add((String)ienum.Key, (Double)ienum.Value); } } return(ht); }
void OnGUI() { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Scripts Diff", EditorUtility.FormatBytes(Mathf.RoundToInt(anaMemRecord)), EditorStyles.boldLabel, GUILayout.Width(250)); EditorGUILayout.LabelField("Total Memory Diff", EditorUtility.FormatBytes(Mathf.RoundToInt(totalIncreaseMem)), GUILayout.Width(250)); EditorGUILayout.LabelField("Profiler Tool Diff", EditorUtility.FormatBytes(Mathf.RoundToInt(toolMemRecord)), GUILayout.Width(250)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.enabled = canUse && !inRecord; // lua returned KB if (GUILayout.Button("Start Record")) { inRecord = true; startRecordCount = 1000 * System.Convert.ToSingle(LuaScriptMgr.CallLuaFunction("SG_StartRecordAlloc")[0]); } GUI.enabled = canUse && inRecord; if (GUILayout.Button("Stop Record")) { inRecord = false; var m_Root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" }; int m_Id = 1; var profilerData = LuaScriptMgr.CallLuaFunction("SG_StopRecordAllocAndDumpStat"); endRecordCount = 1000 * System.Convert.ToSingle(profilerData[0]); totalIncreaseMem = 1000 * System.Convert.ToSingle(profilerData[1]); anaMemRecord = 1000 * System.Convert.ToSingle(profilerData[2]); toolMemRecord = 1000 * System.Convert.ToSingle(profilerData[3]); LuaTable memStat = profilerData[4] as LuaTable; var enumerator = memStat.GetEnumerator(); while (enumerator.MoveNext()) { var child = new LuaMemoryTreeViewItem(m_Id++, enumerator.Value as LuaTable); m_Root.AddChild(child); } if (!m_Root.hasChildren) { EditorUtility.DisplayDialog("Error", "未统计到Lua运行数据,请游戏操作Lua脚本之后再点击结束按钮", "确定"); return; } //LuaDLL.lua_pop(LuaState.L, 1); Debug.Log("Total Memory Diff " + EditorUtility.FormatBytes(Mathf.RoundToInt(endRecordCount - startRecordCount))); m_TreeView = LuaMemoryTreeView.Create(m_Root); } GUI.enabled = true; GUILayout.EndHorizontal(); if (m_TreeView != null) { m_TreeView.OnGUI(new Rect(0, 60, position.width, position.height - 30)); } }
/// <summary> /// Marks the start of a multi-choice menu. /// Choices must be added after calling this method using the AddChoice() method. /// WaitForChoice() must be called afterwards for the menu to be actually displayed, /// and for execution to suspend until the choice is returned. /// Then to recover the integer value indicating the result of the menu, ChoiceResult() must be called. /// </summary> /// <param name="message">The question to ask the user.</param> public void BeginChoiceMenu(string message, LuaTable choicespairs, object defaultchoice, object cancelchoice) { if (DataManager.Instance.CurrentReplay != null) { m_choiceresult = DataManager.Instance.CurrentReplay.ReadUI(); return; } try { m_choiceresult = null; int mappedDefault = 0; int mappedCancel = 0; //Intepret the choices from lua List <DialogueChoice> choices = new List <DialogueChoice>(); IDictionaryEnumerator dict = choicespairs.GetEnumerator(); while (dict.MoveNext()) { string choicetext = ""; bool enabled = true; if (dict.Value is string) { choicetext = dict.Value as string; } else if (dict.Value is LuaTable) { LuaTable tbl = dict.Value as LuaTable; choicetext = (string)tbl[1]; enabled = (bool)tbl[2]; } long choiceval = (long)dict.Key; if (defaultchoice.Equals(choiceval)) { mappedDefault = choices.Count; } if (cancelchoice.Equals(choiceval)) { mappedCancel = choices.Count; } choices.Add(new DialogueChoice(choicetext, () => { m_choiceresult = choiceval; DataManager.Instance.LogUIPlay((int)choiceval); }, enabled)); } //Make a choice menu, and check if we display a speaker or not if (m_curspeakerName != null) { m_curchoice = MenuManager.Instance.CreateMultiQuestion(m_curspeakerID, m_curspeakerName, m_curspeakerEmo, message, m_curspeakerSnd, choices.ToArray(), mappedDefault, mappedCancel); } else { m_curchoice = MenuManager.Instance.CreateMultiQuestion(message, m_curspeakerSnd, choices, mappedDefault, mappedCancel); } } catch (Exception e) { DiagManager.Instance.LogInfo(String.Format("ScriptUI.BeginChoiceMenu({0}): Encountered exception:\n{1}", message, e.Message)); } }
public LuaManager(string filepath, string regexNameParserText) { _regexNameParserText = regexNameParserText; _lua.DoFile(filepath); LuaTable CharTable = _lua.GetTable(_CharTablePath); IDictionaryEnumerator CharTableEnumerator = CharTable.GetEnumerator(); this.setCharTable(CharTableEnumerator); }
private void getBags(IDictionaryEnumerator tableEnumerator, string previousPath, Character character) { while (tableEnumerator.MoveNext()) { Item item = new Item(); string path = previousPath + "." + tableEnumerator.Entry.Key.ToString(); LuaTable bagsTable = _lua.GetTable(path); IDictionaryEnumerator bagsTableEnumerator = bagsTable.GetEnumerator(); this.getItemsInBag(bagsTableEnumerator, path, character); } }
private static void InterpretItems(Lua lua, String typeName) { LuaTable itemTable = lua.GetTable("data.raw")[typeName] as LuaTable; if (itemTable != null) { var enumerator = itemTable.GetEnumerator(); while (enumerator.MoveNext()) { InterpretLuaItem(enumerator.Key as String, enumerator.Value as LuaTable); } } }
private static Dictionary <String, Object> luaTable2DictionaryObject(LuaTable lTable) { var ht = new Dictionary <string, Object>(); IDictionaryEnumerator ienum = (IDictionaryEnumerator)lTable.GetEnumerator(); while (ienum.MoveNext()) { ht.Add((String)ienum.Key, ienum.Value); } return(ht); }
static public void setv(LuaTable t) { foreach (LuaTable.TablePair pair in t) { Debug.Log(string.Format("foreach LuaTable {0}-{1}", pair.key, pair.value)); break; } var iter = t.GetEnumerator(); while (iter.MoveNext()) { var pair = iter.Current; Debug.Log(string.Format("foreach LuaTable {0}-{1}", pair.key, pair.value)); break; } iter.Dispose(); }
/// <summary> /// Gets the dictionary enumerator for a table. /// </summary> /// <param name="table">The table to get an enumerator of.</param> /// <returns>A thread-safe enumerator on the table.</returns> public IDictionaryEnumerator SafeGetEnumerator(LuaTable table) { IEnumerator <KeyValuePair <LuaValue, LuaValue> > e; lock (_luaState) { try { e = table.GetEnumerator(); } catch (Exception ex) { return(HandleException(ex, null) as IDictionaryEnumerator); } } return((IDictionaryEnumerator) new SafeDictionaryEnumerator(e, this)); }
private Table parseString(string str) { Table retTable = new Table(); object[] lt = state.DoString("return " + str); if (lt != null && lt.Count() > 0) { LuaTable o = (LuaTable)lt[0]; IEnumerator enumra = o.Values.GetEnumerator(); int index = 1; while (enumra.MoveNext()) { string type = enumra.Current.GetType().ToString(); if (type == "NLua.LuaTable") { LuaTable table = enumra.Current as LuaTable; IEnumerator subEnumra = table.GetEnumerator(); Console.WriteLine(subEnumra.ToString()); //subEnumra.Current.GetType() string key = "";// ob.Key.ToString(); while (subEnumra.MoveNext()) { KeyValuePair <Object, Object> obj = (KeyValuePair <Object, Object>)subEnumra.Current; retTable.addValue(index + ":" + obj.Key.ToString(), obj.Value.ToString()); } } else { retTable.addValue(index + "", enumra.Current.ToString()); } index++; } } return(retTable); }
/// <summary> /// Marks the start of a multi-choice menu. /// Choices must be added after calling this method using the AddChoice() method. /// WaitForChoice() must be called afterwards for the menu to be actually displayed, /// and for execution to suspend until the choice is returned. /// Then to recover the integer value indicating the result of the menu, ChoiceResult() must be called. /// </summary> /// <param name="message">The question to ask the user.</param> public void BeginChoiceMenu(string message, LuaTable choicespairs, object defaultchoice, object cancelchoice) { try { m_choiceresult = null; int mappedDefault = 0; int mappedCancel = 0; //Intepret the choices from lua List <DialogueChoice> choices = new List <DialogueChoice>(); IDictionaryEnumerator dict = choicespairs.GetEnumerator(); while (dict.MoveNext()) { string choicetext = dict.Value as string; object choiceval = dict.Key; if (defaultchoice.Equals(choiceval)) { mappedDefault = choices.Count; } if (cancelchoice.Equals(choiceval)) { mappedCancel = choices.Count; } choices.Add(new DialogueChoice(choicetext, () => { m_choiceresult = choiceval; })); } //Make a choice menu, and check if we display a speaker or not if (m_curspeakerName != null) { m_curchoice = MenuManager.Instance.CreateMultiQuestion(m_curspeakerID, m_curspeakerName, m_curspeakerEmo, message, m_curspeakerSnd, choices.ToArray(), mappedDefault, mappedCancel); } else { m_curchoice = MenuManager.Instance.CreateMultiQuestion(message, m_curspeakerSnd, choices, mappedDefault, mappedCancel); } } catch (Exception e) { DiagManager.Instance.LogInfo(String.Format("ScriptUI.BeginChoiceMenu({0}): Encountered exception:\n{1}", message, e.Message)); } }
public void getCharacterItems(Character character) { string charBagsPath = _CharTablePath + "." + character.Name + ".Bag.Items"; string charBagScanPath = _CharTablePath + "." + character.Name + ".Bag.lastScanned"; string charBankBagsPath = _CharTablePath + "." + character.Name + ".Bank.Items"; string charBankScanPath = _CharTablePath + "." + character.Name + ".Bank.lastScanned"; character.LastBagScan = _lua.GetString(charBagScanPath); character.LastBankScan = _lua.GetString(charBankScanPath); LuaTable charBagsTable = _lua.GetTable(charBagsPath); IDictionaryEnumerator charBagsTableEnumerator = charBagsTable.GetEnumerator(); this.getBags(charBagsTableEnumerator, charBagsPath, character); LuaTable charBankBagsTable = _lua.GetTable(charBankBagsPath); IDictionaryEnumerator charBankBagsTableEnumerator = charBankBagsTable.GetEnumerator(); this.getBags(charBankBagsTableEnumerator, charBankBagsPath, character); }
public static void SetV(LuaTable t) { Debug.Log("negative index test " + t[-2]); Debug.Log("zero index test " + t[0]); foreach (LuaTable.TablePair pair in t) { Debug.Log(string.Format("foreach LuaTable {0}-{1}", pair.Key, pair.Value)); break; } IEnumerator <LuaTable.TablePair> iter = t.GetEnumerator(); while (iter.MoveNext()) { LuaTable.TablePair pair = iter.Current; Debug.Log(string.Format("foreach LuaTable {0}-{1}", pair.Key, pair.Value)); break; } iter.Dispose(); }
public DataLoader() { lua["package.path"] = Settings.FactorioPath + @"\data\base\?"; lua["package.path"] = lua["package.path"] + ";" + Settings.FactorioPath + @"\data\base\?.lua"; lua["package.path"] = lua["package.path"] + ";" + Settings.FactorioPath + @"\data\core\?"; lua["package.path"] = lua["package.path"] + ";" + Settings.FactorioPath + @"\data\core\?.lua"; lua["package.path"] = lua["package.path"] + ";" + Settings.FactorioPath + @"\data\core\lualib\?"; lua["package.path"] = lua["package.path"] + ";" + Settings.FactorioPath + @"\data\core\lualib\?.lua"; string luascript = (@" require ('util') function log(...) end serpent = {} serpent.block = function(n) return '' end settings = {} settings.startup = {} defines = {} defines.difficulty_settings = {} defines.difficulty_settings.recipe_difficulty = {} defines.difficulty_settings.technology_difficulty = {} defines.difficulty_settings.recipe_difficulty.normal = 1 defines.difficulty_settings.technology_difficulty.normal = 1 defines.direction = {} defines.direction.north = 1 defines.direction.east = 2 defines.direction.south = 3 defines.direction.west = 4 require('data') require('data-updates') "); lua.DoFile(Settings.FactorioPath + @"\data\core\lualib\dataloader.lua"); lua.DoFile(Settings.FactorioPath + @"\data\core\data.lua"); lua.DoString(luascript); lua.DoString(@" function electrolyserpictures() end data.raw['item-subgroup']['bob-greenhouse-items'] = {} data.raw['item-subgroup']['bob-greenhouse-items'].group = 'bob-intermediate-products' mods = {} "); LoadMods(); LuaTable rawRecipes = lua.GetTable("data.raw")["recipe"] as LuaTable; LuaTable rawFluids = lua.GetTable("data.raw")["fluid"] as LuaTable; LuaTable rawItems = lua.GetTable("data.raw")["item"] as LuaTable; LuaTable rawAssemblingMachines = lua.GetTable("data.raw")["assembling-machine"] as LuaTable; LuaTable rawFurnaces = lua.GetTable("data.raw")["furnace"] as LuaTable; LuaTable rawMiningDrills = lua.GetTable("data.raw")["mining-drill"] as LuaTable; LuaTable rawResources = lua.GetTable("data.raw")["resource"] as LuaTable; LuaTable rawModules = lua.GetTable("data.raw")["module"] as LuaTable; var fluidEnumerator = rawFluids.GetEnumerator(); while (fluidEnumerator.MoveNext()) { AddIconToCollection(fluidEnumerator.Value as LuaTable); Fluid newFluid = InterpretFluid(fluidEnumerator.Key as string, fluidEnumerator.Value as LuaTable); if (newFluid != null) { Data.AddFluid(newFluid.name, newFluid); } } var itemEnumerator = rawItems.GetEnumerator(); while (itemEnumerator.MoveNext()) { AddIconToCollection(itemEnumerator.Value as LuaTable); Item newItem = InterpretItem(itemEnumerator.Key as string, itemEnumerator.Value as LuaTable); if (newItem != null) { Data.AddItem(newItem.name, newItem); if (newItem.category != "" && !Data.ItemCategories.Contains(newItem.category)) { Data.ItemCategories.Add(newItem.category); } if (newItem.subgroup != "" && !Data.ItemSubgroups.Contains(newItem.subgroup)) { Data.ItemSubgroups.Add(newItem.subgroup); } } } var recipeEnumerator = rawRecipes.GetEnumerator(); while (recipeEnumerator.MoveNext()) { AddIconToCollection(recipeEnumerator.Value as LuaTable); Recipe newRecipe = InterpretRecipe(recipeEnumerator.Key as string, recipeEnumerator.Value as LuaTable); if (newRecipe != null) { Data.AddRecipe(newRecipe); if (newRecipe.category != "" && !Data.RecipeCategories.Contains(newRecipe.category)) { Data.RecipeCategories.Add(newRecipe.category); } if (newRecipe.subgroup != "" && !Data.RecipeSubgroups.Contains(newRecipe.subgroup)) { Data.RecipeSubgroups.Add(newRecipe.subgroup); } } } Data.Locale.Count(); }
public IDictionaryEnumerator GetEnumerator() { return(mTable.GetEnumerator()); }
private void InitUniqueMonsterConfig(NPCLevelMetaData npcLevelMetaData) { if (this.uniqueMonsterID != 0) { UniqueMonsterMetaData uniqueMonsterMetaData = MonsterData.GetUniqueMonsterMetaData(this.uniqueMonsterID); base.baseMaxHP = base.maxHP = base.HP = (this.metaConfig.HP * uniqueMonsterMetaData.HPRatio) * npcLevelMetaData.HPRatio; base.defense = (this.metaConfig.defense * uniqueMonsterMetaData.defenseRatio) * npcLevelMetaData.DEFRatio; base.attack = (this.metaConfig.attack * uniqueMonsterMetaData.attackRatio) * npcLevelMetaData.ATKRatio; if (uniqueMonsterMetaData.abilities.Length > 0) { LuaState state = new LuaState(); IDictionaryEnumerator enumerator = ((LuaTable)state.DoString(uniqueMonsterMetaData.abilities)[0]).GetEnumerator(); try { while (enumerator.MoveNext()) { ConfigAbility abilityConfig; DictionaryEntry current = (DictionaryEntry)enumerator.Current; string key = (string)current.Key; LuaTable table2 = (LuaTable)current.Value; string monsterName = uniqueMonsterMetaData.monsterName; if (monsterName == null) { abilityConfig = AbilityData.GetAbilityConfig(key); } else { abilityConfig = AbilityData.GetAbilityConfig(key, monsterName); } Dictionary <string, object> dictionary = new Dictionary <string, object>(); IDictionaryEnumerator enumerator2 = table2.GetEnumerator(); try { while (enumerator2.MoveNext()) { DictionaryEntry entry2 = (DictionaryEntry)enumerator2.Current; string str3 = (string)entry2.Key; if (entry2.Value is double) { dictionary.Add(str3, (float)((double)entry2.Value)); } else if (entry2.Value is string) { dictionary.Add(str3, (string)entry2.Value); } } } finally { IDisposable disposable = enumerator2 as IDisposable; if (disposable == null) { } disposable.Dispose(); } base.appliedAbilities.Add(Tuple.Create <ConfigAbility, Dictionary <string, object> >(abilityConfig, dictionary)); } } finally { IDisposable disposable2 = enumerator as IDisposable; if (disposable2 == null) { } disposable2.Dispose(); } } } }
IEnumerator <KeyValuePair <object, object> > IEnumerable <KeyValuePair <object, object> > .GetEnumerator() { return((IEnumerator <KeyValuePair <object, object> >)table.GetEnumerator()); }
public static void LoadRecipes(string factorioPath, List <string> mods) { DataCache.factorioPath = factorioPath; DataCache.mods = mods; using (Lua lua = new Lua()) { try { AddLuaPackagePath(lua, Path.Combine(factorioPath, "data", "core", "lualib")); lua.DoFile(Path.Combine(factorioPath, "data", "core", "lualib", "dataloader.lua")); Assembly assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream("Foreman.lua-compat.lua"); StreamReader rd = new StreamReader(stream); lua.DoString(rd.ReadToEnd()); AddLuaPackagePath(lua, Path.Combine(factorioPath, "data", "base")); lua.DoFile(Path.Combine(factorioPath, "data", "base", "data.lua")); foreach (string modDirectory in mods) { AddLuaPackagePath(lua, Path.Combine(modDirectory)); lua.DoFile(Path.Combine(modDirectory, "data.lua")); } } catch (NLua.Exceptions.LuaScriptException e) { Console.Out.WriteLine("error: " + e.ToString()); MessageBox.Show("Error loading factorio game data: " + e.ToString()); } foreach (String type in new List <String> { "item", "fluid", "capsule", "module", "ammo", "gun", "armor", "blueprint", "deconstruction-item" }) { InterpretItems(lua, type); } LuaTable recipeTable = lua.GetTable("data.raw")["recipe"] as LuaTable; if (recipeTable != null) { var recipeEnumerator = recipeTable.GetEnumerator(); while (recipeEnumerator.MoveNext()) { InterpretLuaRecipe(recipeEnumerator.Key as String, recipeEnumerator.Value as LuaTable); } } LuaTable assemblerTable = lua.GetTable("data.raw")["assembling-machine"] as LuaTable; if (assemblerTable != null) { var assemblerEnumerator = assemblerTable.GetEnumerator(); while (assemblerEnumerator.MoveNext()) { InterpretAssemblingMachine(assemblerEnumerator.Key as String, assemblerEnumerator.Value as LuaTable); } } LuaTable furnaceTable = lua.GetTable("data.raw")["furnace"] as LuaTable; if (furnaceTable != null) { var furnaceEnumerator = furnaceTable.GetEnumerator(); while (furnaceEnumerator.MoveNext()) { InterpretFurnace(furnaceEnumerator.Key as String, furnaceEnumerator.Value as LuaTable); } } LuaTable minerTable = lua.GetTable("data.raw")["mining-drill"] as LuaTable; if (minerTable != null) { var minerEnumerator = minerTable.GetEnumerator(); while (minerEnumerator.MoveNext()) { InterpretMiner(minerEnumerator.Key as String, minerEnumerator.Value as LuaTable); } } LuaTable resourceTable = lua.GetTable("data.raw")["resource"] as LuaTable; if (resourceTable != null) { var resourceEnumerator = resourceTable.GetEnumerator(); while (resourceEnumerator.MoveNext()) { InterpretResource(resourceEnumerator.Key as String, resourceEnumerator.Value as LuaTable); } } LuaTable moduleTable = lua.GetTable("data.raw")["module"] as LuaTable; if (moduleTable != null) { foreach (String moduleName in moduleTable.Keys) { InterpretModule(moduleName, moduleTable[moduleName] as LuaTable); } } UnknownIcon = LoadImage("UnknownIcon.png"); LoadLocaleFiles(); LoadItemNames("item-name"); LoadItemNames("fluid-name"); LoadItemNames("entity-name"); LoadItemNames("equipment-name"); LoadRecipeNames(); LoadEntityNames(); LoadModuleNames(); } }