2024-09-18 15:53:58 +08:00
|
|
|
using AxibugEmuOnline.Client.ClientCore;
|
|
|
|
using AxibugProtobuf;
|
|
|
|
using System;
|
2024-08-16 14:45:44 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client
|
|
|
|
{
|
|
|
|
public static class Utility
|
|
|
|
{
|
|
|
|
public static void SetActiveEx(this GameObject go, bool active)
|
|
|
|
{
|
|
|
|
if (active && go.activeSelf) return;
|
|
|
|
if (!active && !go.activeSelf) return;
|
|
|
|
|
|
|
|
go.SetActive(active);
|
|
|
|
}
|
2024-09-18 15:53:58 +08:00
|
|
|
|
|
|
|
public static string GetHostNickName(this Protobuf_Room_MiniInfo roomInfo)
|
|
|
|
{
|
|
|
|
var hostUID = roomInfo.HostPlayerUID;
|
|
|
|
if (hostUID == roomInfo.Player1UID) return roomInfo.Player1NickName;
|
|
|
|
else if (hostUID == roomInfo.Player2UID) return roomInfo.Player2NickName;
|
|
|
|
else if (hostUID == roomInfo.Player3UID) return roomInfo.Player3NickName;
|
|
|
|
else if (hostUID == roomInfo.Player4UID) return roomInfo.Player4NickName;
|
|
|
|
else return string.Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void GetRoomPlayers(this Protobuf_Room_MiniInfo roomInfo, out int current, out int max)
|
|
|
|
{
|
|
|
|
current = 0; max = 4;
|
|
|
|
|
|
|
|
if (roomInfo.Player1UID > 0) current++;
|
|
|
|
if (roomInfo.Player2UID > 0) current++;
|
|
|
|
if (roomInfo.Player3UID > 0) current++;
|
|
|
|
if (roomInfo.Player4UID > 0) current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>();
|
2024-11-08 11:31:12 +08:00
|
|
|
public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<Protobuf_Room_MiniInfo, RomFile> callback)
|
2024-09-18 15:53:58 +08:00
|
|
|
{
|
|
|
|
if (s_RomFileCahcesInRoomInfo.TryGetValue(roomInfo.GameRomID, out RomFile romFile))
|
|
|
|
{
|
2024-11-08 11:31:12 +08:00
|
|
|
callback.Invoke(roomInfo,romFile);
|
2024-09-18 15:53:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (platform)
|
|
|
|
{
|
|
|
|
case EnumPlatform.NES:
|
|
|
|
App.StartCoroutine(App.httpAPI.GetNesRomInfo(roomInfo.GameRomID, (romWebData) =>
|
|
|
|
{
|
|
|
|
RomFile romFile = new RomFile(EnumPlatform.NES, 0, 0);
|
|
|
|
romFile.SetWebData(romWebData);
|
|
|
|
s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = romFile;
|
2024-11-08 13:48:53 +08:00
|
|
|
|
2024-11-08 11:31:12 +08:00
|
|
|
callback.Invoke(roomInfo,romFile);
|
2024-09-18 15:53:58 +08:00
|
|
|
}));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-08-16 14:45:44 +08:00
|
|
|
}
|
|
|
|
}
|