Пример #1
0
        private static object SanitizeValue(object value)
        {
            if (SanitationDisabled)
            {
                return(value);
            }

            // TODO: Reenable variable sanitization when there a C# serializer is implemented.
            if (value == null)
            {
                return(null);
            }
            if (value is string || value is bool || value is int || value is double || value is float)
            {
                return(value);
            }
            if (!(value is NativeLuaTable))
            {
                return(null);
            }


            var t = new NativeLuaTable();

            (value as NativeLuaTable).__Foreach((k, v) =>
            {
                t[k] = SanitizeValue(v);
            });
            return(t);
        }
Пример #2
0
 public void Load(NativeLuaTable savedVariables)
 {
     foreach (var savedVariablesName in this.savedVariablesNames)
     {
         this.LoadObject(savedVariablesName, savedVariables[savedVariablesName]);
     }
 }
Пример #3
0
        public NativeLuaTable GenerateMenuTable()
        {
            var entry = new NativeLuaTable();

            if (this.InnerList != null)
            {
                entry["hasArrow"] = true;
                entry["menuList"] = this.InnerList.GenerateMenuTable();
            }

            if (!string.IsNullOrEmpty(this.text))
            {
                entry["text"] = this.text;
            }

            if (!string.IsNullOrEmpty(this.icon))
            {
                entry["icon"] = this.icon;
            }

            if (this.action != null)
            {
                entry["func"] = this.action;
            }

            return(entry);
        }
Пример #4
0
        public void TestEntityStoreSetOverwrites()
        {
            // Set up
            var id1        = "entity1";
            var e1         = MakeEntity(id1);
            var e1New      = MakeEntity(id1);
            var savedData  = new NativeLuaTable();
            var savedData1 = new NativeLuaTable();

            savedData[id1] = savedData1;
            var e1NewSerialised = new NativeLuaTable();

            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(savedData);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(savedData1)).Returns(e1);
            this.serializerMock.Setup(s => s.Serialize(e1New)).Returns(e1NewSerialised);

            // Execute
            this.storeUnderTest.LoadFromSaved();
            this.storeUnderTest.Set(e1New);

            // Assert
            this.serializerMock.Verify(s => s.Serialize(e1New), Times.Once);
            this.savedDataHandlerMock.Verify(s => s.SetVar(id1, e1NewSerialised), Times.Once);
            Assert.AreEqual(e1New, this.storeUnderTest.Get(id1));
            this.entityUpdateSubCenterMock.Verify(center => center.TriggerSubscriptionUpdate(e1New), Times.Once);
        }
Пример #5
0
        public void TestEntityStoreRemove()
        {
            // Set up
            var id1 = "entity1";
            var id2 = "entity2";
            var id3 = "entity3";
            var e1  = MakeEntity(id1);
            var e2  = MakeEntity(id2);
            var e3  = MakeEntity(id3);
            var t1  = new NativeLuaTable();
            var t2  = new NativeLuaTable();
            var t3  = new NativeLuaTable();

            var savedData = new NativeLuaTable();

            savedData[id1] = t1;
            savedData[id2] = t2;
            savedData[id3] = t3;
            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(savedData);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(t1)).Returns(e1);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(t2)).Returns(e2);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(t3)).Returns(e3);

            // Execute
            this.storeUnderTest.LoadFromSaved();
            this.storeUnderTest.Remove(id2);

            // Assert
            var idList = this.storeUnderTest.GetIds();

            Assert.AreEqual(2, idList.Count);
            Assert.AreEqual(id1, idList[0]);
            Assert.AreEqual(id3, idList[1]);
        }
        public void TestEntityStoreWithDefaultsGetAll()
        {
            // Set up
            var id1 = "entity1";
            var id2 = "entity2";
            var id3 = "entity3";
            var e1  = MakeEntity(id1);
            var e2  = MakeEntity(id2);
            var e3  = MakeEntity(id3);
            var t1  = new NativeLuaTable();
            var t2  = new NativeLuaTable();
            var t3  = new NativeLuaTable();

            var savedData = new NativeLuaTable();

            savedData[id1] = t1;
            savedData[id2] = t2;
            savedData[id3] = t3;
            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(savedData);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(t1)).Returns(e1);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(t2)).Returns(e2);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(t3)).Returns(e3);

            // Execute
            this.storeUnderTest.LoadFromSaved();
            var allEntities = this.storeUnderTest.GetAll();

            // Assert
            Assert.AreEqual(3, allEntities.Count);
            Assert.AreEqual(e1, allEntities[0]);
            Assert.AreEqual(e2, allEntities[1]);
            Assert.AreEqual(e3, allEntities[2]);
        }
