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

Support multiple supercampaigns #459

Merged
merged 6 commits into from
May 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions client/Assets/Scenes/Overworld.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4510,7 +4510,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 5680396890292483277, guid: c36f69f305d3c4336a02acc5a4050f98, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_MethodName
value: ChangeToSceneWithDelay
value: ChangeToSuperCampaign
objectReference: {fileID: 0}
- target: {fileID: 5680396890292483277, guid: c36f69f305d3c4336a02acc5a4050f98, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
Expand All @@ -4526,7 +4526,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 5680396890292483277, guid: c36f69f305d3c4336a02acc5a4050f98, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Arguments.m_StringArgument
value: CampaignsMap
value: Main Campaign
objectReference: {fileID: 0}
- target: {fileID: 5680396890292483277, guid: c36f69f305d3c4336a02acc5a4050f98, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
Expand Down
20 changes: 11 additions & 9 deletions client/Assets/Scripts/BackendConnection/SocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,16 @@ private List<Unit> CreateUnitsFromData(IEnumerable<Protobuf.Messages.Unit> units
return createdUnits;
}

private List<Campaign> ParseCampaignsFromResponse(Protobuf.Messages.Campaigns campaignsData, List<Character> availableCharacters)
private List<Campaign> ParseCampaignsFromResponse(Protobuf.Messages.Campaigns campaignsData, string superCampaignName, List<Character> availableCharacters)
{
List<(string superCampaignId, string campaignId, string levelId)> userCampaignsProgress = GlobalUserData.Instance.User.campaignsProgresses;
List<(string superCampaignName, string campaignId, string levelId)> userCampaignsProgress = GlobalUserData.Instance.User.campaignsProgresses;
List<Campaign> campaigns = new List<Campaign>();
LevelProgress.Status campaignStatus = LevelProgress.Status.Completed;

// Currently looping through all the campaigns like they all belong to the same super campaign
foreach (Protobuf.Messages.Campaign campaignData in campaignsData.Campaigns_)
// Filter campaigns by supercampaign name
var superCampaignCampaigns = campaignsData.Campaigns_.Where(campaign => campaign.SuperCampaignName == superCampaignName).ToList();

foreach (Protobuf.Messages.Campaign campaignData in superCampaignCampaigns)
{
LevelProgress.Status levelStatus = LevelProgress.Status.Completed;
List<LevelData> levels = new List<LevelData>();
Expand Down Expand Up @@ -438,7 +440,7 @@ private void AwaitCampaignsProgressResponse(byte[] data, Action<List<(string, st
WebSocketResponse webSocketResponse = WebSocketResponse.Parser.ParseFrom(data);
if (webSocketResponse.ResponseTypeCase == WebSocketResponse.ResponseTypeOneofCase.SuperCampaignProgresses)
{
List<(string, string, string)> campaignProgresses = webSocketResponse.SuperCampaignProgresses.SuperCampaignProgresses_.Select(cp => (cp.SuperCampaignId, cp.CampaignId, cp.LevelId)).ToList();
List<(string, string, string)> campaignProgresses = webSocketResponse.SuperCampaignProgresses.SuperCampaignProgresses_.Select(cp => (cp.SuperCampaignName, cp.CampaignId, cp.LevelId)).ToList();
onCampaignProgressReceived?.Invoke(campaignProgresses);
}
}
Expand All @@ -448,7 +450,7 @@ private void AwaitCampaignsProgressResponse(byte[] data, Action<List<(string, st
}
}

public void GetCampaigns(string userId, Action<List<Campaign>> onCampaignDataReceived)
public void GetCampaigns(string userId, string superCampaignName, Action<List<Campaign>> onCampaignDataReceived)
{
GetCampaigns getCampaignsRequest = new GetCampaigns
{
Expand All @@ -458,13 +460,13 @@ public void GetCampaigns(string userId, Action<List<Campaign>> onCampaignDataRec
{
GetCampaigns = getCampaignsRequest
};
currentMessageHandler = (data) => AwaitGetCampaignsResponse(data, onCampaignDataReceived);
currentMessageHandler = (data) => AwaitGetCampaignsResponse(data, onCampaignDataReceived, superCampaignName);
ws.OnMessage += currentMessageHandler;
ws.OnMessage -= OnWebSocketMessage;
SendWebSocketMessage(request);
}

private void AwaitGetCampaignsResponse(byte[] data, Action<List<Campaign>> onCampaignDataReceived)
private void AwaitGetCampaignsResponse(byte[] data, Action<List<Campaign>> onCampaignDataReceived, string superCampaignName)
{
try
{
Expand All @@ -474,7 +476,7 @@ private void AwaitGetCampaignsResponse(byte[] data, Action<List<Campaign>> onCam
if (webSocketResponse.ResponseTypeCase == WebSocketResponse.ResponseTypeOneofCase.Campaigns)
{
List<Character> availableCharacters = GlobalUserData.Instance.AvailableCharacters;
List<Campaign> campaigns = ParseCampaignsFromResponse(webSocketResponse.Campaigns, availableCharacters);
List<Campaign> campaigns = ParseCampaignsFromResponse(webSocketResponse.Campaigns, superCampaignName, availableCharacters);
onCampaignDataReceived?.Invoke(campaigns);
}
}
Expand Down
4 changes: 3 additions & 1 deletion client/Assets/Scripts/CampaignsMap/CampaignsMapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public class CampaignsMapManager : MonoBehaviour
[SerializeField]
LevelManager sceneManager;

public static string selectedSuperCampaign;

void Start()
{
SocketConnection.Instance.GetCampaigns(GlobalUserData.Instance.User.id, (campaigns) =>
SocketConnection.Instance.GetCampaigns(GlobalUserData.Instance.User.id, selectedSuperCampaign, (campaigns) =>
{
// this needs to be refactored, the campaigns have two parallel "paths" that do different things, they should be unified into the static class
LevelProgress.campaigns = campaigns;
Expand Down
Loading