const string WORLD_TYPE_NONE = "WORLD_TYPE_NONE"; const string WORLD_TYPE_OFFICIAL = "WORLD_TYPE_OFFICIAL"; const string WORLD_TYPE_GENERAL = "WORLD_TYPE_GENERAL"; const string WORLD_TYPE_CREATOR = "WORLD_TYPE_CREATOR"; const string WORLD_TYPE_ROOM = "WORLD_TYPE_ROOM"; const string WORLD_SORT_TYPE_POPULAR = "WORLD_SORT_TYPE_POPULAR"; const string WORLD_SORT_TYPE_NEW = "WORLD_SORT_TYPE_NEW"; const string WORLD_SORT_TYPE_OLD = "WORLD_SORT_TYPE_OLD"; const string WORLD_SORT_TYPE_VISIT = "WORLD_SORT_TYPE_VISIT"; const string WORLD_SORT_TYPE_NONE = "WORLD_SORT_TYPE_NONE"; class WorldMenuModel { WorldMenuViewModel m_ViewModel; string m_CurrentWorldType; list m_WorldList; int m_PagerIndex; int m_MaxPege; int m_SelectedWorldItemIndex; string m_CurrentWorldSortType; string m_CurrentKeyword; string m_CurrentWorldCreatorVketId; WorldMenuWorldDetailData m_CurrentDetailData; public WorldMenuModel() { // ワールド訪問数カウントスクリプトを実行する DoCountVisit(); m_ViewModel = system.Layer_GetComponentByName("mainmenu_world_tab"); m_CurrentWorldType = WORLD_TYPE_NONE; m_WorldList = new list(); m_PagerIndex = 0; m_MaxPege = 0; m_SelectedWorldItemIndex = -1; m_CurrentWorldSortType = WORLD_SORT_TYPE_POPULAR; m_CurrentDetailData = null; } void DoCountVisit() { string spatiumCode = hsNetGetSpatiumCode(); string platformCode = hsGetPlatformCode(); string worldid = hsGetCurrentWorldId(); heliport.v3.api.worlds.getWorldDetailByWorldId(_FetchWorldDetailForVisitCount, spatiumCode, worldid); } void _FetchWorldDetailForVisitCount(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; JsVal world = result.data.GetProperty("world_portal"); if(world === null) return; int world_set_id = world.GetProperty("world_set_id").GetNum(); heliport.v3.api.worlds.visitWorld(_VisitWorldCallback, world_set_id, hsGetPlatformCode()); } void _VisitWorldCallback(JsVal val) { } public void Release() { m_WorldList.Clear(); m_CurrentKeyword = ""; } public void CloseDescriptDialog() { m_CurrentDetailData = null; } public string GetCurrentWorldType() { return m_CurrentWorldType; } public list GetWorldList() { return m_WorldList; } public int GetPagerIndex() { return m_PagerIndex; } public void SetWorldSortType(string SortType) { m_CurrentWorldSortType = SortType; } public void FetchWorldList(string WorldType, int PagerIndex, string keyword) { Release(); m_CurrentWorldType = WorldType; m_PagerIndex = PagerIndex; int Offset = 6 * PagerIndex; m_CurrentKeyword = keyword; string SortParam; if(m_CurrentWorldSortType == WORLD_SORT_TYPE_POPULAR) { SortParam = "popular"; } else if(m_CurrentWorldSortType == WORLD_SORT_TYPE_NEW) { SortParam = "newer"; } else if(m_CurrentWorldSortType == WORLD_SORT_TYPE_OLD) { SortParam = "older"; } else if(m_CurrentWorldSortType == WORLD_SORT_TYPE_VISIT) { SortParam = (m_CurrentWorldType == WORLD_TYPE_ROOM)? "favorite" : "visit_count"; } else { SortParam = ""; } string filter; if(m_CurrentWorldType == WORLD_TYPE_OFFICIAL) { filter = "official"; } else if(m_CurrentWorldType == WORLD_TYPE_GENERAL) { filter = "user"; } if(m_CurrentWorldType == WORLD_TYPE_ROOM) { heliport.v3.api.worlds.getHousingWorldList(_FetchHousingWorldListCallback, 6, Offset, hsGetPlatformCode(), SortParam, m_CurrentKeyword); } else if(m_CurrentWorldType == WORLD_TYPE_CREATOR) { { LayerBundle layer = hsLayerGet("worldinfo_descript_text_dialog"); if(layer !== null) { Func GetWorldCreatorVketID = system.Layer_GetComponentMethod(layer.GetCurrent()._GetInstanceID(), "WorldInfoDialog", "GetWorldCreatorVketID"); if(GetWorldCreatorVketID.IsEmpty()) return; m_CurrentWorldCreatorVketId = GetWorldCreatorVketID(); } } // 空の時はAPIを実行しない if(m_CurrentWorldCreatorVketId.IsEmpty()) { return; } heliport.v3.api.worlds.getWorldListByCreator(_FetchWorldListCallback, m_CurrentWorldCreatorVketId, 6, Offset, hsGetPlatformCode(), SortParam, filter, m_CurrentKeyword); } else { heliport.v3.api.worlds.getWorldList(_FetchWorldListCallback, 6, Offset, hsGetPlatformCode(), SortParam, filter, m_CurrentKeyword); } } void _FetchWorldListCallback(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; JsVal world_portals = result.data.GetProperty("world_portals"); if(world_portals === null || world_portals.IsNull()) return; list world_portals_array = world_portals.GetPropertyList(); for(int i = 0; i < world_portals_array.Count; i++) { JsVal world = world_portals_array[i].GetValue(); if(world === null || world.IsNull()) continue; WorldMenuWorldData Data = new WorldMenuWorldData(); int id = world.GetProperty("id").GetNum(); Data.WorldID = ("%d" % id); string name = world.GetProperty("name").GetStr(); Data.Title = (name); int visit_count = world.GetProperty("visit_count").GetNum(); Data.VisitCount = (visit_count); Data.IsOfficial = false; if(world.GetProperty("is_official") !== null) { Data.IsOfficial = world.GetProperty("is_official").GetBool(); } string ingame_url = world.GetProperty("ingame_url").GetStr(); Data.IngameUrl = (ingame_url); JsVal thumbnail = world.GetProperty("thumbnail"); if(thumbnail !== null) { string url = thumbnail.GetProperty("url").GetStr(); if(url.IsEmpty()) { url = "gui2024/menu/world/world_thumbnail_world_list.png"; } Data.ThumbnailURL = (url); } m_WorldList.Add(Data); } int world_portal_count = result.data.GetProperty("world_portal_count").GetNum(); m_MaxPege = (world_portal_count + 6 - 1) / 6; m_ViewModel.DrawWorldList(m_CurrentWorldType, m_WorldList); } void _FetchHousingWorldListCallback(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; JsVal housing_worlds = result.data.GetProperty("housing_worlds"); if(housing_worlds === null) return; list housingWorldsArray = housing_worlds.GetPropertyList(); for(int i = 0; i < housingWorldsArray.Count; i++) { JsVal world = housingWorldsArray[i].GetValue(); if(world === null) continue; WorldMenuWorldData Data = new WorldMenuWorldData(); string world_id = world.GetProperty("world_id").GetStr(); Data.WorldID = (world_id); string name = world.GetProperty("name").GetStr(); Data.Title = (name); int visit_count = 0; // Data.VisitCount = (visit_count); // HousingWorldにはvisit_countのフィールドはない(仕様にもない) string ingame_url; // world.FindValueString("ingame_url", ingame_url); // ハウジングの場合はgetHousingWorldDetailからURLを取得する必要がある Data.IngameUrl = (ingame_url); JsVal thumbnail = world.GetProperty("thumbnail"); if(thumbnail !== null) { string url = thumbnail.GetProperty("url").GetStr(); if(url.IsEmpty()) { url = "gui2024/menu/world/world_thumbnail_world_list.png"; } Data.ThumbnailURL = (url); } m_WorldList.Add(Data); } int housing_world_count = result.data.GetProperty("housing_world_count").GetNum(); m_MaxPege = (housing_world_count + 6 - 1) / 6; m_ViewModel.DrawWorldList(m_CurrentWorldType, m_WorldList); } public void UpdatePager(int val) { m_PagerIndex += val; if(m_PagerIndex < 0) { m_PagerIndex = 0; return; } else if(m_PagerIndex >= m_MaxPege) { m_PagerIndex = (m_MaxPege - 1); return; } if(m_CurrentWorldType == WORLD_TYPE_OFFICIAL) { FetchWorldList(WORLD_TYPE_OFFICIAL, m_PagerIndex, ""); } else if(m_CurrentWorldType == WORLD_TYPE_GENERAL) { FetchWorldList(WORLD_TYPE_GENERAL, m_PagerIndex, m_CurrentKeyword); } else if(m_CurrentWorldType == WORLD_TYPE_CREATOR) { FetchWorldList(WORLD_TYPE_CREATOR, m_PagerIndex, m_CurrentKeyword); } else if(m_CurrentWorldType == WORLD_TYPE_ROOM) { FetchWorldList(WORLD_TYPE_ROOM, m_PagerIndex, m_CurrentKeyword); } } public void SortWorldList(string SortType) { m_CurrentWorldSortType = SortType; m_PagerIndex = 0; if(m_CurrentWorldType == WORLD_TYPE_GENERAL) { FetchWorldList(WORLD_TYPE_GENERAL, 0, ""); } else if(m_CurrentWorldType == WORLD_TYPE_ROOM) { FetchWorldList(WORLD_TYPE_ROOM, 0, ""); } } public void SearchWorld(string keyword) { m_CurrentWorldSortType = WORLD_SORT_TYPE_NONE; if(m_CurrentWorldType == WORLD_TYPE_GENERAL) { FetchWorldList(WORLD_TYPE_GENERAL, 0, keyword); } else if(m_CurrentWorldType == WORLD_TYPE_ROOM) { FetchWorldList(WORLD_TYPE_ROOM, 0, keyword); } } public void SelectWorldItem(int ItemIndex) { m_SelectedWorldItemIndex = ItemIndex; } public void FetchWorldListDetail() { if(m_SelectedWorldItemIndex >= 0 && m_SelectedWorldItemIndex < m_WorldList.Count) { WorldMenuWorldData Data = m_WorldList[m_SelectedWorldItemIndex]; string ID = Data.WorldID; if(m_CurrentWorldType == WORLD_TYPE_ROOM) { // heliport.v3.api.worlds.getHousingWorldDetail(_FetchWorldListDetailCallback, ID, hsGetPlatformCode()); } else { heliport.v3.api.worlds.getWorldDetail(_FetchWorldListDetailCallback, ID, hsGetPlatformCode()); } } } void _FetchWorldListDetailCallback(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; WorldMenuWorldData WorldData = m_WorldList[m_SelectedWorldItemIndex]; WorldMenuWorldDetailData DetailData = new WorldMenuWorldDetailData(); JsVal world = result.data.GetProperty("world_portal"); if(world === null) return; string created_at = world.GetProperty("created_at").GetStr(); DetailData.CreatedDate = created_at; string updated_at = world.GetProperty("updated_at").GetStr(); DetailData.UpdatedDate = updated_at; string creator_name = world.GetProperty("creator_name").GetStr(); DetailData.CreatorName = creator_name; string creator_name_en = world.GetProperty("creator_name_en").GetStr(); DetailData.CreatorName_EN = creator_name_en; string creator_vket_id = world.GetProperty("creator_vket_id").GetStr(); DetailData.UserCode = creator_vket_id; string description = world.GetProperty("description").GetStr(); DetailData.Description = description; int number_of_likes = world.GetProperty("number_of_likes").GetNum(); DetailData.NumOfLikes = number_of_likes; int world_set_id = world.GetProperty("world_set_id").GetNum(); DetailData.WorldSetID = "%d" % world_set_id; Player SelfPlayer = hsPlayerGet(); string SelfUserType = SelfPlayer.GetCustomState("UserType"); if(SelfUserType == "login") { JsVal liked = world.GetProperty("liked"); if(liked !== null) { DetailData.Liked = liked.GetBool(); } } m_CurrentDetailData = DetailData; m_ViewModel.OnUpdatedWorldDetailPage(WorldData, DetailData); } public void FetchCreatorProfile(int UserIndex) { if(m_SelectedWorldItemIndex >= 0 && m_SelectedWorldItemIndex < m_WorldList.Count) { if(m_CurrentDetailData !== null) { string UserCode = m_CurrentDetailData.UserCode; if(!UserCode.IsEmpty()) { Player SelfPlayer = hsPlayerGet(); string SelfUserCode = SelfPlayer.GetCustomState("UserCode"); string SelfUserType = SelfPlayer.GetCustomState("UserType"); LayerBundle layer = hsLayerGet("other_profile"); if(layer !== null) { Func FindUserDataAndShowProfileFromUserID = system.Layer_GetComponentMethod(layer.GetCurrent()._GetInstanceID(), "ProfileModel", "FindUserDataAndShowProfileFromUserID"); if(!FindUserDataAndShowProfileFromUserID.IsEmpty()) FindUserDataAndShowProfileFromUserID(UserCode, "login", (SelfUserType == "login" && SelfUserCode != UserCode)); } } } } } public void MoveWorld() { if(m_SelectedWorldItemIndex >= 0 && m_SelectedWorldItemIndex < m_WorldList.Count) { WorldMenuWorldData Data = m_WorldList[m_SelectedWorldItemIndex]; if(m_CurrentWorldType == WORLD_TYPE_ROOM) { // ハウジングの場合はさらに詳細を問い合わせる必要がある string worldid = Data.WorldID; if(!worldid.IsEmpty()) { //heliport.v3.api.profiles.openMyVketUrl("/myroom/maker/?worldid=%s" % worldid); string CurrentUrl = GetCurrentUrl(); bool IsTest = (CurrentUrl.IndexOf("test") != -1 || CurrentUrl.IndexOf("localhost") != -1 || CurrentUrl.IndexOf("hikky.dev") != -1); string Domain = (IsTest)? "cloud.hikky.dev" : "cloud.vket.com"; string MyVketURL = "https://%s/myroom/maker/?worldid=%s" % Domain % worldid; hsWebOpen(MyVketURL); } } else { // ワールドリストが持っているURLで遷移する string URL = Data.IngameUrl; if(!URL.IsEmpty()) { hsWebOpen(URL); } } } } public void PostLikeWorld() { heliport.v3.api.auths.isLoggedIn(_LoginCallbackLikeWorld); } void _LoginCallbackLikeWorld(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; bool loginValid = result.data.GetBool(); if(loginValid) { string WorldSetID = m_CurrentDetailData.WorldSetID; if(WorldSetID.IsEmpty()) return; heliport.v3.api.worlds.likeWorld(_LikeWorldCallback, WorldSetID, hsGetPlatformCode()); } } void _LikeWorldCallback(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; FetchWorldListDetail(); } public void PostUnlikeWorld() { heliport.v3.api.auths.isLoggedIn(_LoginCallbackUnlikeWorld); } void _LoginCallbackUnlikeWorld(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; bool loginValid = result.data.GetBool(); if(loginValid) { string WorldSetID = m_CurrentDetailData.WorldSetID; if(WorldSetID.IsEmpty()) return; heliport.v3.api.worlds.unlikeWorld(_UnlikeWorldCallback, WorldSetID, hsGetPlatformCode()); } } void _UnlikeWorldCallback(JsVal val) { ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return; FetchWorldListDetail(); } private string GetCurrentUrl() { JsVal val = heliport.v3.api.routers.getCurrentUrl(); ReturnType result = hsLoadReturnType(val); if(!result.IsValid()) return ""; return result.data.GetStr(); } }