Пример #7
0
        public void Click(string text)
        {
            var visibleFrames = this.util.GetVisibleFrames().ToList();
            var button        = (IButton)visibleFrames
                                .FirstOrDefault(f => f is IButton && this.ButtonMatchesText(f as IButton, text));

            if (button != null)
            {
                this.Click(button);
                return;
            }

            var label = visibleFrames.Where(f => f is IButton).SelectMany(f => f.GetRegions()).FirstOrDefault(r =>
                                                                                                              (r is IFontString && text.Equals((r as IFontString).GetText())));

            if (label != null)
            {
                button = (IButton)label.GetParent();
                this.Click(button);
                return;
            }

            if (this.currentMenu != null)
            {
                var found = false;
                Table.Foreach(this.currentMenu, (key, value) =>
                {
                    if (found)
                    {
                        return;
                    }
                    if (!(value is NativeLuaTable))
                    {
                        return;
                    }

                    var t = (NativeLuaTable)value;
                    if (!t["text"].Equals(text))
                    {
                        return;
                    }

                    if (t["menuList"] is NativeLuaTable)
                    {
                        this.currentMenu = (t["menuList"] as NativeLuaTable);
                    }
                    else if (t["func"] is Action)
                    {
                        (t["func"] as Action)();
                    }
                    found = true;
                });
                if (found)
                {
                    return;
                }
            }

            throw new UiSimuationException(string.Format("Could not find element matching text '{0}' to click on.", text));
        }
Пример #8
0
        public static T GetTableValue <T>(NativeLuaTable t, params object[] indexes)
        {
            var value = t[indexes[0]];

            if (indexes.Length == 1)
            {
                return((T)value);
            }
            return(GetTableValue <T>((NativeLuaTable)value, indexes.Skip(1).ToArray()));
        }
Пример #9
0
        private static NativeLuaTable GenerateTitleMenuTableEntry()
        {
            var titleEntry = new NativeLuaTable();

            titleEntry["isTitle"]      = true;
            titleEntry["text"]         = "Select an entity to track";
            titleEntry["notCheckable"] = true;

            return(titleEntry);
        }
Пример #10
0
        public NativeLuaTable GetSavedVariables()
        {
            var t = new NativeLuaTable();

            foreach (var savedVariablesName in this.savedVariablesNames)
            {
                t[savedVariablesName] = this.GetVariable(savedVariablesName);
            }
            return(t);
        }
        public void TestEntityStoreWithDefaultsGetWithWrongIdThrows()
        {
            // Set up
            var savedData = new NativeLuaTable();

            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(savedData);

            // Execute
            this.storeUnderTest.LoadFromSaved();
            this.storeUnderTest.Get("WrongID");
        }
Пример #12
0
        private NativeLuaTable ListToLuaTable(List <string> list)
        {
            var t = new NativeLuaTable();

            for (var index = 0; index < list.Count; index++)
            {
                t[index] = list[index];
            }

            return(t);
        }
Пример #13
0
        private static NativeLuaTable GenerateMenuListForEntities(List <ITrackableEntity> entities)
        {
            var menuList = new NativeLuaTable();

            foreach (var entity in entities)
            {
                Table.insert(menuList, GenerateEntryForEntity(entity));
            }

            return(menuList);
        }
Пример #14
0
        private static NativeLuaTable GenerateEntryForEntityType(string entityTypeName, List <ITrackableEntity> entities)
        {
            var entry = new NativeLuaTable();

            entry["hasArrow"]     = true;
            entry["text"]         = entityTypeName;
            entry["menuList"]     = GenerateMenuListForEntities(entities);
            entry["notCheckable"] = true;

            return(entry);
        }
Пример #15
0
        public NativeLuaTable ToNativeLuaTable()
        {
            var t = new NativeLuaTable();

            t["Top"]    = this.Top;
            t["Bottom"] = this.Bottom;
            t["Left"]   = this.Left;
            t["Right"]  = this.Right;

            return(t);
        }
