Exemplo n.º 1
0
        public List <ImageHashData> LoadImageHashes(JsonParser.ObjectValue jsonOb)
        {
            List <ImageHashData> list = new List <ImageHashData>();

            string[] enumArr = Enum.GetNames(typeof(EImageHashType));
            foreach (var kvp in jsonOb.entries)
            {
                EImageHashType        groupType = (EImageHashType)Array.IndexOf(enumArr, kvp.Key);
                JsonParser.ArrayValue typeArr   = (JsonParser.ArrayValue)kvp.Value;

                foreach (JsonParser.Value value in typeArr.entries)
                {
                    JsonParser.ObjectValue jsonHashOb = (JsonParser.ObjectValue)value;
                    string idStr = jsonHashOb["id"];

                    bool hasIdNum   = int.TryParse(idStr, out int idNum);
                    bool needsIdNum = (groupType != EImageHashType.Rule);
                    if (hasIdNum != needsIdNum)
                    {
                        continue;
                    }

                    ImageHashData hashEntry = new ImageHashData()
                    {
                        type = groupType, isKnown = true
                    };
                    switch (groupType)
                    {
                    case EImageHashType.Rule:
                        hashEntry.ownerOb = ParseRule(idStr);
                        break;

                    case EImageHashType.CardImage:
                        hashEntry.ownerOb = TriadCardDB.Get().cards[idNum];
                        break;

                    default:
                        hashEntry.ownerOb = idNum;
                        break;
                    }

                    if (hashEntry.ownerOb != null)
                    {
                        string descHashTLSH = jsonHashOb["hashC", JsonParser.StringValue.Empty];
                        string descHashMd5  = jsonHashOb["hashB", JsonParser.StringValue.Empty];

                        hashEntry.LoadFromString(descHashTLSH, descHashMd5);
                        if (hashEntry.IsValid())
                        {
                            list.Add(hashEntry);
                        }
                    }
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        public bool Load()
        {
            hashes.Clear();

            modObjects.Clear();
            foreach (Type type in Assembly.GetAssembly(typeof(TriadGameModifier)).GetTypes())
            {
                if (type.IsSubclassOf(typeof(TriadGameModifier)))
                {
                    modObjects.Add((TriadGameModifier)Activator.CreateInstance(type));
                }
            }

            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(AssetManager.Get().GetAsset(DBPath));

                foreach (XmlNode testNode in xdoc.DocumentElement.ChildNodes)
                {
                    XmlElement    testElem  = (XmlElement)testNode;
                    ImageHashData hashEntry = LoadHashEntry(testElem);
                    if (hashEntry != null && hashEntry.IsValid())
                    {
                        hashes.Add(hashEntry);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Loading failed! Exception:" + ex);
            }

            Logger.WriteLine("Loaded hashes: " + hashes.Count);
            return(true);
        }