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

Add an option for always showing items received while offline #221

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Archipelago.HollowKnight/Archipelago.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Archipelago.HollowKnight
{
public class Archipelago : Mod, IGlobalSettings<ConnectionDetails>, ILocalSettings<ConnectionDetails>
public class Archipelago : Mod, IGlobalSettings<ConnectionDetails>, ILocalSettings<ConnectionDetails>, IMenuMod
{
// Events support
public static event Action OnArchipelagoGameStarted;
Expand Down Expand Up @@ -297,8 +297,23 @@ public ConnectionDetails OnSaveGlobal()
{
ServerUrl = MenuSettings.ServerUrl,
ServerPort = MenuSettings.ServerPort,
SlotName = MenuSettings.SlotName
SlotName = MenuSettings.SlotName,
AlwaysShowItems = MenuSettings.AlwaysShowItems,
};
}

public bool ToggleButtonInsideMenu => false;
public List<IMenuMod.MenuEntry> GetMenuData(IMenuMod.MenuEntry? toggleButtonEntry)
{
return [
new IMenuMod.MenuEntry {
Name = "Show offline items",
Description = "Show items received while you were disconnected.",
Values = ["No", "Yes"],
Saver = opt => { MenuSettings.AlwaysShowItems = opt == 1; },
Loader = () => MenuSettings.AlwaysShowItems ? 1 : 0,
},
];
}
}
}
2 changes: 2 additions & 0 deletions Archipelago.HollowKnight/ConnectionDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public record ConnectionDetails

public string RoomSeed { get; set; }
public long Seed { get; set; }

public bool AlwaysShowItems { get; set; }
}
}
26 changes: 20 additions & 6 deletions Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ public async Task SendLocationsAsync(params long[] locationIds)
}
}

public void MarkLocationAsChecked(long locationId, bool silentGive)
public void MarkLocationAsChecked(long locationId, bool silentGive, bool silenceRecentItems = false)
{
// Called when marking a location as checked remotely (i.e. through ReceiveItem, etc.)
// This also grants items at said locations.
AbstractPlacement pmt;
bool hadNewlyObtainedItems = false;
bool hadUnobtainedItems = false;

Archipelago.Instance.LogDebug($"Marking location {locationId} as checked.");
Archipelago.Instance.LogDebug($"Marking location {locationId} as checked{(silentGive ? " silently" : "")}.");
if (!ArchipelagoPlacementTag.PlacementsByLocationId.TryGetValue(locationId, out pmt))
{
Archipelago.Instance.LogDebug($"Could not find a placement for location {locationId}");
Expand Down Expand Up @@ -136,6 +136,14 @@ public void MarkLocationAsChecked(long locationId, bool silentGive)
pmt.AddVisitFlag(VisitState.ObtainedAnyItem);

GiveInfo giveInfo = silentGive ? SilentGiveInfo : RemoteGiveInfo;

if (silenceRecentItems)
{
InteropTag recentItemsTag = item.AddTag<InteropTag>();
recentItemsTag.Message = "RecentItems";
recentItemsTag.Properties["IgnoreItem"] = true;
}

item.Give(pmt, giveInfo.Clone());
}

Expand Down Expand Up @@ -180,12 +188,18 @@ private async Task Synchronize()
NetworkItem seen = session.Items.DequeueItem();
Archipelago.Instance.LogDebug($"Fast-forwarding past already-obtained {session.Items.GetItemName(seen.Item)} at index {i}");
}
bool silentGive = !Archipelago.Instance.MenuSettings.AlwaysShowItems;
// receive from the server any items that are pending
while (ReceiveNextItem(true)) { }
// ensure any already-checked locations (co-op, restarting save) are marked cleared
while (ReceiveNextItem(silentGive)) { }
// ensure any already-checked locations (co-op, restarting save, other players collecting) are marked cleared
foreach (long location in session.Locations.AllLocationsChecked)
{
MarkLocationAsChecked(location, true);
// NOTE: this is intentionally always set to silently give during initial sync even when
// AlwaysShowItems is true because this shows the items that OTHER players have gotten
// FROM this world, which can SERIOUSLY lock up the item display if someone collects a
// lot of their items at once (usually via the !collect command). It also prevents these
// items from displaying in RecentItemsDisplay (if installed) for the same reason.
MarkLocationAsChecked(location, true, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this also hide your own received items from recent items? That seems wrong.

}
// send out any pending items that didn't get to the network from the previous session
long[] pendingLocations = deferredLocationChecks.ToArray();
Expand Down Expand Up @@ -229,7 +243,7 @@ private void ReceiveItem(NetworkItem netItem, bool silentGive)
{
string name = session.Items.GetItemName(netItem.Item);
Archipelago.Instance.LogDebug($"Receiving item ID {netItem.Item}. Name is {name}. " +
$"Slot is {netItem.Player}. Location is {netItem.Location}.");
$"Slot is {netItem.Player}. Location is {netItem.Location}. Silent is {silentGive}");

if (netItem.Player == Archipelago.Instance.Slot && netItem.Location > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ private static void StartOrResumeGame(bool newGame, MenuLabel errorLabel)
}
else
{
Archipelago.Instance.MenuSettings = Archipelago.Instance.ApSettings with { };
Archipelago.Instance.MenuSettings = Archipelago.Instance.ApSettings with {
AlwaysShowItems = Archipelago.Instance.MenuSettings.AlwaysShowItems
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be needed

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately it is. Without that change the save-specific ApSettings will override the MenuSettings whenever a save file is loaded, which causes the AlwaysShowItems setting to be overridden. If you have another solution I'm happy to hear it, but this was the simplest fix I was able to find.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yuck didn't think of that. Settings really need to be refactored but there is just not a way to do it that doesn't break anyone with an existing install

Copy link
Author

Choose a reason for hiding this comment

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

I'm sure it's possible to do while still being backwards-compatible, but it was a bigger change than I wanted to make in this PR, so I opted for the simpler solution. I'm happy to take a crack at that refactor if you'd prefer it done that way though.

};
}
try
{
Expand Down