Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghosts in PICO-8 #151

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Ghosts in PICO-8 #151

wants to merge 23 commits into from

Conversation

balt-dev
Copy link
Contributor

@balt-dev balt-dev commented Jul 25, 2024

@balt-dev balt-dev marked this pull request as ready for review July 26, 2024 04:10
@balt-dev
Copy link
Contributor Author

I tested this as best I could using 3 instances of Celeste hooked up to a locally hosted server. Stress tests may be in order?

@balt-dev
Copy link
Contributor Author

Did a lot of refactoring per some advice on discord, there is no longer a server module needed!

@balt-dev
Copy link
Contributor Author

balt-dev commented Aug 2, 2024

oh you know what i totally forgot to test that before pushing. one second

@balt-dev
Copy link
Contributor Author

any updates on this?

@RedFlames
Copy link
Collaborator

Hey, really sorry about the lack of activity 😅

Personally been having some trouble with working on CNet stuff or what to prioritize, but I can probably take a more thorough look at this again over the weekend?

This is definitely a solid PR that is 90% where it should be, but I still see some areas I wanna go over.
Like some nullable-related stuff looks quite confusing to me, e.g. in the LevelIndex property... which besides that imho should be declared before the methods of the class as well 🤔
Wondering if the location SID should be "Celeste/PICO-8" since that would fit in with vanilla and make the change in player list code unnecessary.

Copy link
Collaborator

@RedFlames RedFlames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even know what exactly GitHub does when you "Finish" a Review, but I'm doing it :33:

using System.Reflection;

namespace Celeste.Mod.CelesteNet.Client.Components;
#nullable enable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure why Client is the only project that doesn't have nullable context enabled. We should look into if we can turn that on for the whole project and fix warnings, rather than just toggling it for this file alone imo.


CelesteNetPlayerListComponent.OnGetState += ModifyStateOfPicoPlayers;
CelesteNetMainComponent.OnSendState += ModifyStateInPico;
var client = Context?.Client;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the var and use the Client property of CelesteNetGameComponent?


CelesteNetPlayerListComponent.OnGetState -= ModifyStateOfPicoPlayers;
CelesteNetMainComponent.OnSendState -= ModifyStateInPico;
var client = Context?.Client;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same as line 65)

private void ModifyStateInPico(DataPlayerState state)
{
uint? id = state.Player?.ID;
if (id == null) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check state.Player == null, drop the local var and possibly combine the two conditional returns


Logger.Log(LogLevel.DBG, "PICO8-CNET", $"Modifying state!");

state.SID = $"PICO-8";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I already said I think it'd make sense to make this "Celeste/PICO-8", and since the constant shows up in multiple places, make it a member constant variable?

Comment on lines +203 to +205
var x = (float?) nodeData.Get("x") ?? float.NaN;
var y = (float?) nodeData.Get("y") ?? float.NaN;
var size = (float?) nodeData.Get("size") ?? float.NaN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use .Get<float>()? 🤔
Unsure why VS then tells me it wouldn't even return a float? but maybe that's nullable-context jank we gotta fix...

Comment on lines +374 to +377
if (_classic == null) {
Logger.Log(LogLevel.WRN, "PICO8-CNET", "Failed to retrieve Classic");
return null;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if _classic was null, InitData wouldn't have returned true and the previous conditional would've returned, right

@@ -492,7 +492,7 @@ private string GetOrderKey(DataPlayerInfo player) {
return "9";

if (Client?.Data?.TryGetBoundRef(player, out DataPlayerState state) == true && !string.IsNullOrEmpty(state?.SID))
return $"0 {(state.SID.StartsWith("Celeste/") ? "0" : "1") + state.SID + (int) state.Mode} {player.FullName}";
return $"0 {(state.SID.StartsWith("Celeste/") || state.SID == "PICO-8" ? "0" : "1") + state.SID + (int) state.Mode} {player.FullName}";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change would be avoided by using SID "Celeste/PICO-8"

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Celeste.Pico8;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are superfluous? The SceneAs vs. is not seems okay although idk about the { return; } instead of newline no-braces ;)

Comment on lines +21 to +55
public static void Print(string text, int x, int y) {
Print(text, x, y, PicoWhite);
}

public static void Print(string text, int x, int y, Color color) {
var initialX = x;
for (var i = 0; i < text.Length; i += char.IsSurrogatePair(text, i) ? 2 : 1) {
var codepoint = char.ConvertToUtf32(text, i);
if (codepoint == 0x0A) {
// Newline
x = initialX;
y += 5;
continue;
}
var sprite = CharacterSprite((uint) codepoint);

sprite.Draw(new Vector2(x, y), Vector2.Zero, color);
x += 4;
}
}
public static void PrintOutlinedCenter(string text, int x, int y) {
PrintOutlinedCenter(text, x, y, PicoWhite, PicoBlack);
}

public static void PrintOutlinedCenter(string text, int x, int y, Color inside, Color outside) {
Print(text, x - (text.Length / 2 * 4) - 1, y - 1, outside);
Print(text, x - (text.Length / 2 * 4) , y - 1, outside);
Print(text, x - (text.Length / 2 * 4) + 1, y - 1, outside);
Print(text, x - (text.Length / 2 * 4) - 1, y , outside);
Print(text, x - (text.Length / 2 * 4) + 1, y , outside);
Print(text, x - (text.Length / 2 * 4) - 1, y + 1, outside);
Print(text, x - (text.Length / 2 * 4) , y + 1, outside);
Print(text, x - (text.Length / 2 * 4) + 1, y + 1, outside);
Print(text, x - (text.Length / 2 * 4) , y , inside);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could give the Color parameters default values instead of the overloaded methods? 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants