Пример #1
0
        public void ReduceTest()
        {
            // Reduce<T>
            List <string> origList = new List <string>();

            origList.Add("ONE");
            origList.Add("TWO");
            origList.Add("THREE");
            origList.Add("FOUR");

            string res = Functionals.Reduce <string, string>(String.Concat, origList);

            Assert.AreEqual("ONETWOTHREEFOUR", res);

            List <int> intList = new List <int>();

            intList.Add(1);
            intList.Add(2);
            intList.Add(3);
            intList.Add(4);

            int sum = Functionals.Reduce <int, int>(delegate(int x, int y) { return(x + y); }, intList, 5);

            Assert.AreEqual(15, sum);

            // Reduce<T, U>
            List <int> lenList = Functionals.Reduce <string, List <int> >(delegate(List <int> lengths, string s) { lengths.Add(s.Length); return(lengths); }, origList);

            Assert.AreEqual(lenList.Count, origList.Count);

            for (int i = 0; i < origList.Count; ++i)
            {
                Assert.IsTrue(origList[i].Length == lenList[i]);
            }
        }
Пример #2
0
        /// <summary>
        /// Receives messages from the server that report the assets of a single friend that was just hired by the user
        /// </summary>
        public void HiredFriend(Message message, FashionLevel level)
        {
            Jobs job = (Jobs)Enum.Parse(typeof(Jobs), message.Data[0].ToString());

            // Parse the XML from the message and build the avatars it describes
            mActiveTasks.Add
            (
                mScheduler.StartCoroutine
                (
                    BuildNpcs
                    (
                        job,
                        level,
                        Functionals.Reduce <XmlDocument, List <XmlNode> >
                        (
                            delegate(List <XmlNode> accumulator, XmlDocument docItem)
            {
                foreach (XmlNode node in docItem.SelectNodes("//Avatar"))
                {
                    accumulator.Add(node);
                }
                return(accumulator);
            },
                            MessageUtil.GetXmlDocumentsFromMessage(message)
                        ),
                        level.Gui.HiredFriendLoaded
                    )
                )
            );
        }
Пример #3
0
        public void BuildDefaultTest()
        {
            object aListOfInts         = Functionals.BuildDefault <List <int> >();
            object anInt               = Functionals.BuildDefault <int>();
            object binaryReaderDefault = Functionals.BuildDefault <BinaryReader>();            // Has no default constructor

            Assert.AreEqual(0, ((List <int>)aListOfInts).Count);
            Assert.AreEqual(0, (int)anInt);
            Assert.IsNull(binaryReaderDefault);
        }
Пример #4
0
        public void LoadClothing(IEnumerable <ItemId> itemIds, string levelPath)
        {
            mItemIdsToClothingItems.Clear();
            mItemTypeToClothingItem.Clear();
            mClothingLoaded = false;

            GameFacade.Instance.RetrieveProxy <ClientAssetRepository>().GetItemToAssetsXmlDoc(itemIds, delegate(XmlDocument itemsDoc)
            {
                XmlNodeList itemNodes = itemsDoc.SelectNodes("Items/Item");
                mItemsToLoad          = itemNodes.Count;

                GameFacade.Instance.RetrieveMediator <SchedulerMediator>().Scheduler.StartCoroutine(WaitForAssetsToDownload());

                XmlDocument fashionGui             = XmlUtility.LoadXmlDocument(FashionGameGui.FASHION_GUI_PATH);
                List <string> clothingButtonStyles = Functionals.Reduce <List <string> >
                                                     (
                    delegate(List <string> accumulator, object xmlNode)
                {
                    accumulator.Add(((XmlNode)xmlNode).InnerText);
                    return(accumulator);
                },
                    fashionGui.SelectNodes("GUI/ClothingButtonStyles/Style/@name")
                                                     );
                int styles = clothingButtonStyles.Count;

                foreach (XmlNode itemNode in itemNodes)
                {
                    List <AssetInfo> assetInfos = new List <AssetInfo>();
                    foreach (XmlNode assetNode in itemNode.SelectNodes("Assets/Asset"))
                    {
                        assetInfos.Add(new ClientAssetInfo(assetNode));
                    }

                    uint idOfItem       = uint.Parse(itemNode.SelectSingleNode("Id").InnerText);
                    ItemId itemId       = new ItemId(idOfItem);
                    string thumbnailUrl = itemNode.Attributes["thumbnailUrl"].InnerText;
                    string itemType     = itemNode.Attributes["type"].InnerText;

                    GameFacade.Instance.RetrieveProxy <ClientAssetRepository>().GetAssets <Asset>(assetInfos, delegate(IEnumerable <Asset> assets)
                    {
                        if (clothingButtonStyles.Count == 0)
                        {
                            throw new Exception("Not enough styles(" + styles + ") in " + FashionGameGui.FASHION_GUI_PATH + " 'GUI/ClothingButtonStyles/' for all the clothing items in this level(" + levelPath + ")");
                        }

                        string styleName = clothingButtonStyles[mRandom.Next(0, clothingButtonStyles.Count)];
                        clothingButtonStyles.Remove(styleName);

                        RetrieveItemAssetsFromRepository(itemId, itemType, thumbnailUrl, styleName, assets);
                    });
                }
            });
        }