Пример #16
0
        private static NativeLuaTable GenerateEntryForEntity(ITrackableEntity entity)
        {
            var entry = new NativeLuaTable();

            entry["text"]         = entity.Name;
            entry["icon"]         = entity.IconPath;
            entry["func"]         = entity.OnSelect.ToLuaFunction();
            entry["notCheckable"] = true;

            return(entry);
        }
        /// <summary>
        /// Loads an entity with a provided id and a provided set of default serialized info.
        /// </summary>
        /// <param name="id">The id of the entity to load.</param>
        /// <param name="defaultInfo">The serialized default info to compare with.</param>
        private void LoadEntity(object id, NativeLuaTable defaultInfo)
        {
            T1 defaultEntity = this.defaultEntities.FirstOrDefault(o => o.Id.Equals(id));

            if (defaultEntity != null)
            {
                defaultInfo = MergeUA(defaultInfo, this.serializer.Serialize(defaultEntity));
            }

            this.entities.Add(this.serializer.Deserialize <T1>(defaultInfo));
        }
Пример #18
0
        public void TestInitialize()
        {
            this.dataSetInGlobal = new NativeLuaTable {
                [this.subIndex] = new NativeLuaTable()
            };
            var globalApiMock = new Mock <IApi>();

            globalApiMock.Setup(api => api.GetGlobal(this.indexOfDataSet)).Returns(this.dataSetInGlobal);
            globalApiMock.Setup(api => api.SetGlobal(this.indexOfDataSet, this.dataSetInGlobal));
            Global.Api = globalApiMock.Object;
        }
Пример #19
0
        public void TestSavedDataHandlerSetVarWithSubIndex()
        {
            // Setup
            var expectedTable        = new NativeLuaTable();
            var dataHandlerUnderTest = new SavedDataHandler(this.indexOfDataSet, this.subIndex);

            // Act
            dataHandlerUnderTest.SetVar("index", expectedTable);

            // Assert
            Assert.AreEqual(expectedTable, ((NativeLuaTable)this.dataSetInGlobal[this.subIndex])["index"]);
        }
Пример #20
0
        private static NativeLuaTable CreateMenuTable(IEntitySelection selection)
        {
            var menuTable = new NativeLuaTable();

            Table.insert(menuTable, GenerateTitleMenuTableEntry());

            foreach (var entityCategory in selection)
            {
                Table.insert(menuTable, GenerateEntryForEntityType(entityCategory.Key, entityCategory.Value));
            }

            return(menuTable);
        }
Пример #21
0
        private static void SlashCmd(string fullCmd, NativeLuaTable _)
        {
            var t            = Strings.strsplittotable(" ", fullCmd);
            var cmd          = (string)Table.remove(t, 1);
            var remainingCmd = Strings.strjoinfromtable(" ", t);

            switch (cmd)
            {
            default:
                Core.print("Unknown command:", cmd);
                break;
            }
        }
Пример #22
0
        public void TestEntityStoreGetWithWrongId()
        {
            // Set up
            var savedData = new NativeLuaTable();

            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(savedData);

            // Execute
            this.storeUnderTest.LoadFromSaved();
            var ret = this.storeUnderTest.Get("WrongID");

            // Assert
            Assert.AreEqual(null, ret);
        }
Пример #23
0
        public void TestSavedDataHandlerGetVarWithoutSubIndex()
        {
            // Setup
            var expectedTable = new NativeLuaTable();

            this.dataSetInGlobal["index"] = expectedTable;
            var dataHandlerUnderTest = new SavedDataHandler(this.indexOfDataSet);

            // Act
            var actualTable = dataHandlerUnderTest.GetVar("index");

            // Assert
            Assert.AreEqual(expectedTable, actualTable);
        }
