Example #1
0
        /// <summary>
        /// Find object by MMO style path (based on label)
        /// <example>e.g. "all_parts/全体構造/■全体レイアウト"</example>
        /// </summary>
        /// <param name="psbObj"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static IPsbValue FindByMmoPath(this IPsbCollection psbObj, string path)
        {
            if (psbObj == null)
            {
                return(null);
            }
            if (path.StartsWith("/"))
            {
                path = new string(path.SkipWhile(c => c == '/').ToArray());
            }

            string current = null;
            int    pos     = -1;

            if (path.Contains("/"))
            {
                pos     = path.IndexOf('/');
                current = path.Substring(0, pos);
            }
            else
            {
                current = path;
            }

            IPsbValue currentObj = null;

            if (psbObj is PsbCollection col)
            {
                currentObj = col.FirstOrDefault(c =>
                                                c is PsbDictionary d && d.ContainsKey("label") && d["label"] is PsbString s &&
                                                s.Value == current);
            }
            else if (psbObj is PsbDictionary dic)
            {
                //var dd = dic.Value.FirstOrDefault();
                var children =
                    (PsbCollection)(dic.ContainsKey("layerChildren") ? dic["layerChildren"] : dic["children"]);
                currentObj = children.FirstOrDefault(c =>
                                                     c is PsbDictionary d && d.ContainsKey("label") && d["label"] is PsbString s &&
                                                     s.Value == current);
            }

            if (pos == path.Length - 1 || pos < 0)
            {
                return(currentObj);
            }

            if (currentObj is IPsbCollection psbCol)
            {
                path = path.Substring(pos);
                return(psbCol.FindByMmoPath(path));
            }

            return(psbObj[path]);
        }
Example #2
0
        private void Travel(IPsbCollection collection, Dictionary <string, List <string> > iconInfo)
        {
            //TODO: recover icon names
            if (collection is PsbDictionary dic)
            {
                //mask+=1
                //add ox=0, oy=0 //explain: the last bit of mask (00...01) is whether to use ox & oy. if use, last bit of mask is 1
                //change src
                if (dic.ContainsKey("mask") && dic.GetName() == "content")
                {
                    if (dic["src"] is PsbString s)
                    {
                        //"blank" ("icon" : "32:32:16:16") -> "blank/32:32:16:16"
                        if (s.Value == "blank")
                        {
                            var size = dic["icon"].ToString();
                            dic["src"] = new PsbString($"blank/{size}");
                        }
                        //"tex" ("icon" : "0001") -> "src/tex/0001"
                        else if (iconInfo.ContainsKey(s))
                        {
                            var iconName = dic["icon"].ToString();
                            dic["src"] = new PsbString($"src/{s}/{iconName}");
                        }
                        //"ex_body_a" ("icon" : "差分A") -> "motion/ex_body_a/差分A"
                        else
                        {
                            var iconName = dic["icon"].ToString();
                            dic["src"] = new PsbString($"motion/{s}/{iconName}");
                        }
                    }

                    var num = (PsbNumber)dic["mask"];
                    num.AsInt |= 1;
                    //num.IntValue = num.IntValue + 1;
                    //add src = layout || src = shape/point (0)
                    if (num.IntValue == 1 || num.IntValue == 3 || num.IntValue == 19)
                    {
                        if (!dic.ContainsKey("src"))
                        {
                            bool isLayout = true;
                            //content -> {} -> [] -> {}
                            if (dic.Parent.Parent.Parent is PsbDictionary childrenArrayDic)
                            {
                                if (childrenArrayDic.ContainsKey("shape"))
                                {
                                    string shape = ((PsbNumber)childrenArrayDic["shape"]).ToShapeString();

                                    dic.Add("src", new PsbString($"shape/{shape}"));
                                    isLayout = false;
                                }
                            }

                            if (isLayout)
                            {
                                dic.Add("src", new PsbString("layout"));
                            }
                        }
                    }

                    if (!dic.ContainsKey("ox"))
                    {
                        dic.Add("ox", PsbNumber.Zero);
                    }

                    if (!dic.ContainsKey("oy"))
                    {
                        dic.Add("oy", PsbNumber.Zero);
                    }
                }

                foreach (var child in dic.Values)
                {
                    if (child is IPsbCollection childCol)
                    {
                        Travel(childCol, iconInfo);
                    }
                }
            }

            if (collection is PsbList col)
            {
                foreach (var child in col)
                {
                    if (child is IPsbCollection childCol)
                    {
                        Travel(childCol, iconInfo);
                    }
                }
            }
        }
Example #3
0
 private void Travel(IPsbCollection collection, Dictionary <string, (string Tex, string IconName)> iconInfos)
Example #4
0
        private void Travel(IPsbCollection collection, Dictionary <string, List <string> > iconInfo)
        {
            //TODO: recover icon names
            if (collection is PsbDictionary dic)
            {
                //mask+=1
                //add ox=0, oy=0
                //change src
                if (dic.ContainsKey("mask") && dic.GetName() == "content")
                {
                    if (dic["src"] is PsbString s)
                    {
                        //"blank" ("icon" : "32:32:16:16") -> "blank/32:32:16:16"
                        if (s.Value == "blank")
                        {
                            var size = dic["icon"].ToString();
                            dic["src"] = new PsbString($"blank/{size}");
                        }
                        //"tex" ("icon" : "0001") -> "src/tex/0001"
                        else if (iconInfo.ContainsKey(s))
                        {
                            var iconName = dic["icon"].ToString();
                            dic["src"] = new PsbString($"src/{s}/{iconName}");
                        }
                        //"ex_body_a" ("icon" : "差分A") -> "motion/ex_body_a/差分A"
                        else
                        {
                            var iconName = dic["icon"].ToString();
                            dic["src"] = new PsbString($"motion/{s}/{iconName}");
                        }
                    }

                    var num = (PsbNumber)dic["mask"];
                    num.IntValue = num.IntValue + 1;
                    //add src = layout || src = shape/point (0)
                    if (num.IntValue == 1 || num.IntValue == 3 || num.IntValue == 19)
                    {
                        if (!dic.ContainsKey("src"))
                        {
                            bool isLayout = true;
                            //content -> {} -> [] -> {}
                            if (dic.Parent.Parent.Parent is PsbDictionary childrenArrayDic)
                            {
                                if (childrenArrayDic.ContainsKey("shape"))
                                {
                                    string shape;
                                    switch (((PsbNumber)childrenArrayDic["shape"]).IntValue)
                                    {
                                    case 0:     //We only know 0 = point
                                    default:
                                        shape = "point";
                                        break;
                                    }
                                    dic.Add("src", new PsbString($"shape/{shape}"));
                                    isLayout = false;
                                }
                            }
                            if (isLayout)
                            {
                                dic.Add("src", new PsbString("layout"));
                            }
                        }
                    }
                    if (!dic.ContainsKey("ox"))
                    {
                        dic.Add("ox", new PsbNumber(0));
                    }
                    if (!dic.ContainsKey("oy"))
                    {
                        dic.Add("oy", new PsbNumber(0));
                    }
                }

                foreach (var child in dic.Values)
                {
                    if (child is IPsbCollection childCol)
                    {
                        Travel(childCol, iconInfo);
                    }
                }
            }
            if (collection is PsbCollection col)
            {
                foreach (var child in col)
                {
                    if (child is IPsbCollection childCol)
                    {
                        Travel(childCol, iconInfo);
                    }
                }
            }
        }