private void OnConversationLine(Subtitle subtitle)
        {
            var speaker = "\"Actor[\\\"" + DialogueLua.StringToTableIndex(subtitle.speakerInfo.nameInDatabase) + "\\\"]\"";
            var self    = "\"Dialog[" + subtitle.dialogueEntry.id + "]\""; // Note that Dialog[#] only has SimStatus to conserve memory. getProp() uses special case to get entry fields.

            Lua.Run("speaker = " + speaker + "; self = " + self, DialogueDebug.logInfo);
        }
示例#2
0
        public static string getObj(string objectName)
        {
            var db    = DialogueManager.MasterDatabase;
            var actor = db.actors.Find(x => string.Equals(objectName, x.Name) || string.Equals(objectName, x.LookupValue("Technical Name")) || string.Equals(objectName, x.LookupValue("Articy Id")));

            if (actor != null)
            {
                return("Actor[\"" + DialogueLua.StringToTableIndex(actor.Name) + "\"]");
            }
            var item = db.items.Find(x => string.Equals(objectName, x.Name) || string.Equals(objectName, x.LookupValue("Technical Name")) || string.Equals(objectName, x.LookupValue("Articy Id")));

            if (item != null)
            {
                return("Item[\"" + DialogueLua.StringToTableIndex(item.Name) + "\"]");
            }
            var location = db.locations.Find(x => string.Equals(objectName, x.Name) || string.Equals(objectName, x.LookupValue("Technical Name")) || string.Equals(objectName, x.LookupValue("Articy Id")));

            if (location != null)
            {
                return("Location[\"" + DialogueLua.StringToTableIndex(location.Name) + "\"]");
            }
            var conversation = db.conversations.Find(x => string.Equals(objectName, x.Title) || string.Equals(objectName, x.LookupValue("Technical Name")) || string.Equals(objectName, x.LookupValue("Articy Id")));

            if (conversation != null)
            {
                return("Conversation[\"" + conversation.id + "\"]");
            }
            return(null);
        }
示例#3
0
        private void DrawWatchVariableNamePopup(Watch watch)
        {
            if (watchableVariableNames == null || watchableVariableNames.Length == 0)
            {
                List <string> variableNames = new List <string>();
                if (database != null)
                {
                    foreach (var variable in database.variables)
                    {
                        variableNames.Add(variable.Name);
                    }
                }
                watchableVariableNames = variableNames.ToArray();
            }
            int newIndex = EditorGUILayout.Popup(watch.variableIndex, watchableVariableNames);

            if (newIndex != watch.variableIndex)
            {
                watch.variableIndex = newIndex;
                if (0 <= watch.variableIndex && watch.variableIndex < watchableVariableNames.Length)
                {
                    watch.expression = string.Format("Variable[\"{0}\"]", DialogueLua.StringToTableIndex(watchableVariableNames[watch.variableIndex]));
                }
                else
                {
                    watch.expression = string.Empty;
                }
                watch.Evaluate();
            }
        }
示例#4
0
 public override void OnEnter()
 {
     if ((actor1Name != null) && (actor2Name != null) && (relationshipType != null) && (incrementAmount != null))
     {
         Lua.Run(string.Format("IncRelationship(Actor[\"{0}\"], Actor[\"{1}\"], {2}, {3})",
                               DialogueLua.StringToTableIndex(actor1Name.Value), DialogueLua.StringToTableIndex(actor2Name.Value),
                               relationshipType.Value, incrementAmount.Value), DialogueDebug.LogInfo);
     }
     Finish();
 }
        public static object getProp(string objectIdentifier, string propertyName)
        {
            if (string.IsNullOrEmpty(objectIdentifier) || string.IsNullOrEmpty(propertyName))
            {
                return(string.Empty);
            }
            if (objectIdentifier.StartsWith("Dialog[") && DialogueManager.isConversationActive)
            {
                // Handle Dialog[#] specially:
                var entryID        = Tools.StringToInt(objectIdentifier.Substring(7, objectIdentifier.Length - 8));
                var conversationID = DialogueManager.currentConversationState.subtitle.dialogueEntry.conversationID;
                if (string.Equals("SimStatus", propertyName))
                {
                    return(DialogueLua.GetSimStatus(conversationID, entryID));
                }
                var entry = DialogueManager.masterDatabase.GetDialogueEntry(conversationID, entryID);
                if (entry == null)
                {
                    return(string.Empty);
                }
                var field = Field.Lookup(entry.fields, propertyName);
                if (field == null)
                {
                    return(string.Empty);
                }
                if (field.type == FieldType.Number)
                {
                    return(Tools.StringToFloat(field.value));
                }
                else if (field.type == FieldType.Boolean)
                {
                    return(Tools.StringToBool(field.value));
                }
                else
                {
                    return(field.value);
                }
            }
            var result = Lua.Run("return " + objectIdentifier + "." + DialogueLua.StringToTableIndex(GetShortPropertyName(propertyName)), DialogueDebug.logInfo);

            if (result.isBool)
            {
                return(result.asBool);
            }
            else if (result.isNumber)
            {
                return(result.asInt);
            }
            else
            {
                return(result.asString);
            }
        }
