public bool Remove(Thing item)
        {
            if (item is null)
            {
                return(false);
            }

            if (!ThingCache.TryGetValue(item.def, out Dictionary <Thing, float> things))
            {
                return(false);
            }

            if (!things.TryGetValue(item, out float weight))
            {
                return(false);
            }

            things.Remove(item);
            this.TotalWeight -= weight;
            this.Count--;

            RemoveFromNonFull(item);

            return(true);
        }
 public void Clear()
 {
     ThingCache.Clear();
     NonFullThings.Clear();
     TotalWeight = 0;
     Count       = 0;
 }
        private void AddToThingCache(Thing thing, float unitWeight)
        {
            if (ThingCache.TryGetValue(thing.def, out Dictionary <Thing, float> things))
            {
                things[thing] = thing.stackCount * unitWeight;
            }
            else
            {
                Dictionary <Thing, float> newCache = new Dictionary <Thing, float>
                {
                    [thing] = thing.stackCount * unitWeight
                };

                ThingCache[thing.def] = newCache;
            }
        }
示例#4
0
 public void SetUp()
 {
     thingService = A.Fake <IThingService>();
     thingCache   = new ThingCache(thingService);
 }