Пример #5
0
        protected virtual void SendClientAvailableRooms(Guid sessionId, MessageSubType roomRequestType)
        {
            ServerAccount        account = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId);
            Action <XmlDocument> getAvailableRoomsCallback = delegate(XmlDocument xmlResponse)
            {
                List <IServerDistributedRoom> availableRooms     = new List <IServerDistributedRoom>();
                List <RoomProperties>         roomPropertiesList = RoomXmlUtil.GetRoomsPropertiesFromXml(xmlResponse, mServerStateMachine.ServerAssetRepository);
                foreach (RoomProperties roomProperties in roomPropertiesList)
                {
                    availableRooms.Add(CreateServerDistributedRoom(roomProperties));
                }
                Message availableRoomsMessage = GenerateSendClientAvailableRoomsMessage(availableRooms);
                //send message to client
                SendMessageToClient(availableRoomsMessage, sessionId);
            };

            switch (roomRequestType)
            {
            case MessageSubType.ClientOwnedRooms:
                RoomManagerServiceAPI.GetSessionOwnedRoomsService(account.AccountId, getAvailableRoomsCallback);
                break;

            case MessageSubType.PublicRooms:
                RoomManagerServiceAPI.GetAllSystemRoomsService(getAvailableRoomsCallback);
                break;

            case MessageSubType.FriendsRooms:

                IList <AccountId> friendAccountIds =
                    Functionals.MapImmediate <FacebookFriendInfo, AccountId>
                    (
                        delegate(FacebookFriendInfo facebookFriendInfo)
                {
                    return(facebookFriendInfo.AccountId);
                },
                        account.HangoutFacebookFriends
                    );

                RoomManagerServiceAPI.GetSessionOwnedRoomsWithPrivacyService(friendAccountIds, PrivacyLevel.Default, getAvailableRoomsCallback);
                break;

            default:
                //Console.WriteLine("be patient! not implemented yet!");
                List <IServerDistributedRoom> availableRooms = new List <IServerDistributedRoom>();
                Message availableRoomsMessage = GenerateSendClientAvailableRoomsMessage(availableRooms);
                //send message to client
                SendMessageToClient(availableRoomsMessage, sessionId);
                break;
            }
        }
Пример #6
0
        public void FilterImmediateTest()
        {
            List <string> origList = new List <string>();

            origList.Add("ONE");
            origList.Add("TWO");
            origList.Add("THREE");
            origList.Add("FOUR");

            IList <string> res = Functionals.FilterImmediate <string>(delegate(string s) { return(s.Length > 3); }, origList);

            foreach (string str in res)
            {
                Assert.IsTrue(str.Length > 3);
            }

            Assert.IsTrue(res.Count == 2);
        }
Пример #7
0
        private IEnumerator <IYieldInstruction> BuildLevel
        (
            XmlDocument levelXml,
            LevelInfo levelInfo,
            bool firstTimePlayed,
            Action <FashionLevel> fashionLevelResult
        )
        {
            //Console.WriteLine(Time.realtimeSinceStartup.ToString("f2") + "> Building Level");

            // Start loading the clothing assets
            ClothingMediator clothingMediator = GameFacade.Instance.RetrieveMediator <ClothingMediator>();

            clothingMediator.LoadClothing
            (
                Functionals.Map <ItemId>
                (
                    delegate(object xmlNode)
            {
                return(new ItemId(XmlUtility.GetUintAttribute((XmlNode)xmlNode, "id")));
            },
                    levelXml.SelectNodes("Level/Clothing/ClothingItem")
                ),
                levelInfo.LevelDataPath
            );

            yield return(new YieldWhile(delegate()
            {
                return !clothingMediator.ClothingLoaded;
            }));

            FashionNpcMediator fashionModelFactory = GameFacade.Instance.RetrieveMediator <FashionNpcMediator>();

            // Clear this value
            mLeveledThisLevel = false;

            // Make the first level that this player qualifies for
            FashionLevel result = new FashionLevel(levelInfo.LevelDataPath, fashionModelFactory, firstTimePlayed, levelInfo.Energy);

            fashionLevelResult(result);
            //Console.WriteLine(Time.realtimeSinceStartup.ToString("f2") + "> Build Level Completed");
        }