示例#6
0
 public override void OnEnter()
 {
     if ((actor1Name != null) && (actor2Name != null) && (relationshipType != null) && (storeResult != null))
     {
         try {
             storeResult.Value = Lua.Run(string.Format("return GetRelationship(Actor[\"{0}\"], Actor[\"{1}\"], \"{2}\")",
                                                       DialogueLua.StringToTableIndex(actor1Name.Value), DialogueLua.StringToTableIndex(actor2Name.Value),
                                                       relationshipType.Value), DialogueDebug.LogInfo).AsFloat;
         } catch (System.NullReferenceException) {
         }
     }
     Finish();
 }
示例#7
0
 public override void OnEnter()
 {
     if ((actor1Name != null) && (actor2Name != null) && (relationshipType != null) && (relationshipValue != null))
     {
         try {
             Lua.Run(string.Format("SetRelationship(Actor[\"{0}\"], Actor[\"{1}\"], {2}, {3})",
                                   DialogueLua.StringToTableIndex(actor1Name.Value), DialogueLua.StringToTableIndex(actor2Name.Value),
                                   relationshipType.Value, relationshipValue.Value), DialogueDebug.LogInfo);
         } catch (System.NullReferenceException) {
         }
     }
     Finish();
 }
示例#8
0
        public static object getProp(string objectIdentifier, string propertyName)
        {
            var result = Lua.Run("return " + objectIdentifier + "." + DialogueLua.StringToTableIndex(propertyName), DialogueDebug.logInfo);

            if (result.isBool)
            {
                return(result.asBool);
            }
            else if (result.isNumber)
            {
                return(result.asInt);
            }
            else
            {
                return(result.asString);
            }
        }
        /// <summary>
        /// Syncs AC's inventory to Lua.
        /// </summary>
        public void SyncInventoryToLua()
        {
            var inventoryManager = KickStarter.inventoryManager;
            var runtimeInventory = KickStarter.runtimeInventory;

            if (inventoryManager == null || runtimeInventory == null)
            {
                return;
            }
            foreach (var item in inventoryManager.items)
            {
                string luaName             = DialogueLua.StringToTableIndex(item.label);
                var    runtimeItemInstance = runtimeInventory.GetInstance(item.id);
                int    runtimeCount        = (runtimeItemInstance != null) ? runtimeItemInstance.Count : 0;
                Lua.Run(string.Format("Item[\"{0}\"] = {{ Name=\"{1}\", Description=\"\", Is_Item=true, AC_ID={2}, Count={3} }}",
                                      luaName, item.label, item.id, runtimeCount), debug || DialogueDebug.LogInfo);
            }
        }
示例#10
0
        /// <summary>
        /// Syncs AC's inventory to Lua.
        /// </summary>
        public void SyncInventoryToLua()
        {
            var inventoryManager = KickStarter.inventoryManager;
            var runtimeInventory = KickStarter.runtimeInventory;

            if (inventoryManager == null || runtimeInventory == null)
            {
                return;
            }
            foreach (InvItem item in inventoryManager.items)
            {
                string luaName = DialogueLua.StringToTableIndex(item.label);
                //---Was: InvItem runtimeItem = runtimeInventory.localItems.Find(x => x.id == item.id);
                InvItem runtimeItem  = runtimeInventory.GetItem(item.id);                // Credit: jackallplay. Thanks for the fix!
                int     runtimeCount = (runtimeItem != null) ? runtimeItem.count : 0;
                Lua.Run(string.Format("Item[\"{0}\"] = {{ Name=\"{1}\", Description=\"\", Is_Item=true, AC_ID={2}, Count={3} }}",
                                      luaName, item.label, item.id, runtimeCount), DialogueDebug.LogInfo);
            }
        }
        private void SyncVarListToLua(List <GVar> varList, bool global)
        {
            foreach (var variable in varList)
            {
                if (!string.Equals(variable.label, DialogueSystemGlobalVariableName))
                {
                    string luaName = DialogueLua.StringToTableIndex(variable.label);
                    if (global && prependGlobalVariables)
                    {
                        luaName = "global_" + luaName;
                    }
                    switch (variable.type)
                    {
                    case VariableType.Boolean:
                        bool boolValue = variable.BooleanValue;
                        DialogueLua.SetVariable(luaName, boolValue);
                        break;

                    case VariableType.Integer:
                    case VariableType.PopUp:
                        DialogueLua.SetVariable(luaName, variable.IntegerValue);
                        break;

                    case VariableType.Float:
                        DialogueLua.SetVariable(luaName, variable.FloatValue);
                        break;

                    case VariableType.String:
                        DialogueLua.SetVariable(luaName, variable.TextValue);
                        break;

                    default:
                        if (DialogueDebug.LogWarnings)
                        {
                            Debug.LogWarning("Dialogue System: AdventureCreatorBridge doesn't know how to sync variable type " + variable.type, this);
                        }
                        break;
                    }
                }
            }
        }
