Skip to content

Commit

Permalink
Merge pull request #581 from coloursofnoise/deprecate-classext
Browse files Browse the repository at this point in the history
Deprecate __Ext classe members
  • Loading branch information
maddie480 authored Oct 14, 2023
2 parents a5a3640 + 151687b commit e513d42
Show file tree
Hide file tree
Showing 82 changed files with 544 additions and 492 deletions.
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Contributions are very welcome and greatly appreciated! Make sure to join the [C
- [Adding Content](#adding-content)
- [Patching](#patching)
- [`patch_` classes](#patch_-classes)
- [`Ext` classes](#ext-classes)
- [MonoModRules](#monomodrules)
- [Miscellaneous](#miscellaneous)
- [Warnings](#warnings)
Expand Down Expand Up @@ -90,6 +91,19 @@ There are a few attributes that can be applied to members of the class with diff
- `[MonoModConstructor]` treat this method as a constructor - [why this is needed](https://github.com/MonoMod/MonoMod/issues/51#issuecomment-496115932).
- `[MonoModReplace]` replace this method entirely, do not generate an `orig_` method.

### `Ext` classes
Code mods were previously created with Everest as a git submodule, which meant that any additions from Everest in `patch_` classes were not available to those mods at build time.

The recommended practice has since been updated to build against a patched version of Celeste, making `Ext` classes relatively obsolete.

In most cases, **new `patch_` members should not be added to their associated `Ext` class, and new `Ext` classes should not be created.**

Exceptions are made when the `Ext` class contains significant additions that are not within the scope of the original class (ex: `TextMenuExt`).

Existing `Ext` classes will also be kept in the following cases:
- An associated `patch_` class member was not made public (ex: `patch_Audio.CheckFmod`)
- Useful extension methods are defined (ex: `AreaDataExt.ToKey`)

### MonoModRules
:information_source: **The recommended practices for MonoModRules have recently been changed as described in [this PR](https://github.com/EverestAPI/Everest/pull/351).**

Expand Down
14 changes: 7 additions & 7 deletions Celeste.Mod.mm/Mod/Core/CoreMapDataProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ public override void Reset() {
if (entity.Name == "checkpoint") {
if (CheckpointsAuto != null) {
MapMeta modeMeta = AreaData.GetModeMeta(AreaKey.Mode);
CheckpointData c = new CheckpointData(
patch_CheckpointData c = new patch_CheckpointData(
LevelName,
(AreaData.GetSID() + "_" + LevelName).DialogKeyify(),
(AreaData.SID + "_" + LevelName).DialogKeyify(),
MapMeta.GetInventory(entity.Attr("inventory")),
entity.Attr("dreaming") == "" ? modeMeta.Dreaming ?? AreaData.Dreaming : entity.AttrBool("dreaming"),
null
);
c.SetArea(AreaKey);
c.Area = AreaKey;
if (entity.Attr("coreMode") == "") {
c.CoreMode = modeMeta.CoreMode ?? AreaData.CoreMode;
} else {
Expand Down Expand Up @@ -221,8 +221,8 @@ public override void Reset() {
if (ParentAreaData.CassetteCheckpointIndex < 0)
ParentAreaData.CassetteCheckpointIndex = Checkpoint + (ParentMode.Checkpoints?.Length ?? 0);

MapData.SetDetectedCassette();
ParentMapData.SetDetectedCassette();
MapData.DetectedCassette = true;
ParentMapData.DetectedCassette = true;
} },

{ "entity:strawberry", entity => {
Expand Down Expand Up @@ -281,9 +281,9 @@ public override void End() {
ParentMode.Checkpoints = ParentMode.Checkpoints.Concat(CheckpointsAuto.Where(c => c != null)).ToArray();
}

MapData.SetDetectedStrawberriesIncludingUntracked(TotalStrawberriesIncludingUntracked);
MapData.DetectedStrawberriesIncludingUntracked = TotalStrawberriesIncludingUntracked;
if (MapData != ParentMapData)
ParentMapData.SetDetectedStrawberriesIncludingUntracked(ParentMapData.GetDetectedStrawberriesIncludingUntracked() + TotalStrawberriesIncludingUntracked);
ParentMapData.DetectedStrawberriesIncludingUntracked = ParentMapData.DetectedStrawberriesIncludingUntracked + TotalStrawberriesIncludingUntracked;
}
}
}
18 changes: 9 additions & 9 deletions Celeste.Mod.mm/Mod/Core/CoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public override void LoadContent(bool firstLoad) {
// Check if the current input GUI override is still valid. If so, apply it.
if (!string.IsNullOrEmpty(Settings.InputGui)) {
string inputGuiPath = $"controls/{Settings.InputGui}/";
if (GFX.Gui.GetTextures().Any(kvp => kvp.Key.StartsWith(inputGuiPath))) {
if (((patch_Atlas) GFX.Gui).Textures.Any(kvp => kvp.Key.StartsWith(inputGuiPath))) {
Input.OverrideInputPrefix = Settings.InputGui;
} else {
Settings.InputGui = "";
Expand Down Expand Up @@ -160,10 +160,10 @@ public void CreateMainMenuButtons(OuiMainMenu menu, List<MenuButton> buttons) {

// Find the options button and place our button below it.
index = buttons.FindIndex(_ => {
MainMenuSmallButton other = (_ as MainMenuSmallButton);
patch_MainMenuSmallButton other = (_ as patch_MainMenuSmallButton);
if (other == null)
return false;
return other.GetLabelName() == "menu_options" && other.GetIconName() == "menu/options";
return other.LabelName == "menu_options" && other.IconName == "menu/options";
});
if (index != -1)
index++;
Expand All @@ -178,11 +178,11 @@ public void CreateMainMenuButtons(OuiMainMenu menu, List<MenuButton> buttons) {
}));
}

public void CreatePauseMenuButtons(Level level, TextMenu menu, bool minimal) {
public void CreatePauseMenuButtons(Level level, patch_TextMenu menu, bool minimal) {
if (!Settings.ShowModOptionsInGame)
return;

List<TextMenu.Item> items = menu.GetItems();
List<TextMenu.Item> items = menu.Items;
int index;

// Find the options button and place our button below it.
Expand Down Expand Up @@ -215,8 +215,8 @@ public void CreatePauseMenuButtons(Level level, TextMenu menu, bool minimal) {
level.Pause(returnIndex, minimal, false);

// adjust the Mod Options menu position, in case it moved (pause menu entries added/removed after changing mod options).
TextMenu textMenu = level.Entities.GetToAdd().FirstOrDefault((Entity e) => e is TextMenu) as TextMenu;
TextMenu.Button modOptionsButton = textMenu?.GetItems().OfType<TextMenu.Button>()
patch_TextMenu textMenu = ((patch_EntityList) (object) level.Entities).ToAdd.FirstOrDefault((Entity e) => e is TextMenu) as patch_TextMenu;
TextMenu.Button modOptionsButton = textMenu?.Items.OfType<TextMenu.Button>()
.FirstOrDefault(button => button.Label == Dialog.Clean("menu_pause_modoptions"));
if (modOptionsButton != null) {
textMenu.Selection = textMenu.IndexOf(modOptionsButton);
Expand All @@ -236,14 +236,14 @@ public void CreatePauseMenuButtons(Level level, TextMenu menu, bool minimal) {
}));
}

public override void CreateModMenuSection(TextMenu menu, bool inGame, EventInstance snapshot) {
public override void CreateModMenuSection(patch_TextMenu menu, bool inGame, EventInstance snapshot) {
// Optional - reload mod settings when entering the mod options.
// LoadSettings();

base.CreateModMenuSection(menu, inGame, snapshot);

if (!inGame) {
List<TextMenu.Item> items = menu.GetItems();
List<TextMenu.Item> items = menu.Items;

// insert extra options before the "key config" options
menu.Insert(items.Count - 2, new TextMenu.Button(Dialog.Clean("modoptions_coremodule_oobe")).Pressed(() => {
Expand Down
2 changes: 1 addition & 1 deletion Celeste.Mod.mm/Mod/Core/CoreModuleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public void CreateInputGuiEntry(TextMenu menu, bool inGame) {
List<string> inputGuiPrefixes = new List<string> {
"" // Auto
};
foreach (KeyValuePair<string, MTexture> kvp in GFX.Gui.GetTextures()) {
foreach (KeyValuePair<string, MTexture> kvp in ((patch_Atlas) GFX.Gui).Textures) {
string path = kvp.Key;
if (!path.StartsWith("controls/"))
continue;
Expand Down
4 changes: 2 additions & 2 deletions Celeste.Mod.mm/Mod/Entities/CustomTextVignette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CustomTextVignette(Session session, MapMetaTextVignette meta, HiresSnow s
snow.Direction = meta.SnowDirection;
Add(renderer = new HudRenderer());
Add(this.snow = snow);
RendererList.UpdateLists();
((patch_RendererList) (object) RendererList).UpdateLists();

initialDelay = meta.InitialDelay;
finalDelay = meta.FinalDelay;
Expand Down Expand Up @@ -164,7 +164,7 @@ private void ReturnToMap() {
}
}).OnUpdate = (f) => textAlpha = Math.Min(textAlpha, 1f - f);

RendererList.UpdateLists();
((patch_RendererList) (object) RendererList).UpdateLists();
RendererList.MoveToFront(snow);
}

Expand Down
2 changes: 1 addition & 1 deletion Celeste.Mod.mm/Mod/Everest/Emoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static void Auto() {
return;
Initialized = true;

foreach (KeyValuePair<string, MTexture> kvp in GFX.Gui.GetTextures())
foreach (KeyValuePair<string, MTexture> kvp in ((patch_Atlas) GFX.Gui).Textures)
if (kvp.Key.StartsWith("emoji/"))
Register(kvp.Key.Substring(6), kvp.Value);

Expand Down
10 changes: 5 additions & 5 deletions Celeste.Mod.mm/Mod/Everest/Everest.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ private static void RecrawlMod(ModContent mod) {
public static void Update(ModAsset prev, ModAsset next) {
if (prev != null) {
foreach (object target in prev.Targets) {
if (target is MTexture mtex) {
if (target is patch_MTexture mtex) {
AssetReloadHelper.Do($"{Dialog.Clean("ASSETRELOADHELPER_UNLOADINGTEXTURE")} {Path.GetFileName(prev.PathVirtual)}", () => {
mtex.UndoOverride(prev);
});
Expand Down Expand Up @@ -1013,11 +1013,11 @@ public static void ProcessUpdate(object asset, ModAsset mapping, bool load) {
if (asset == null || mapping == null)
return;

if (asset is Atlas atlas) {
if (asset is patch_Atlas atlas) {
string reloadingText = Dialog.Language == null ? "" : Dialog.Clean(mapping.Children.Count == 0 ? "ASSETRELOADHELPER_RELOADINGTEXTURE" : "ASSETRELOADHELPER_RELOADINGTEXTURES");
AssetReloadHelper.Do(load, $"{reloadingText} {Path.GetFileName(mapping.PathVirtual)}", () => {
atlas.ResetCaches();
(atlas as patch_Atlas).Ingest(mapping);
atlas.Ingest(mapping);
});

// if the atlas is (or contains) an emoji, register it.
Expand Down Expand Up @@ -1153,7 +1153,7 @@ public static void Dump(string assetNameFull, object asset) {
}
/**/

} else if (asset is Atlas atlas) {
} else if (asset is patch_Atlas atlas) {

/*
for (int i = 0; i < atlas.Sources.Count; i++) {
Expand All @@ -1171,7 +1171,7 @@ public static void Dump(string assetNameFull, object asset) {
}
*/

Dictionary<string, MTexture> textures = atlas.GetTextures();
Dictionary<string, MTexture> textures = atlas.Textures;
foreach (KeyValuePair<string, MTexture> kvp in textures) {
string name = kvp.Key;
MTexture source = kvp.Value;
Expand Down
4 changes: 2 additions & 2 deletions Celeste.Mod.mm/Mod/Everest/Everest.DebugRC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public static void Write(HttpListenerContext c, string str) {
return;
}

AreaData area = AreaDataExt.Get(sid);
AreaData area = patch_AreaData.Get(sid);
if (area == null) {
c.Response.StatusCode = (int) HttpStatusCode.BadRequest;
Write(c, $"ERROR: Chapter not found: {sid}");
Expand Down Expand Up @@ -484,7 +484,7 @@ public static void Write(HttpListenerContext c, string str) {
return;
}

AreaData area = AreaDataExt.Get(sid);
patch_AreaData area = patch_AreaData.Get(sid);
if (area == null) {
c.Response.StatusCode = (int) HttpStatusCode.BadRequest;
Write(c, $"ERROR: Chapter not found: {sid}");
Expand Down
10 changes: 5 additions & 5 deletions Celeste.Mod.mm/Mod/Everest/Everest.DiscordSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal void UpdatePresence(Session session = null) {
}
} else {
Language english = Dialog.Languages["english"];
AreaData area = AreaData.Get(session);
patch_AreaData area = patch_AreaData.Get(session);

// the displayed info if "show map" was disabled: just "Playing a map"
string mapName = "a map";
Expand All @@ -197,7 +197,7 @@ internal void UpdatePresence(Session session = null) {
}

if (!IsOnlyMapInLevelSet(area)) {
fullName = FilterEmojiFrom(area.GetLevelSet().DialogCleanOrNull(english) ?? area.GetLevelSet())
fullName = FilterEmojiFrom(area.LevelSet.DialogCleanOrNull(english) ?? area.LevelSet)
+ " | " + (session.Area.ChapterIndex >= 0 ? "Chapter " + session.Area.ChapterIndex + " - " : "") + mapName;
} else {
fullName = mapName;
Expand Down Expand Up @@ -241,9 +241,9 @@ private string FilterEmojiFrom(string s) {
return Regex.Replace(Emoji.Apply(s), "[" + Emoji.Start + "-" + Emoji.End + "]", "").Trim();
}

private bool IsOnlyMapInLevelSet(AreaData area) {
foreach (AreaData otherArea in AreaData.Areas) {
if (area.GetLevelSet() == otherArea.GetLevelSet() && area.GetSID() != otherArea.GetSID()) {
private bool IsOnlyMapInLevelSet(patch_AreaData area) {
foreach (patch_AreaData otherArea in AreaData.Areas) {
if (area.LevelSet == otherArea.LevelSet && area.SID != otherArea.SID) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Celeste.Mod.mm/Mod/Everest/Everest.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ internal static void Pause(_Level level, int startIndex, bool minimal, bool quic
public static event UnpauseHandler OnUnpause;
internal static void Unpause(_Level level) => OnUnpause?.Invoke(level);

public delegate void CreatePauseMenuButtonsHandler(_Level level, TextMenu menu, bool minimal);
public delegate void CreatePauseMenuButtonsHandler(_Level level, patch_TextMenu menu, bool minimal);
/// <summary>
/// Called when the Level's pause menu is created.
/// </summary>
public static event CreatePauseMenuButtonsHandler OnCreatePauseMenuButtons;
internal static void CreatePauseMenuButtons(_Level level, TextMenu menu, bool minimal)
internal static void CreatePauseMenuButtons(_Level level, patch_TextMenu menu, bool minimal)
=> OnCreatePauseMenuButtons?.Invoke(level, menu, minimal);

public delegate void TransitionToHandler(_Level level, LevelData next, Vector2 direction);
Expand Down
8 changes: 4 additions & 4 deletions Celeste.Mod.mm/Mod/Everest/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static Vector2 ToVector2(this Point p) {
/// <param name="containingMenu">The menu containing the TextMenu.Item option.</param>
/// <param name="needsRelaunch">This method does nothing if this is set to false.</param>
/// <returns>The passed option.</returns>
public static TextMenu.Item NeedsRelaunch(this TextMenu.Item option, TextMenu containingMenu, bool needsRelaunch = true) {
public static TextMenu.Item NeedsRelaunch(this TextMenu.Item option, patch_TextMenu containingMenu, bool needsRelaunch = true) {
if (!needsRelaunch)
return option;

Expand All @@ -207,7 +207,7 @@ public static TextMenu.Item NeedsRelaunch(this TextMenu.Item option, TextMenu co
HeightExtra = 0f
};

List<TextMenu.Item> items = containingMenu.GetItems();
List<TextMenu.Item> items = containingMenu.Items;
if (items.Contains(option)) {
// insert the text after the option that needs relaunch.
containingMenu.Insert(items.IndexOf(option) + 1, needsRelaunchText);
Expand All @@ -232,14 +232,14 @@ public static TextMenu.Item NeedsRelaunch(this TextMenu.Item option, TextMenu co
/// <param name="containingMenu">The menu containing the TextMenu.Item option.</param>
/// <param name="description"></param>
/// <returns>The passed option.</returns>
public static TextMenu.Item AddDescription(this TextMenu.Item option, TextMenu containingMenu, string description) {
public static TextMenu.Item AddDescription(this TextMenu.Item option, patch_TextMenu containingMenu, string description) {
// build the description menu entry
TextMenuExt.EaseInSubHeaderExt descriptionText = new TextMenuExt.EaseInSubHeaderExt(description, false, containingMenu) {
TextColor = Color.Gray,
HeightExtra = 0f
};

List<TextMenu.Item> items = containingMenu.GetItems();
List<TextMenu.Item> items = containingMenu.Items;
if (items.Contains(option)) {
// insert the description after the option.
containingMenu.Insert(items.IndexOf(option) + 1, descriptionText);
Expand Down
4 changes: 2 additions & 2 deletions Celeste.Mod.mm/Mod/Helpers/AssetReloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static void ReloadAllMaps() {
SaveData saveData = SaveData.Instance;

// ChapterSelect only updates the ID.
string lastAreaSID = saveData == null ? null : (AreaData.Get(saveData.LastArea.ID)?.ToKey().GetSID() ?? AreaKey.Default.GetSID());
string lastAreaSID = saveData == null ? null : (patch_AreaData.Get(saveData.LastArea.ID)?.ToKey().GetSID() ?? AreaKey.Default.GetSID());
// Note: SaveData.Instance.LastArea is reset by AreaData.Interlude_Safe -> SaveData.LevelSetStats realizing that AreaOffset == -1
// Store the "resolved" last selected area in a local variable, then re-set it after reloading.

Expand All @@ -192,7 +192,7 @@ public static void ReloadAllMaps() {

// Fake a save data reload to resync the save data to the new area list.
if (saveData != null) {
AreaData lastArea = AreaDataExt.Get(lastAreaSID);
patch_AreaData lastArea = patch_AreaData.Get(lastAreaSID);
saveData.LastArea = lastArea?.ToKey() ?? AreaKey.Default;
saveData.BeforeSave();
saveData.AfterInitialize();
Expand Down
Loading

0 comments on commit e513d42

Please sign in to comment.