Пример #8
0
        public void FilterTest()
        {
            List <string> origList = new List <string>();

            origList.Add("ONE");
            origList.Add("TWO");
            origList.Add("THREE");
            origList.Add("FOUR");

            IEnumerable <string> res = Functionals.Filter <string>(delegate(string s) { return(s.Length > 3); }, origList);

            List <string> resCopy = new List <string>();

            foreach (string str in res)
            {
                Assert.IsTrue(str.Length > 3);
                resCopy.Add(str);
            }

            Assert.IsTrue(resCopy.Count == 2);
        }
Пример #9
0
        public void MapImmediateTest()
        {
            List <string> origList = new List <string>();

            origList.Add("ONE");
            origList.Add("TWO");
            origList.Add("THREE");
            origList.Add("FOUR");

            IList <string> res = Functionals.MapImmediate <string, string>(delegate(string s) { return(s.ToLower()); }, origList);

            int i = 0;

            foreach (string str in res)
            {
                Assert.IsTrue(str == origList[i].ToLower());
                ++i;
            }

            Assert.IsTrue(origList.Count == res.Count);
        }
Пример #10
0
        public static XmlDocument ResolveXRefs(XmlDocument rootNode)
        {
            Hangout.Shared.Func <List <XmlNode>, List <XmlNode>, object> xmlNodeListToRealList =
                delegate(List <XmlNode> result, object node)
            {
                result.Add((XmlNode)node);
                return(result);
            };

            List <XmlNode> xrefNodes = Functionals.Reduce <List <XmlNode> >
                                       (
                xmlNodeListToRealList,
                rootNode.SelectNodes(".//XRef")
                                       );

            while (xrefNodes.Count != 0)
            {
                XmlNode xrefNode = xrefNodes[0];
                xrefNodes.RemoveAt(0);

                XmlAttribute pathAttrib = xrefNode.Attributes["path"];
                XmlElement   resultNode = (XmlElement)rootNode.SelectSingleNode(pathAttrib.InnerText).CloneNode(true);

                xrefNodes.AddRange
                (
                    Functionals.Reduce <List <XmlNode> >
                    (
                        xmlNodeListToRealList,
                        resultNode.SelectNodes(".//XRef")
                    )
                );

                xrefNode.Attributes.Remove(pathAttrib);
                CopyAttributes(xrefNode, resultNode);

                xrefNode.ParentNode.ReplaceChild(resultNode, xrefNode);
            }

            return(rootNode);
        }
Пример #11
0
        public void AutoLayoutUpdate()
        {
            if (mAutoLayoutNeedsUpdate)
            {
                List <Rect> reservedSpace = new List <Rect>();
                foreach (KeyValuePair <IWidget, IGuiPosition> widget in mWidgets)
                {
                    widget.Key.Parent = this;

                    // Add all the non-autoLayout widget locations to the reservedSpace
                    if (!(widget.Value is IAutoLayout))
                    {
                        Vector2 widgetPosition = widget.Value.GetPosition(widget.Key);
                        reservedSpace.Add(new Rect(widgetPosition.x, widgetPosition.y, widget.Key.ExternalSize.x, widget.Key.ExternalSize.y));
                    }
                }

                IList <KeyValuePair <IWidget, IAutoLayout> > autolayoutWidgets =
                    Functionals.Reduce <KeyValuePair <IWidget, IGuiPosition>, List <KeyValuePair <IWidget, IAutoLayout> > >
                    (
                        delegate(List <KeyValuePair <IWidget, IAutoLayout> > accumulator, KeyValuePair <IWidget, IGuiPosition> element)
                {
                    if (element.Value is IAutoLayout)
                    {
                        accumulator.Add(new KeyValuePair <IWidget, IAutoLayout>(element.Key, (IAutoLayout)element.Value));
                    }
                    return(accumulator);
                },
                        mWidgets
                    );

                // Assign coordinates to any IAutoLayout Positions
                foreach (KeyValuePair <IWidget, IAutoLayout> widget in autolayoutWidgets)
                {
                    reservedSpace.Add(widget.Value.NextPosition(widget.Key, reservedSpace, this.InternalSize, autolayoutWidgets));
                }

                mAutoLayoutNeedsUpdate = false;
            }
        }
