public StructureProjectorModel(MyObjectBuilder_CubeGrid grid, MyObjectBuilder_Projector proj) : base(null) { var identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == proj.Owner); if (identity != null) { _ownerName = identity.DisplayName; } else { _ownerName = "Nobody"; } _gridName = grid.DisplayName; identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == proj.BuiltBy); if (identity != null) { _builderName = identity.DisplayName; } else { _builderName = "Nobody"; } _builderName = $"(by {_builderName})"; identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == grid.GetTopBuilderId()); if (identity != null) { _gridBuilderName = identity.DisplayName; } else { _gridBuilderName = "Nobody"; } _gridBuilderName = $"(by {_gridBuilderName})"; DisplayName = proj.GetBlockName(grid); _enabled = proj.Enabled && proj.ProjectedGrid != null; if (proj.ProjectedGrid == null) { return; } _blockStatistics = new BlockStatistics(proj.ProjectedGrid.CubeBlocks); BlockCount = proj.ProjectedGrid.CubeBlocks.Count; _blockCountStr = $"{proj.ProjectedGrid.CubeBlocks.Count} ({((decimal)proj.ProjectedGrid.CubeBlocks.Count / grid.CubeBlocks.Count * 100):F1}% of self)"; }
public StructureTimerModel(IEnumerable <Tuple <MyObjectBuilder_CubeGrid, MyObjectBuilder_CubeBlock> > blocks, MyObjectBuilder_CubeGrid grid, MyObjectBuilder_TimerBlock timer) : base(null) { var identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == timer.Owner); if (identity != null) { _ownerName = identity.DisplayName; } else { _ownerName = "Nobody"; } _gridName = grid.DisplayName; identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == timer.BuiltBy); if (identity != null) { _builderName = identity.DisplayName; } else { _builderName = "Nobody"; } _builderName = $"(by {_builderName})"; identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == grid.GetTopBuilderId()); if (identity != null) { _gridBuilderName = identity.DisplayName; } else { _gridBuilderName = "Nobody"; } _gridBuilderName = $"(by {_gridBuilderName})"; DisplayName = timer.GetBlockName(grid); _delay = timer.Delay / 1000; _enabled = timer.Enabled && timer.IsCountingDown; if (timer.Toolbar.Slots.Count > 0) { var toolbarItems = timer.Toolbar.Slots.OrderBy(s => s.Index).Select(s => s.Data).OfType <MyObjectBuilder_ToolbarItemTerminalBlock>(); _toolbarButtons = toolbarItems.Select(ti => $"{GetBlockName(blocks.SingleOrDefault(cb => cb.Item2.EntityId == ti.BlockEntityId))} - {ti._Action}"); _toolbarSummary = String.Join(" | ", _toolbarButtons); var selfRefSlots = timer.Toolbar.Slots.Select(s => s.Data).OfType <MyObjectBuilder_ToolbarItemTerminalBlock>().Where(s => s.BlockEntityId == timer.EntityId); if (selfRefSlots.Count() == 0) { _selfTriggerType = "None"; } else { if (selfRefSlots.Count(s => s._Action == "TriggerNow") > 0) { _selfTriggerType = "Trigger Now"; } else { if (selfRefSlots.Count(s => s._Action == "Start") > 0) { _selfTriggerType = "Start"; } else { _selfTriggerType = selfRefSlots.First()._Action; } } } var pbSlots = toolbarItems.Where(ti => ti._Action.StartsWith("Run")).Select(s => blocks.SingleOrDefault(cb => cb.Item2.EntityId == s.BlockEntityId)).Where(cb => cb?.Item2 is MyObjectBuilder_MyProgrammableBlock); _programmableBlocks = pbSlots.Select(pb => new Tuple <long, string>(pb.Item2.EntityId, GetBlockName(pb))); _pbNames = String.Join("\n", _programmableBlocks); _pbSourceCodePreview = String.Join("\n", pbSlots.Select(pb => { var prg = ((MyObjectBuilder_MyProgrammableBlock)pb.Item2).Program; return(prg?.Substring(0, Math.Min(prg.Length, 1000)).Replace('\n', ' ')); })); _pbSourceCodes = pbSlots.Select(pb => new Tuple <long, string>(pb.Item2.EntityId, ((MyObjectBuilder_MyProgrammableBlock)pb.Item2).Program)); } }