Skip to content

Commit

Permalink
WIP: Receive upgrades in client
Browse files Browse the repository at this point in the history
  • Loading branch information
ncontinanza committed Jun 12, 2024
1 parent aa01c76 commit 19d5616
Show file tree
Hide file tree
Showing 13 changed files with 6,369 additions and 3,820 deletions.
1,629 changes: 1,195 additions & 434 deletions client/Assets/Scenes/DungeonUpgrades.unity

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion client/Assets/Scripts/BackendConnection/SocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,4 +1004,41 @@ private void AwaitLevelUpDungeonSettlementResponse(byte[] data, Action<User> onL
}
}

}
public void GetDungeonUpgrades(string userId, Action<User> onLeveledUpUserReceived, Action<string> onError = null)
{
GetDungeonUpgrades getDungeonUpgrades = new GetDungeonUpgrades
{
UserId = userId
};
WebSocketRequest request = new WebSocketRequest
{
GetDungeonUpgrades = getDungeonUpgrades
};
currentMessageHandler = (data) => AwaitGetDungeonUpgradesResponse(data, onLeveledUpUserReceived, onError);
ws.OnMessage += currentMessageHandler;
ws.OnMessage -= OnWebSocketMessage;
SendWebSocketMessage(request);
}

private void AwaitGetDungeonUpgradesResponse(byte[] data, Action<User> onLeveledUpUserReceived, Action<string> onError = null)
{
try
{
ws.OnMessage -= currentMessageHandler;
ws.OnMessage += OnWebSocketMessage;
WebSocketResponse webSocketResponse = WebSocketResponse.Parser.ParseFrom(data);
if (webSocketResponse.ResponseTypeCase == WebSocketResponse.ResponseTypeOneofCase.Upgrades)
{
GlobalUserData.Instance.AvailableUpgrades = webSocketResponse.Upgrades.Upgrades_.Select(upgrade => new Upgrade
{
id = upgrade.Id,
name = upgrade.Name,
description = upgrade.Description,
cost = upgrade.Cost.ToDictionary(cost => cost.Currency.Name, cost => (int)cost.Amount),
level = (int)upgrade.Level,
maxLevel = (int)upgrade.MaxLevel,
type = upgrade.Type,
value = upgrade.Value
}).ToList();

}
7 changes: 7 additions & 0 deletions client/Assets/Scripts/Buff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public class Buff
{
string attribute;
float value;
string operation;
}
32 changes: 32 additions & 0 deletions client/Assets/Scripts/Dungeon/DungeonUpgradeDetailPopUp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class DungeonUpgradeDetailPopup : MonoBehaviour
{
[SerializeField]
Image icon;
[SerializeField]
new TMP_Text name;
[SerializeField]
TMP_Text rarity;
[SerializeField]
TMP_Text level;
[SerializeField]
TMP_Text type;
[SerializeField]
TMP_Text attributes;
public void ShowItem(Item item)
{
icon.sprite = item.template.icon;
name.text = item.template.name;
rarity.text = "Common"; // Hardcoded, don't currently get attributes from the backend.
level.text = $"Level: {item.level}";
type.text = $"Type: {item.template.type}";
attributes.text = "+50hp"; // Hardcoded, don't currently get attributes from the backend.
gameObject.SetActive(true);
}
}
11 changes: 11 additions & 0 deletions client/Assets/Scripts/Dungeon/DungeonUpgradeDetailPopUp.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions client/Assets/Scripts/Dungeon/DungeonUpgradesManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;

public class DungeonUpgradesManager : MonoBehaviour
{
[SerializeField]
GameObject upgradePrefab;
[SerializeField]
GameObject upgradesContainer;
[SerializeField]
ItemDetailPopup upgradeDetailPopup;


void Start()
{
User user = GlobalUserData.Instance.User;

SocketConnection.Instance.GetDungeonUpgrades(user.id, (upgrades) =>
{
foreach (var group in upgrades.GroupBy(upgrade => upgrade.template.name))
{
GameObject upgradeUIObject = Instantiate(upgradePrefab, upgradesContainer.transform);
upgradeUIObject.GetComponent<DungeonUpgradeUI>().SetUpUpgrade(group.First(), group.Count());
Button unitUpgradeButton = upgradeUIObject.GetComponent<Button>();
unitUpgradeButton.onClick.AddListener(() => ShowUpgradeDetailPopup(group.First()));
}
},
(error) =>
{
Debug.LogError(error);
});
}

}
11 changes: 11 additions & 0 deletions client/Assets/Scripts/Dungeon/DungeonUpgradesManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 19d5616

Please sign in to comment.