示例#1
0
        /// <summary>
        /// Seeks eligible subjects, associates them with dictionary key, adds states into SaveState dictionary, wraps dictionary into SaveHolder
        /// </summary>
        /// <returns></returns>
        private SaveHolder WrapStates()
        {
            var SaveBuffer = new SerializableDictionary <int, SaveState>();
            var SaveHold   = new SaveHolder();

            foreach (var kvp in Studio.Studio.Instance.sceneInfo.dicObject)
            {
                switch (kvp.Value)
                {
                case OICharInfo x:
                    var charInfo  = (OICharInfo)kvp.Value;
                    var chars     = Studio.Studio.Instance.dicObjectCtrl.Values.OfType <OCIChar>();
                    var character = chars.FirstOrDefault(yx => yx.charInfo.chaFile == charInfo.charFile);
                    if (character == null)
                    {
                        continue;
                    }
                    SaveCharacter(character, kvp.Key, SaveBuffer);
                    break;

                case OIItemInfo y:
                    var itemInfo = (OIItemInfo)kvp.Value;
                    var items    = Studio.Studio.Instance.dicObjectCtrl.Values.OfType <OCIItem>();
                    var item     = items.FirstOrDefault(zz => zz.itemInfo.dicKey == itemInfo.dicKey);
                    if (item == null)
                    {
                        continue;
                    }
                    SaveItem(item, kvp.Key, SaveBuffer);
                    break;
                }
            }
            SaveHold.Buffer = SaveBuffer;
            return(SaveHold);
        }
示例#2
0
        private void LoadProcedure(XmlNode node)
        {
            Console.WriteLine("LoadProcedure");
            //Console.WriteLine(node.Name);
            //var nodes = node.ChildNodes;
            //foreach (XmlNode done in nodes)
            //{
            //    Console.WriteLine(done.Name);
            //}



            if (node == null || node.Name != "ControllerRoot")
            {
                Console.WriteLine("Root null");
                loadSuccess = false;
                return;
            }
            try
            {
                var state = node?.FirstChild.OuterXml;
                if (state == null || node.FirstChild.Name != "SaveHolder")
                {
                    Console.WriteLine("SaveHolder null");
                    loadSuccess = false;
                    return;
                }
                try
                {
                    SaveHolder holder = new SaveHolder();
                    holder = XML <SaveHolder> .From(state);

                    try
                    {
                        if (holder.Buffer == null)
                        {
                            Console.WriteLine("holderbuffer null");
                            loadSuccess = false;
                            return;
                        }
                        LoadBuffer = holder.Buffer;
                        if (LoadBuffer.Count == 0 || LoadBuffer == null)
                        {
                            loadSuccess = false;
                        }
                        else
                        {
                            loadSuccess = true;
                        }
                    }
                    catch
                    {
                        Console.WriteLine("layer3");
                    }
                }
                catch
                {
                    Console.WriteLine("layer2");
                }
            }
            catch
            {
                Console.WriteLine("layer1");
            }

            //Console.WriteLine("-----------LOADING-----------");
            //foreach (KeyValuePair<int, SaveState> kvp in LoadBuffer)
            //{
            //    Console.WriteLine("-----------------------------");
            //    Console.WriteLine(kvp.Key);
            //    Console.WriteLine(kvp.Value.X);
            //    Console.WriteLine(kvp.Value.Y);
            //    Console.WriteLine(kvp.Value.CtrlType);
            //    Console.WriteLine("-----------------------------");
            //}
            //Console.WriteLine("-----------END---------------");
            //File.WriteAllText("out2.txt", state);
            Console.WriteLine(loadSuccess);
        }