Skip to content

Commit

Permalink
Fix error when room is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Falconne committed Mar 2, 2020
1 parent d8d8c21 commit 9dcb677
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/HeatMap/HeatMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources.cs" />
<Compile Include="RoomTemperatureDisplayer.cs" />
<Compile Include="RoomWithLabelCell.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\mod-structure\About\About.xml">
Expand Down
4 changes: 2 additions & 2 deletions src/HeatMap/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.9.0")]
[assembly: AssemblyFileVersion("1.1.9.0")]
[assembly: AssemblyVersion("1.1.10.0")]
[assembly: AssemblyFileVersion("1.1.10.0")]



Expand Down
21 changes: 11 additions & 10 deletions src/HeatMap/RoomTemperatureDisplayer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;

namespace HeatMap
{
public class RoomTemperatureDisplayer
{
public List<RoomWithLabelCell> RoomsWithLabelCells { get; } = new List<RoomWithLabelCell>();
public List<IntVec3> LabelCells { get; } = new List<IntVec3>();

private int _nextUpdateTick;

Expand All @@ -24,7 +22,7 @@ public void Update(int updateDelay)
_lastSeenMap = Find.CurrentMap;

_nextUpdateTick = tick + updateDelay;
RoomsWithLabelCells.Clear();
LabelCells.Clear();

var map = Find.CurrentMap;
foreach (var room in map.regionGrid.allRooms)
Expand All @@ -33,7 +31,7 @@ public void Update(int updateDelay)
continue;

var cell = GetBestCellForRoom(room, map);
RoomsWithLabelCells.Add(new RoomWithLabelCell(room, cell));
LabelCells.Add(cell);
}
}

Expand Down Expand Up @@ -81,7 +79,7 @@ private static IntVec3 GetBestCellForRoom(Room room, Map map)

public void Reset()
{
RoomsWithLabelCells.Clear();
LabelCells.Clear();
_nextUpdateTick = 0;
}

Expand All @@ -90,18 +88,21 @@ public void OnGUI()
Text.Font = GameFont.Tiny;
var map = Find.CurrentMap;
CellRect currentViewRect = Find.CameraDriver.CurrentViewRect;
foreach (var roomWithLabelCell in RoomsWithLabelCells)
foreach (var cell in LabelCells)
{
var cell = roomWithLabelCell.Cell;
if (!currentViewRect.Contains(cell))
continue;

var room = cell.GetRoom(map, RegionType.Set_All);
if (room == null)
continue;

var panelLength = 20f;
var panelHeight = 20f;
var panelSize = new Vector2(panelLength, panelHeight);
var drawTopLeft = GenMapUI.LabelDrawPosFor(cell);
var labelRect = new Rect(drawTopLeft.x, drawTopLeft.y, panelSize.x, panelSize.y);
Widgets.Label(labelRect, roomWithLabelCell.Room.Temperature.ToStringTemperature("F0"));
Widgets.Label(labelRect, room.Temperature.ToStringTemperature("F0"));
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions src/HeatMap/RoomWithLabelCell.cs

This file was deleted.

0 comments on commit 9dcb677

Please sign in to comment.