Exemple #1
0
 private void LabelToLuaVars(ACA.LabelX.Label.Label label, string prefix)
 {
     foreach (KeyValuePair <string, ACA.LabelX.Label.Label.Value> pair in label.Values)
     {
         string var = VarNameToLua(pair.Key, prefix);
         variableList.Items.Add(var);
         dictionary.Add(var, pair.Value.Data);
     }
 }
Exemple #2
0
 private void LabelVarsToLua(ACA.LabelX.Label.Label label, string prefix, Dictionary <string, string> dictionary, Lua lua)
 {//Converts label variables to lua variables, puts the lua variables in a dictionary and adds them to lua.
     foreach (KeyValuePair <string, ACA.LabelX.Label.Label.Value> pair in label.Values)
     {
         string luaVarName = VarNameToLua(pair.Key, prefix);
         try
         {
             dictionary.Add(luaVarName, pair.Key); //TODO handle duplicates
         }
         catch (Exception e)
         {
             GlobalDataStore.Logger.Error(e.Message);
         }
         lua[luaVarName] = pair.Value.Data;
     }
 }
Exemple #3
0
        private void executeLua(ACA.LabelX.Label.Label currentLabel, ACA.LabelX.Label.Label defaultLabel, ACA.LabelX.Label.Label baseLabel, ACA.LabelX.Label.Label staticVarsLabel)
        {
            //Lua lua = new Lua();
            if (!String.IsNullOrEmpty(labelDef.luaCode))
            {
                Lua lua = new Lua();
                //try
                //{
                Dictionary <string, string> LabelVariablesDict = new Dictionary <string, string>();
                LabelVarsToLua(currentLabel, "cl", LabelVariablesDict, lua);
                LabelVarsToLua(defaultLabel, "dl", LabelVariablesDict, lua);
                LabelVarsToLua(baseLabel, "bl", LabelVariablesDict, lua);
                LabelVarsToLua(staticVarsLabel, "staticvar", LabelVariablesDict, lua);
                try
                {
                    lua.DoString(labelDef.luaCode);
                }
                catch (LuaException ex4)
                {
                    // A Lua Exception occurred. This can be a programming
                    // error, or for example a call to error()
                    //Future:
                    // In the future this has to lead to a skip of this label.
                    // Now we hide the error... This should not be done if called
                    // from the label designer... Also to be done in the future.
                    GlobalDataStore.Logger.Error(string.Format("Lua Exception: {0}", ex4.Message));
                }

                LuaTable globalLuaTable = lua.GetTable("_G");
                Dictionary <string, string> LuaVariablesDict = new Dictionary <string, string>();

                foreach (DictionaryEntry de in globalLuaTable)
                {
                    LuaVariablesDict.Add(de.Key.ToString(), de.Value.ToString());
                }

                LuaVarsToLabel(LabelVariablesDict, currentLabel, defaultLabel, baseLabel, staticVarsLabel, LuaVariablesDict, lua);
                //}
                //catch (Exception e)
                //{
                //    System.Diagnostics.Debug.WriteLine(e.Message);
                //}
                lua.Dispose();
            }
            //lua.Dispose();
        }
Exemple #4
0
        private void LuaVarsToLabel(Dictionary <string, string> LabelVariablesDict, ACA.LabelX.Label.Label currentLabel, ACA.LabelX.Label.Label defaultLabel, ACA.LabelX.Label.Label baseLabel, ACA.LabelX.Label.Label staticVarsLabel, Dictionary <string, string> LuaVariablesDict, Lua lua)
        {//Converts Dictionary with lua variable names back to their labels
            foreach (KeyValuePair <string, string> pair in LuaVariablesDict)
            {
                ACA.LabelX.Label.Label labelToUse = null;
                if (pair.Key.StartsWith("cl_"))
                {
                    labelToUse = currentLabel;
                }
                else if (pair.Key.StartsWith("dl_"))
                {
                    labelToUse = defaultLabel;
                }
                else if (pair.Key.StartsWith("bl_"))
                {
                    labelToUse = baseLabel;
                }
                else if (pair.Key.StartsWith("staticvar_"))
                {
                    labelToUse = staticVarsLabel;
                }
                if (labelToUse != null)
                {
                    ACA.LabelX.Label.Label.Value value;
                    string labelPrintNaam;

                    if (LabelVariablesDict.TryGetValue(pair.Key, out labelPrintNaam))
                    {
                        if (labelToUse.Values.TryGetValue(labelPrintNaam, out value))
                        {
                            string luaValue = lua[pair.Key].ToString();

                            if (luaValue != null)
                            {
                                value.Data = luaValue;
                            }

                            /* mve fix
                             * if (!string.IsNullOrEmpty(luaValue))
                             * {
                             *  value.Data = luaValue;
                             * }
                             */
                        }
                    }
                    else if (pair.Key.StartsWith("staticvar_")) //If the key doesn't exist but is a staticvar, add it
                    {
                        string[] stringAr = pair.Key.Split('_');
                        if (isInteger(stringAr[stringAr.Length - 1])) //If last part isn't a language code, don't bother
                        {
                            string languagecode = stringAr[stringAr.Length - 1];
                            string variableName = "";
                            for (int i = 1; i < stringAr.Length - 1; i++)
                            {
                                variableName = variableName + stringAr[i] + '_';
                            }
                            variableName = variableName.Substring(0, variableName.Length - 1);
                            variableName = variableName + '.' + languagecode;

                            ACA.LabelX.Label.Label.Value tempvalue = new ACA.LabelX.Label.Label.Value();
                            tempvalue.Type = "xs:string";
                            tempvalue.Key  = variableName;
                            tempvalue.Data = pair.Value;
                            KeyValuePair <string, ACA.LabelX.Label.Label.Value> tempKeyValuePair = new KeyValuePair <string, ACA.LabelX.Label.Label.Value>(variableName, tempvalue);
                            labelToUse.Values.Add(tempKeyValuePair);
                        }
                    }
                }
            }
        }