///<summary>Restores the light sources that were temporarily removed when UpdateBeforeOpacityChange was called. /// (UpdateBeforeOpacityChange MUST be called immediately before changing the opacity.)</summary> public void UpdateAfterOpacityChange() { if (!midOpacityUpdate) { throw new InvalidOperationException("This method can only be called to finish an opacity update"); } midOpacityUpdate = false; foreach (KeyValuePair <Point, int> pair in tempRemovedLights.GetAllKeyValuePairs()) { UpdateBrightnessWithinRadius(pair.Key, pair.Value, 1); } tempRemovedLights.Clear(); }
///<summary>Temporarily removes light sources around the given cell so that that cell's opacity can be changed. /// (Immediately after changing the opacity, UpdateAfterOpacityChange MUST be called.)</summary> public void UpdateBeforeOpacityChange(Point cell) { if (midOpacityUpdate) { throw new InvalidOperationException("Already in the middle of an opacity update"); } // (A pair of methods to update the opacity of multiple cells at once could also be useful here...) midOpacityUpdate = true; foreach (KeyValuePair <Point, int> pair in lightSources.GetAllKeyValuePairs()) { int dist = cell.ChebyshevDistanceFrom(pair.Key); if (pair.Value >= dist) { tempRemovedLights.Add(pair.Key, pair.Value); UpdateBrightnessWithinRadius(pair.Key, pair.Value, -1); } } }