Пример #24
0
        private static Type FrameTypeTranslator(NativeLuaTable obj)
        {
            if (obj["GetObjectType"] == null)
            {
                return(null);
            }

            var type      = (obj["GetObjectType"] as Func <NativeLuaTable, string>)(obj);
            var frameType = (FrameType)Enum.Parse(typeof(FrameType), type);

            switch (frameType)
            {
            case FrameType.Frame:
                return(typeof(IFrame));

            case FrameType.Button:
                return(typeof(IButton));

            case FrameType.CheckButton:
                return(typeof(ICheckButton));

            case FrameType.EditBox:
                return(typeof(IEditBox));

            case FrameType.GameTooltip:
                return(typeof(IGameTooltip));

            case FrameType.ScrollFrame:
                return(typeof(IScrollFrame));

            case FrameType.FontString:
                return(typeof(IFontString));

            case FrameType.FontInstance:
                return(typeof(IFontInstance));

            case FrameType.Slider:
                return(typeof(ISlider));

            case FrameType.StatusBar:
                return(typeof(IStatusBar));

            case FrameType.Texture:
                return(typeof(ITexture));

            default:
                throw new Exception("Could not translate frame type " + type);
            }
        }
Пример #25
0
        private static object CreateInstance(Type type, NativeLuaTable t)
        {
            if (type.IsArray)
            {
                var length = 0;
                while (t["3#_" + length] != null)
                {
                    length++;
                }

                return(Array.CreateInstance(type.GetInterface("IEnumerable`1").GetGenericArguments().Single(), length));
            }

            return(Activator.CreateInstance(type));
        }
        public void TestEntityStoreWithDefaultsSetDefaultAfterLoadThrows()
        {
            // Set up
            var id1                 = "entity1";
            var e1Default           = MakeEntity(id1);
            var e1DefaultSerialized = new NativeLuaTable();

            e1DefaultSerialized["Value1"] = 43;

            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(new NativeLuaTable());

            // Execute
            this.storeUnderTest.LoadFromSaved();
            this.storeUnderTest.SetDefault(e1Default);
        }
 /// <summary>
 /// Merge u into a.
 /// </summary>
 /// <param name="u">The u set.</param>
 /// <param name="a">The a set.</param>
 /// <returns>U merged into a.</returns>
 private static NativeLuaTable MergeUA(NativeLuaTable u, NativeLuaTable a)
 {
     Table.Foreach(
         u,
         (key, value) =>
     {
         if (Core.type(value) == "table" && Core.type(a[key]) == "table")
         {
             a[key] = MergeUA(value as NativeLuaTable, a[key] as NativeLuaTable);
         }
         else
         {
             a[key] = value;
         }
     });
     return(a);
 }
Пример #28
0
        public void TestSavedDataHandlerGetAllWithoutSubIndex()
        {
            // Setup
            var expectedTable1 = new NativeLuaTable();
            var expectedTable2 = new NativeLuaTable();

            this.dataSetInGlobal["index1"] = expectedTable1;
            this.dataSetInGlobal["index2"] = expectedTable2;
            var dataHandlerUnderTest = new SavedDataHandler(this.indexOfDataSet);

            // Act
            var actualTable = dataHandlerUnderTest.GetAll();

            // Assert
            Assert.AreEqual(expectedTable1, actualTable["index1"]);
            Assert.AreEqual(expectedTable2, actualTable["index2"]);
        }
Пример #29
0
        private static void SetBackdrop(IFrame frame, string texture)
        {
            var backdrop = new NativeLuaTable();

            backdrop["bgFile"]   = texture;
            backdrop["edgeFile"] = "Interface/Tooltips/UI-Tooltip-Border";
            backdrop["tile"]     = false;
            backdrop["tileSize"] = 16;
            backdrop["edgeSize"] = 16;
            var inserts = new NativeLuaTable();

            backdrop["left"]   = TitleBar.BorderSize;
            backdrop["right"]  = TitleBar.BorderSize;
            backdrop["top"]    = TitleBar.BorderSize;
            backdrop["bottom"] = TitleBar.BorderSize;
            backdrop["insets"] = inserts;
            frame.SetBackdrop(backdrop);
        }
Пример #30
0
        public void TestEntityStoreGet()
        {
            // Set up
            var id1        = "entity1";
            var e1         = MakeEntity(id1);
            var savedData  = new NativeLuaTable();
            var savedData1 = new NativeLuaTable();

            savedData[id1] = savedData1;
            this.savedDataHandlerMock.Setup(sdh => sdh.GetAll()).Returns(savedData);
            this.serializerMock.Setup(s => s.Deserialize <IIdEntity <string> >(savedData1)).Returns(e1);

            // Execute
            this.storeUnderTest.LoadFromSaved();
            var e1Ret = this.storeUnderTest.Get(id1);

            // Assert
            Assert.AreEqual(e1, e1Ret);
        }