You've already forked CC-Framework.BriskGameServer
Initial Brisk Unity SDK project
This commit is contained in:
309
Assets/BriskSdk/Runtime/Core/BriskModelMapper.cs
Normal file
309
Assets/BriskSdk/Runtime/Core/BriskModelMapper.cs
Normal file
@@ -0,0 +1,309 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
internal static class BriskModelMapper
|
||||
{
|
||||
public static BriskLoginResult ToLoginResult(Dictionary<string, object> data)
|
||||
{
|
||||
var profileData = BriskValueReader.GetDictionary(data, "profile");
|
||||
return new BriskLoginResult
|
||||
{
|
||||
AccessToken = BriskValueReader.GetString(data, "access_token"),
|
||||
ExpiresIn = BriskValueReader.GetInt(data, "expires_in"),
|
||||
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
||||
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
||||
LoginProvider = BriskValueReader.GetString(profileData, "login_provider"),
|
||||
LoginUserId = BriskValueReader.GetString(profileData, "login_user_id"),
|
||||
IsNewPlayer = BriskValueReader.GetBool(data, "is_new_player"),
|
||||
Profile = ToProfile(profileData)
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskBootstrapResult ToBootstrapResult(Dictionary<string, object> data)
|
||||
{
|
||||
return new BriskBootstrapResult
|
||||
{
|
||||
ProjectName = BriskValueReader.GetString(data, "project_name"),
|
||||
ServerTime = BriskValueReader.GetString(data, "server_time"),
|
||||
MaintenanceMode = BriskValueReader.GetBool(data, "maintenance_mode"),
|
||||
MaintenanceMessage = BriskValueReader.GetString(data, "maintenance_message"),
|
||||
MinClientVersion = BriskValueReader.GetString(data, "min_client_version"),
|
||||
FeatureFlags = BriskValueReader.GetDictionary(data, "feature_flags") ?? new Dictionary<string, object>(),
|
||||
DynamicConfig = BriskValueReader.GetDictionary(data, "dynamic_config") ?? new Dictionary<string, object>()
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskConfigCurrent ToConfigCurrent(Dictionary<string, object> data)
|
||||
{
|
||||
return new BriskConfigCurrent
|
||||
{
|
||||
FeatureFlags = BriskValueReader.GetDictionary(data, "feature_flags") ?? new Dictionary<string, object>(),
|
||||
DynamicConfig = BriskValueReader.GetDictionary(data, "dynamic_config") ?? new Dictionary<string, object>()
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskPlayerMe ToPlayerMe(Dictionary<string, object> data)
|
||||
{
|
||||
return new BriskPlayerMe
|
||||
{
|
||||
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
||||
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
||||
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
||||
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
||||
Nickname = BriskValueReader.GetString(data, "nickname"),
|
||||
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
||||
ProfileJson = BriskValueReader.GetDictionary(data, "profile_json")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskProfile ToProfile(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskProfile
|
||||
{
|
||||
Nickname = BriskValueReader.GetString(data, "nickname"),
|
||||
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
||||
ProfileJson = BriskValueReader.GetDictionary(data, "profile_json")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskLeaderboardEntry ToLeaderboardEntry(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskLeaderboardEntry
|
||||
{
|
||||
Rank = BriskValueReader.GetInt(data, "rank"),
|
||||
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
||||
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
||||
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
||||
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
||||
Score = BriskValueReader.GetLong(data, "score"),
|
||||
Nickname = BriskValueReader.GetString(data, "nickname"),
|
||||
AvatarUrl = BriskValueReader.GetString(data, "avatar_url")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskLeaderboardPlayerRank ToLeaderboardPlayerRank(Dictionary<string, object> data)
|
||||
{
|
||||
var entry = ToLeaderboardEntry(data);
|
||||
if (entry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskLeaderboardPlayerRank
|
||||
{
|
||||
Rank = entry.Rank,
|
||||
Score = entry.Score,
|
||||
PlayerId = entry.PlayerId,
|
||||
ProjectAccountId = entry.ProjectAccountId,
|
||||
LoginProvider = entry.LoginProvider,
|
||||
LoginUserId = entry.LoginUserId,
|
||||
Nickname = entry.Nickname,
|
||||
AvatarUrl = entry.AvatarUrl
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskRankSeasonInfo ToRankSeasonInfo(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskRankSeasonInfo
|
||||
{
|
||||
SeasonId = BriskValueReader.GetString(data, "season_id") ?? BriskValueReader.GetString(data, "id"),
|
||||
Name = BriskValueReader.GetString(data, "name"),
|
||||
StartAt = BriskValueReader.GetString(data, "start_at"),
|
||||
EndAt = BriskValueReader.GetString(data, "end_at")
|
||||
};
|
||||
}
|
||||
|
||||
public static List<BriskLeaderboardEntry> ToLeaderboardEntries(object data)
|
||||
{
|
||||
return ExtractList(data)
|
||||
.Select(item => ToLeaderboardEntry(item as Dictionary<string, object>))
|
||||
.Where(item => item != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static List<BriskRankSeasonInfo> ToRankSeasonInfos(object data)
|
||||
{
|
||||
return ExtractList(data)
|
||||
.Select(item => ToRankSeasonInfo(item as Dictionary<string, object>))
|
||||
.Where(item => item != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static BriskAnnouncementItem ToAnnouncementItem(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskAnnouncementItem
|
||||
{
|
||||
Id = BriskValueReader.GetLong(data, "id"),
|
||||
Title = BriskValueReader.GetString(data, "title"),
|
||||
Content = BriskValueReader.GetString(data, "content"),
|
||||
ContentType = BriskValueReader.GetString(data, "content_type"),
|
||||
StartAt = BriskValueReader.GetString(data, "start_at"),
|
||||
EndAt = BriskValueReader.GetString(data, "end_at"),
|
||||
IsRead = BriskValueReader.GetBool(data, "is_read")
|
||||
};
|
||||
}
|
||||
|
||||
public static List<BriskAnnouncementItem> ToAnnouncementItems(object data)
|
||||
{
|
||||
return ExtractList(data)
|
||||
.Select(item => ToAnnouncementItem(item as Dictionary<string, object>))
|
||||
.Where(item => item != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static BriskArchiveSlot ToArchiveSlot(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskArchiveSlot
|
||||
{
|
||||
SlotNo = BriskValueReader.GetInt(data, "slot_no"),
|
||||
Version = BriskValueReader.GetInt(data, "version"),
|
||||
SizeBytes = BriskValueReader.GetLong(data, "size_bytes"),
|
||||
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskArchiveMeta ToArchiveMeta(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskArchiveMeta
|
||||
{
|
||||
SlotNo = BriskValueReader.GetInt(data, "slot_no"),
|
||||
Version = BriskValueReader.GetInt(data, "version"),
|
||||
Checksum = BriskValueReader.GetString(data, "checksum"),
|
||||
SizeBytes = BriskValueReader.GetLong(data, "size_bytes"),
|
||||
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskArchiveUploadResult ToArchiveUploadResult(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskArchiveUploadResult
|
||||
{
|
||||
SlotNo = BriskValueReader.GetInt(data, "slot_no"),
|
||||
Version = BriskValueReader.GetInt(data, "version"),
|
||||
SizeBytes = BriskValueReader.GetLong(data, "size_bytes"),
|
||||
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
||||
};
|
||||
}
|
||||
|
||||
public static List<BriskArchiveSlot> ToArchiveSlots(object data)
|
||||
{
|
||||
return ExtractList(data)
|
||||
.Select(item => ToArchiveSlot(item as Dictionary<string, object>))
|
||||
.Where(item => item != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static BriskSpaceView ToSpaceView(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskSpaceView
|
||||
{
|
||||
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
||||
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
||||
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
||||
Payload = BriskValueReader.GetDictionary(data, "payload_json") ?? BriskValueReader.GetDictionary(data, "payload")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskSpaceStats ToSpaceStats(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskSpaceStats
|
||||
{
|
||||
LikeCount = BriskValueReader.GetInt(data, "like_count"),
|
||||
VisitCount = BriskValueReader.GetInt(data, "visit_count")
|
||||
};
|
||||
}
|
||||
|
||||
public static BriskSpaceVisit ToSpaceVisit(Dictionary<string, object> data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BriskSpaceVisit
|
||||
{
|
||||
VisitorPlayerId = BriskValueReader.GetString(data, "visitor_player_id") ?? BriskValueReader.GetString(data, "player_id"),
|
||||
VisitorLoginProvider = BriskValueReader.GetString(data, "visitor_login_provider") ?? BriskValueReader.GetString(data, "login_provider"),
|
||||
VisitorLoginUserId = BriskValueReader.GetString(data, "visitor_login_user_id") ?? BriskValueReader.GetString(data, "login_user_id"),
|
||||
VisitorNickname = BriskValueReader.GetString(data, "visitor_nickname") ?? BriskValueReader.GetString(data, "nickname"),
|
||||
VisitorAvatarUrl = BriskValueReader.GetString(data, "visitor_avatar_url") ?? BriskValueReader.GetString(data, "avatar_url"),
|
||||
VisitedAt = BriskValueReader.GetString(data, "visited_at")
|
||||
};
|
||||
}
|
||||
|
||||
public static List<BriskSpaceVisit> ToSpaceVisits(object data)
|
||||
{
|
||||
return ExtractList(data)
|
||||
.Select(item => ToSpaceVisit(item as Dictionary<string, object>))
|
||||
.Where(item => item != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static Dictionary<string, object> ExtractObject(object data)
|
||||
{
|
||||
return data as Dictionary<string, object>;
|
||||
}
|
||||
|
||||
private static List<object> ExtractList(object data)
|
||||
{
|
||||
if (data is List<object> list)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
if (data is Dictionary<string, object> dictionary)
|
||||
{
|
||||
return BriskValueReader.GetList(dictionary, "items")
|
||||
?? BriskValueReader.GetList(dictionary, "list")
|
||||
?? BriskValueReader.GetList(dictionary, "records")
|
||||
?? new List<object>();
|
||||
}
|
||||
|
||||
return new List<object>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user