示例#12
0
        private static void InitializeLuaSubtablesForAsset <T>(string tableName, List <T> assets) where T : Asset
        {
            for (int i = 0; i < assets.Count; i++)
            {
                var asset = assets[i];
                for (int j = 0; j < asset.fields.Count; j++)
                {
                    var field = asset.fields[j];
                    if (field.title.StartsWith(SubtableFieldPrefix))
                    {
                        var subtableTitle = field.title.Substring(SubtableFieldPrefix.Length);
                        var code          = tableName + "[\"" + DialogueLua.StringToTableIndex(asset.Name) + "\"]." + DialogueLua.StringToTableIndex(subtableTitle) + " = { ";
                        if (!string.IsNullOrEmpty(field.value.Trim()))
                        {
                            var articyIds = field.value.Split(';');
                            for (int k = 0; k < articyIds.Length; k++)
                            {
                                var articyId    = articyIds[k];
                                var elementItem = FindAssetByArticyId(articyId);
                                if (elementItem != null)
                                {
                                    code += ((elementItem is Actor) ? "Actor" : "Item") + "[\"" + DialogueLua.StringToTableIndex(elementItem.Name) + "\"]";
                                }
                                else
                                {
                                    code += articyId;
                                }
                                code += ", ";
                            }
                        }
                        code += "}";
                        Lua.Run(code, DialogueDebug.logInfo);

                        // Clear original subtable field to save memory:
                        Lua.Run(tableName + "[\"" + DialogueLua.StringToTableIndex(asset.Name) + "\"]." + DialogueLua.StringToTableIndex(field.title) + " = nil", true);
                    }
                }
            }
        }
        private void SyncLuaToVarList(List <GVar> varList, bool global)
        {
            foreach (var variable in varList)
            {
                string luaName = DialogueLua.StringToTableIndex(variable.label);
                if (global && prependGlobalVariables)
                {
                    luaName = "global_" + luaName;
                }
                var luaValue = DialogueLua.GetVariable(luaName);
                switch (variable.type)
                {
                case VariableType.Boolean:
                    variable.BooleanValue = luaValue.asBool;
                    break;

                case VariableType.Integer:
                case VariableType.PopUp:
                    variable.IntegerValue = luaValue.asInt;
                    break;

                case VariableType.Float:
                    variable.FloatValue = luaValue.asFloat;
                    break;

                case VariableType.String:
                    variable.TextValue = luaValue.asString;
                    break;

                default:
                    if (DialogueDebug.LogWarnings)
                    {
                        Debug.LogWarning("Dialogue System: AdventureCreatorBridge doesn't know how to sync variable type " + variable.type, this);
                    }
                    break;
                }
            }
        }
示例#14
0
        private void OnConversationLine(Subtitle subtitle)
        {
            var self = "\"Actor[\\\"" + DialogueLua.StringToTableIndex(subtitle.speakerInfo.nameInDatabase) + "\\\"]\"";

            Lua.Run("speaker = " + self + "; self = " + self, DialogueDebug.logInfo);
        }
示例#15
0
        private void ApplyLuaToPosition()
        {
            string s = Lua.Run(string.Format("return Actor[\"{0}\"].Position", DialogueLua.StringToTableIndex(ActorName)), DialogueDebug.LogInfo).AsString;

            ApplyPositionString(s);
        }
示例#16
0
 public Variable FindVariableInDatabase(int variableIndex)
 {
     return((database == null) ? null : database.variables.Find(x => string.Equals(DialogueLua.StringToTableIndex(x.Name), watchableVariableNames[variableIndex])));
 }
示例#17
0
 private void RecordPositionToLua()
 {
     Lua.Run(string.Format("Actor[\"{0}\"].Position = \"{1}\"", DialogueLua.StringToTableIndex(ActorName), GetPositionString()), DialogueDebug.LogInfo);
 }