-
Notifications
You must be signed in to change notification settings - Fork 1
/
Extensions.cs
61 lines (55 loc) · 1.82 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Celeste;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections.Generic;
namespace MadelineParty {
static class Extensions {
public static T OrDefault<S, T>(this Dictionary<S, T> self, S key, T defaultValue) {
if(self.TryGetValue(key, out T value)) {
return value;
}
return defaultValue;
}
public static T OrDefault<S, T>(this Dictionary<S, object> self, S key, T defaultValue) {
if (self.TryGetValue(key, out object value)) {
return (T)value;
}
return defaultValue;
}
public static void Teleport(this Level self, string levelName, Vector2? spawnPoint = null) {
self.Teleport(levelName, () => spawnPoint);
}
public static void Teleport(this Level self, string levelName, Func<Vector2?> spawnPointFunc) {
Glitch.Value = 0f;
Engine.TimeRate = 1f;
Distort.Anxiety = 0f;
Distort.GameRate = 1f;
Audio.SetMusicParam("fade", 1f);
self.ParticlesBG.Clear();
self.Particles.Clear();
self.ParticlesFG.Clear();
TrailManager.Clear();
if(self.Tracker.GetEntity<Player>() is Player player) {
self.Remove(player);
}
self.UnloadLevel();
GC.Collect();
GC.WaitForPendingFinalizers();
self.Session.Level = levelName;
Vector2? spawnPoint = spawnPointFunc.Invoke();
if (spawnPoint == null) {
spawnPoint = self.GetSpawnPoint(new Vector2(self.Bounds.Left, self.Bounds.Top));
}
self.Session.RespawnPoint = spawnPoint;
self.LoadLevel(Player.IntroTypes.None);
self.strawberriesDisplay.DrawLerp = 0f;
WindController windController = self.Entities.FindFirst<WindController>();
if (windController != null) {
windController.SnapWind();
} else {
self.Wind = Vector2.Zero;
}
}
}
}