public IReadOnlyList <TItem> GetOrAdd(TKey key, Func <TKey, IEnumerable <TItem> > getFunc)
 {
     int index = Primary.GetOrAdd(key, k =>
     {
         var rawList = getFunc(k);
         lock (Primary)
         {
             int[] itemListByIndex = rawList.Select(item =>
             {
                 if (!ItemDict.TryGetValue(item, out int itemIndex))
                 {
                     itemIndex = ItemList.Count;
                     ItemList.Add(item);
                     ItemDict[item] = itemIndex;
                 }
                 return(itemIndex);
             }).ToArray();
             var intArray = new IntArray(itemListByIndex);
             if (!ListDict.TryGetValue(intArray, out int listIndex))
             {
                 lock (ListList)
                 {
                     listIndex = ListList.Count;
                     ListList.Add(itemListByIndex.Select(ii => ItemList[ii]).ToArray());
                 }
                 ListDict[intArray] = listIndex;
             }
             return(listIndex);
         }
Example #2
0
    void Start()
    {
#if INIT_CRYPTO
        Crypto.Init("#:CP$-/Tk:d5-exf", "H:CNA+3ZaLLUJwpPcHC@2dV3XfhrUGN-");
#endif
        // ロード
        Number = CryptoPlayerPrefs.GetInt("Number");
        Value  = CryptoPlayerPrefs.GetFloat("Value");
        Name   = CryptoPlayerPrefs.GetString("Name");
        Items  = CryptoPlayerPrefs.GetObject <ItemDict> ("Items");
        Debug.Log($"loaded... Number = {Number}, Value = {Value}, Name = {Name}, Items = {Items}");

        // 初期化
        Number = 4096;
        Value  = 1.41421356f;
        Name   = "tetr4lab.";
        Items  = new ItemDict(new string [] { "a", "b", "c", "d", "e", "f" });         // 生成

        // セーブ
        CryptoPlayerPrefs.SetInt("Number", Number);
        CryptoPlayerPrefs.SetFloat("Value", Value);
        CryptoPlayerPrefs.SetString("Name", Name);
        CryptoPlayerPrefs.SetObject <ItemDict> ("Items", Items);
        Debug.Log($"saved... Number = {Number}, Value = {Value}, Name = {Name}, Items = {Items}");
    }
        public void Add(ItemDict <TKey, TValue> item)
        {
            int hashCode = GetHash(item.Key);

            if (Keys.Contains(item.Key))
            {
                return;
            }

            if (Items[hashCode] == null)
            {
                Keys.Add(item.Key);
                Items[hashCode] = item;
            }
            else
            {
                bool IsPlaced = false;

                for (int i = 0; i < Size; i++)
                {
                    if (Items[i] == null)
                    {
                        Keys.Add(item.Key);
                        Items[i] = item;
                        IsPlaced = true;
                        break;
                    }

                    if (Items[i].Key.Equals(item.Key))
                    {
                        return;
                    }
                }

                if (!IsPlaced)
                {
                    for (int i = 0; i < hashCode; i++)
                    {
                        if (Items[i] == null)
                        {
                            Keys.Add(item.Key);
                            Items[i] = item;
                            IsPlaced = true;
                            break;
                        }

                        if (Items[i].Key.Equals(item.Key))
                        {
                            return;
                        }
                    }

                    if (!IsPlaced)
                    {
                        throw new Exception("Словарь полон!");
                    }
                }
            }
        }
        private void ItemDictTypes_SelectionChangedEvent(int oldSelection, int newSelection)
        {
            ItemDict.Clear();
            ItemDictVM <object> itdvm = new ItemDictVM <object>(ParentVM, ItemDictTypes.SelectedKey);

            itdvm.PropertyChanged += Itdvm_PropertyChanged;
            ItemDict.Add(itdvm);
        }
Example #5
0
        public static bool SetItemKeys(HttpSessionStateBase Session, List <string> theKeys, string from)
        {
            Dictionary <string, string> ItemDict = ReturnItemKeys(Session);

            if (ItemDict == null)
            {
                ItemDict = new Dictionary <string, string>();
            }

            foreach (string key in theKeys)
            {
                string ItemKey      = Regex.Split(key, ":")[0];
                string ItemKeyValue = Regex.Split(key, ":")[1];


                if (from == "A")
                {
                    if (ItemDict.ContainsKey("A:" + ItemKey))
                    {
                        ItemDict["A:" + ItemKey] = ItemKeyValue;
                    }
                    else
                    {
                        if (ItemDict.ContainsKey("I:" + ItemKey))
                        {
                            ItemDict.Add("A:" + ItemKey, ItemKeyValue);
                            ItemDict.Remove("I:" + ItemKey);
                        }
                        else
                        {
                            ItemDict.Add("A:" + ItemKey, ItemKeyValue);
                        }
                    }
                }
                else
                {
                    if (ItemDict.ContainsKey("I:" + ItemKey))
                    {
                        ItemDict["I:" + ItemKey] = ItemKeyValue;
                    }
                    else
                    {
                        if (ItemDict.ContainsKey("A:" + ItemKey))
                        {
                        }
                        else
                        {
                            ItemDict.Add("I:" + ItemKey, ItemKeyValue);
                        }
                    }
                }
            }

            StoreItemKeys(ItemDict, Session);
            return(true);
        }
Example #6
0
        public static bool SetItemKey(HttpSessionStateBase Session, string ItemKey, string ItemKeyValue, string from)
        {
            Dictionary <string, string> ItemDict = ReturnItemKeys(Session);

            if (ItemDict == null)
            {
                ItemDict = new Dictionary <string, string>();
            }
            if (from == "A")
            {
                if (ItemDict.ContainsKey("A:" + ItemKey))
                {
                    ItemDict["A:" + ItemKey] = ItemKeyValue;
                }
                else
                {
                    if (ItemDict.ContainsKey("I:" + ItemKey))
                    {
                        ItemDict.Add("A:" + ItemKey, ItemKeyValue);
                        ItemDict.Remove("I:" + ItemKey);
                    }
                    else
                    {
                        ItemDict.Add("A:" + ItemKey, ItemKeyValue);
                    }
                }
            }
            else
            {
                if (ItemDict.ContainsKey("I:" + ItemKey))
                {
                    ItemDict["I:" + ItemKey] = ItemKeyValue;
                }
                else
                {
                    if (ItemDict.ContainsKey("A:" + ItemKey))
                    {
                    }
                    else
                    {
                        ItemDict.Add("I:" + ItemKey, ItemKeyValue);
                    }
                }
            }

            StoreItemKeys(ItemDict, Session);
            return(true);
        }
        private void Itdvm_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            foreach (var item in ItemDict.ToList())
            {
                if (string.IsNullOrWhiteSpace(item.Formula) && ItemDict.IndexOf(item) < ItemDict.Count - 1)
                {
                    ItemDict.Remove(item);
                }
            }

            if (!string.IsNullOrWhiteSpace(ItemDict.Last().Formula))
            {
                ItemDictVM <object> itdvm = new ItemDictVM <object>(ParentVM, ItemDictTypes.SelectedKey);
                itdvm.PropertyChanged += Itdvm_PropertyChanged;
                ItemDict.Add(itdvm);
            }
        }
Example #8
0
    public void LoadEquipment(EquipmentData data)
    {
        if (data == null)
        {
            return;
        }

        isLoading = true;
        for (int i = 0; i < data.equipments.Count; i++)
        {
            EquipmentConfig config    = ItemDict.GetItem(data.equipments[i]) as EquipmentConfig;
            Equipment       equipment = config.Create() as Equipment;
            equipment.SetStatModValueFromSave(data.equipmentStats[i]);
            equipment.Use();
        }

        isLoading = false;
    }
Example #9
0
    /// <summary>初期実行</summary>
    void Start()
    {
        // 初期化
#if False
        // キーを任意に定める場合
        var Key = new byte [32];              // キーは32バイト
        (new System.Random()).NextBytes(Key); // 乱数で埋める (例)
        Crypto.Init(Key);
#else
        // キーを自動生成する場合
        var Key = Crypto.Init();
#endif

        // セーブ用データ
        var number = 4096;
        var value  = 1.41421356f;
        var name   = "tetr4lab.";
        var items  = new ItemDict(new string [] { "a", "b", "c", "d", "e", "f" });         // 生成

        // セーブ
        CryptoPlayerPrefs.SetInt("Number", number);
        CryptoPlayerPrefs.SetFloat("Value", value);
        CryptoPlayerPrefs.SetString("Name", name);
        CryptoPlayerPrefs.SetObject <ItemDict> ("Items", items);
        Debug.Log($"saved... Number = {number}, Value = {value}, Name = {name}, Items = {items}");

        // ここでアプリが終了し、次回起動後に再初期化されたものとする
        Crypto.Init(Key);

        // ロード
        number = CryptoPlayerPrefs.GetInt("Number");
        value  = CryptoPlayerPrefs.GetFloat("Value");
        name   = CryptoPlayerPrefs.GetString("Name");
        items  = CryptoPlayerPrefs.GetObject <ItemDict> ("Items");
        Debug.Log($"loaded... Number = {number}, Value = {value}, Name = {name}, Items = {items}");

        var missingNumber = CryptoPlayerPrefs.GetInt("MissingNumber");
        var missingValue  = CryptoPlayerPrefs.GetFloat("MissingValue");
        var missingName   = CryptoPlayerPrefs.GetString("MissingName");
        var missingItems  = CryptoPlayerPrefs.GetObject <ItemDict> ("MissingItems");
        Debug.Log($"missing... Number = {missingNumber}, Value = {missingValue}, Name = {missingName ?? "NULL"}, Items = {missingItems?.ToString () ?? "NULL"}");
    }
Example #10
0
        /** retreive the branches of a particular path, at a particular version
         *
         *  @param vcs      version control server
         *  @param srcPath  the path to find branches of
         *  @param ver      version of the path
         */
        public static ItemDict GetBranches(VersionControlServer vcs,
                                           string srcPath, VersionSpec ver)
        {
            ItemDict tree = new ItemDict();

            ItemSpec itm = new ItemSpec(srcPath, RecursionType.None);

            BranchHistoryTreeItem[][] branches =
                vcs.GetBranchHistory(new ItemSpec[] { itm }, ver);

            for (int i = 0; i < branches.Length; ++i)
            {
                for (int j = 0; j < branches[i].Length; ++j)
                {
                    _walk_tree(branches[i][j], tree);
                }
            }

            return(tree);
        }
Example #11
0
    public void LoadInventory(InventoryData data)
    {
        if (data == null)
        {
            return;
        }

        credits = data.credits;

        for (int i = 0; i < data.playerInventory.Count; i++)
        {
            LootConfig config = ItemDict.GetItem(data.playerInventory[i]);
            Loot       loot   = config.Create();

            playerInventory.Add(loot);
            if (loot.GetLootType() == LootType.Equipment)
            {
                Equipment equipment = (Equipment)loot;
                equipment.SetStatModValueFromSave(data.playerInventoryStats[i]);
            }
        }
    }
Example #12
0
        private static void _walk_tree(BranchHistoryTreeItem item, ItemDict tree)
        {
            /* bail early. */
            if (item == null)
            {
                return;
            }

            if (item.Relative != null &&
                item.Relative.BranchToItem != null)
            {
                Item tmp = item.Relative.BranchToItem;
                if (tree.find(tmp.ItemId) == tree.end())
                {
                    tree.insert(tmp.ItemId, tmp);
                }

                foreach (BranchHistoryTreeItem ti in item.Children)
                {
                    _walk_tree(ti, tree);
                }
            }
        }
Example #13
0
        public override string[] branches()
        {
            string[]   bs          = null;
            BranchCont brs         = new BranchCont();
            ItemDict   branchItems =
                megahistory.SCMUtils.GetBranches(_vcs,
                                                 "$/IGT_0803/main/EGS/", VersionSpec.Latest);

            /* throw the tfs branches into the branch container. */
            for (ItemDict.iterator it = branchItems.begin();
                 it != branchItems.end();
                 ++it)
            {
                string full_branch      = it.value().ServerItem + "/";
                BranchCont.iterator bit = brs.find(full_branch);
                if (bit == brs.end())
                {
                    brs.insert(full_branch);
                }
            }

            if (_cache.BranchNames.Any())
            {
                bs = _cache.BranchNames.ToArray();

                foreach (string str in bs)
                {
                    BranchCont.iterator bit = brs.find(str);
                    if (bit == brs.end())
                    {
                        brs.insert(str);
                    }
                    else
                    {
                        if (bit.item() != str)
                        {
                            /* well shit. tfs screwed up.
                             * correct tfs.
                             */
                            string tmp = bit.item();

                            bit = null;
                            /* this call will invalidate the iterator. */
                            brs.remove(tmp);
                            brs.insert(str);
                        }
                    }
                }
            }

            if (brs.size() > 0)
            {
                bs = new string[brs.size()];
                int i = 0;
                foreach (string str in brs)
                {
                    bs[i] = str;
                    ++i;
                }
            }
            else
            {
                /* this code should never run. */
                bs = TFSDB.DefaultBranches();
            }

            return(bs);
        }