Exemple #1
0
        public static List <TradeableItem> AggregateResourcesIntoTradeableItems(ResourceSet Resources)
        {
            var aggregates = new Dictionary <String, TradeableItem>();

            foreach (var res in Resources.Enumerate())
            {
                if (aggregates.ContainsKey(res.DisplayName))
                {
                    aggregates[res.DisplayName].Resources.Add(res);
                }
                else
                {
                    aggregates.Add(res.DisplayName, new Gui.Widgets.TradeableItem {
                        Resources = new List <Resource> {
                            res
                        }, ResourceType = res.DisplayName, Prototype = res
                    });
                }
            }

            return(aggregates.Values.ToList());
        }
Exemple #2
0
        // Todo: Remove duplication with ResourceSet.GroupBy
        private List <AggregatedResource> AggregateByType()
        {
            var r = new Dictionary <String, AggregatedResource>();

            foreach (var res in Resources.Enumerate())
            {
                if (r.ContainsKey(res.DisplayName))
                {
                    r[res.DisplayName].Count += 1;
                }
                else
                {
                    r.Add(res.DisplayName, new AggregatedResource
                    {
                        Sample = res,
                        Count  = 1
                    });
                }
            }

            return(r.Values.ToList());
        }