Exemplo n.º 1
0
        internal static void Pull(ModdedSaveData data)
        {
            Clear();
            foreach (var mod in data.segments)
            {
                Debug.Log($"mod {mod.modid} has {mod.extendedData.Count} extended actor datas");
                foreach (var extendedDataTree in mod.extendedData)
                {
                    switch (extendedDataTree.idType)
                    {
                    case ExtendedDataTree.IdentifierType.ACTOR:
                        var          identifier = DataIdentifier.GetActorIdentifier(extendedDataTree.longIdentifier);
                        PreparedData pdata;
                        if (!preparedData.TryGetValue(identifier, out pdata))
                        {
                            pdata = new PreparedData()
                            {
                                Data = new CompoundDataPiece("root"), SourceType = PreparedData.PreparationSource.SPAWN
                            };
                            preparedData[identifier] = pdata;
                        }
                        extendedDataTree.dataPiece.DataList.Do((x) => pdata.Data.GetCompoundPiece(mod.modid).DataList.Add(x));
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                var actualMod = SRModLoader.GetMod(mod.modid);
                if (actualMod == null)
                {
                    continue;
                }
                worldSaveData.Add(actualMod, mod.extendedWorldData);
                SaveRegistry.GetSaveInfo(actualMod).WorldDataPreLoad(mod.extendedWorldData);
            }
            foreach (var v in SRModLoader.GetMods())
            {
                if (!worldSaveData.ContainsKey(v))
                {
                    var newData = new CompoundDataPiece("root");
                    worldSaveData.Add(v, newData);
                    SaveRegistry.GetSaveInfo(v).WorldDataPreLoad(newData);
                }
            }
        }
 public new string evaluate(PreparedData prepared)
 {
     return(base.evaluate(prepared));
 }
        public void DrawData(PreparedData pd, MainForm mainForm)
        {
            ClearChart();
            Chart    chart1    = this.Chart;
            DateTime?localTime = pd.File?.MatchDate?.ToLocalTime();
            string   matchDate = "";

            if (localTime.HasValue)
            {
                matchDate  = localTime.Value.ToString(ViewModel.ChartTitleDateFormat);
                matchDate += " " + localTime.Value.GetTimeZoneAbbreviation();
            }

            chart1.ChartAreas[0].AxisY.Title     = "HP: 0 to 100";
            chart1.ChartAreas[0].AxisY.TitleFont = mainForm.DeriveFont(chart1.ChartAreas[0].AxisY.TitleFont, 0);

            chart1.ChartAreas[0].AxisX.Title     = "Elapsed time since start of match (in minutes).";
            chart1.ChartAreas[0].AxisX.TitleFont = mainForm.DeriveFont(chart1.ChartAreas[0].AxisX.TitleFont, 0);

            ISet <string>    squad  = pd.File?.Squad ?? new HashSet <string>();
            NormalizedRoster roster =
                pd.File?.NormalizedMatch?.Rosters?.FirstOrDefault(r => r.Players?.Any(p => squad.Contains(p?.Attributes?.Stats?.Name)) ?? false);

            chart1.Titles[0].Text = $"HP over time for one match -- {matchDate} -- Squad Rank: {roster?.Roster.Attributes.Stats.Rank}";
            chart1.Titles[0].Font = new Font(chart1.Titles[0].Font.FontFamily, 12, FontStyle.Bold);

            // Declare series first
            foreach (string playerName in pd.PlayerToEvents.Keys)
            {
                var series = chart1.Series.Add(playerName);
                series.Color       = mainForm.ViewModel.ColorForPlayer(playerName);
                series.BorderWidth = 3;
                series.ChartType   = SeriesChartType.Line;
                chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
                series.SmartLabelStyle.Enabled             = true;
                series.SmartLabelStyle.MovingDirection     = LabelAlignmentStyles.Center;
                series.LabelFormat = "#";
                series.SmartLabelStyle.IsOverlappedHidden = true;
                series.XValueType = ChartValueType.DateTime;
            }

            // Track player's last known HP so we can fill in a reasonable value at missing time intervals
            var lastHps = new Dictionary <string, float>();

            // Then add data
            DebugThreadWriteLine("About to render " + pd.File?.FileInfo.Name);
            DateTime t0 = pd.TimeToPlayerToEvents.Keys.FirstOrDefault().ToLocalTime();

            foreach (var kv in pd.TimeToPlayerToEvents)
            {
                TimeSpan eventTimeOffset = kv.Key.ToLocalTime().Subtract(t0);
                DateTime dt = new DateTime(eventTimeOffset.Ticks);
                var      timePlayerToEvents = kv.Value;
                foreach (string squadMember in pd.Squad)
                {
                    timePlayerToEvents.TryGetValue(squadMember, out var squadEvents);
                    if (squadEvents != null)
                    {
                        chart1.Series[squadMember].Points.AddXY(dt, squadEvents.First().character.health);
                        float minHp = squadEvents.Select(x => x.character.health).Min();
                        lastHps[squadMember] = minHp;
                    }
                    else
                    {
                        float lastHp = lastHps.GetValueOrDefault(squadMember, () => 100);
                        chart1.Series[squadMember].Points.AddXY(dt, lastHp);
                    }
                }
            }

            this.RecalcPointLabels();
        }