Пример #12
0
    private void ShowLoadGuiDialog()
    {
        mLoadGuiDialog.Showing = true;
        mAllGuisOnDisk.Clear();
        mAllGuisOnDisk.AddRange
        (
            Functionals.Map <string, FileInfo>
            (
                delegate(string path)
        {
            return(new FileInfo(path));
        },
                Directory.GetFiles(Application.dataPath + "/Resources", "*.gui.xml", SearchOption.AllDirectories)
            )
        );

        mAllGuisOnDisk.Sort(delegate(FileInfo a, FileInfo b)
        {
            return(a.Name.CompareTo(b.Name));
        });

        LayoutGuiListings();
    }
Пример #13
0
        private void GetAllHiredAvatars(Message message, Guid sessionId)
        {
            ServerAccount localUserServerAccount = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId);

            AvatarManagerServiceAPI.GetAvatarForUser(localUserServerAccount, delegate(XmlDocument localAvatarXml)
            {
                FashionMinigameServiceAPI.GetAllHiredFriends(localUserServerAccount, delegate(XmlDocument hiredFriendsXml)
                {
                    Dictionary <long, Jobs> friendFbIds = Functionals.Reduce <Dictionary <long, Jobs> >
                                                          (
                        delegate(Dictionary <long, Jobs> accumulator, object friendIdNode)
                    {
                        XmlNode friendNode = (XmlNode)friendIdNode;
                        foreach (string idText in friendNode.InnerText.Split(','))
                        {
                            accumulator.Add(long.Parse(idText), (Jobs)Enum.Parse(typeof(Jobs), friendNode.SelectSingleNode("@KeyName").InnerText));
                        }
                        return(accumulator);
                    },
                        hiredFriendsXml.SelectNodes("//DataKey")
                                                          );

                    List <object> resultData = new List <object>();

                    XmlNode localAvatarNode = localAvatarXml.SelectSingleNode("//Avatar");

                    XmlAttribute fbidAttrib = localAvatarXml.CreateAttribute("FBID");
                    fbidAttrib.InnerText    = localUserServerAccount.FacebookAccountId.ToString();
                    localAvatarNode.Attributes.Append(fbidAttrib);

                    XmlAttribute firstnameAttrib = localAvatarXml.CreateAttribute("FirstName");
                    firstnameAttrib.InnerText    = localUserServerAccount.Nickname;
                    localAvatarNode.Attributes.Append(firstnameAttrib);

                    XmlAttribute lastnameAttrib = localAvatarXml.CreateAttribute("LastName");
                    lastnameAttrib.InnerText    = "";
                    localAvatarNode.Attributes.Append(lastnameAttrib);

                    resultData.Add(localAvatarXml.OuterXml);

                    ProcessHiredFriends
                    (
                        localUserServerAccount,
                        delegate(List <object> messageData)
                    {
                        friendFbIds.Add(localUserServerAccount.FacebookAccountId, Jobs.Model);

                        Message responseMessage    = new Message();
                        List <object> responseData = new List <object>();
                        responseData.Insert(0, message.Data[0]);                                 // callbackId

                        // Build asset lists for all the avatars and add minigame data
                        foreach (XmlDocument avatarXml in MessageUtil.GetXmlDocumentsFromMessageData(messageData))
                        {
                            XmlNode avatarNode = avatarXml.SelectSingleNode("//Avatar");
                            ReplaceItemIdsWithDna((XmlElement)avatarNode);

                            // The job name will be the DataKey the FBID was stored under
                            XmlAttribute avatarJobAttrib = avatarXml.CreateAttribute("job");
                            long fbid = long.Parse(avatarNode.SelectSingleNode("@FBID").InnerText);
                            Jobs friendJob;
                            if (friendFbIds.TryGetValue(fbid, out friendJob))
                            {
                                avatarJobAttrib.InnerText = friendJob.ToString();
                            }
                            else if (fbid == 0)                                    // Unknown user
                            {
                            }
                            else
                            {
                                string errorMessage = "Unable to find job info for FBID: " + fbid;
                                mLogger.Error(errorMessage);
                                avatarJobAttrib.InnerText = errorMessage;
                            }

                            avatarNode.Attributes.Append(avatarJobAttrib);
                            responseData.Add(avatarNode.OuterXml);
                        }

                        responseMessage.FashionGameModelAssetMessage(responseData);
                        SendMessageToClient(responseMessage, sessionId);
                    },
                        resultData,
                        friendFbIds.Keys
                    );
                });
            });
        }