diff --git a/assets/Scene/GameScene.fire b/assets/Scene/GameScene.fire index 3ba6928..7e5ea75 100644 --- a/assets/Scene/GameScene.fire +++ b/assets/Scene/GameScene.fire @@ -18688,10 +18688,12 @@ }, { "__type__": "cc.ClickEvent", - "target": null, + "target": { + "__id__": 76 + }, "component": "", - "_componentId": "", - "handler": "", + "_componentId": "2234assp7RIvpDgrnqljp2R", + "handler": "runAuthorize", "customEventData": "" }, { diff --git a/assets/Scene/HomeScene.fire b/assets/Scene/HomeScene.fire index 5734836..1e4e5ce 100644 --- a/assets/Scene/HomeScene.fire +++ b/assets/Scene/HomeScene.fire @@ -20,7 +20,7 @@ "__id__": 5 }, { - "__id__": 529 + "__id__": 530 } ], "_active": false, @@ -286,22 +286,22 @@ "__id__": 479 }, { - "__id__": 512 + "__id__": 513 }, { - "__id__": 517 + "__id__": 518 } ], "_active": true, "_components": [ - { - "__id__": 526 - }, { "__id__": 527 }, { "__id__": 528 + }, + { + "__id__": 529 } ], "_prefab": null, @@ -21058,9 +21058,13 @@ } ], "_active": false, - "_components": [], + "_components": [ + { + "__id__": 511 + } + ], "_prefab": { - "__id__": 511 + "__id__": 512 }, "_opacity": 255, "_color": { @@ -21117,7 +21121,7 @@ "__id__": 479 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 481 @@ -21132,7 +21136,7 @@ "_prefab": { "__id__": 484 }, - "_opacity": 210, + "_opacity": 200, "_color": { "__type__": "cc.Color", "r": 0, @@ -21142,8 +21146,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 1180, - "height": 2340 + "width": 1080, + "height": 1920 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -21221,11 +21225,11 @@ "_enabled": true, "alignMode": 1, "_target": null, - "_alignFlags": 40, - "_left": -50, - "_right": -50, - "_top": -210, - "_bottom": -210, + "_alignFlags": 45, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, "_verticalCenter": 0, "_horizontalCenter": 0, "_isAbsLeft": true, @@ -22233,6 +22237,33 @@ "fileId": "cdCj6iBydMHLooCJU2lGg3", "sync": false }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 479 + }, + "_enabled": true, + "alignMode": 1, + "_target": null, + "_alignFlags": 45, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 1080, + "_originalHeight": 1920, + "_id": "06HVSFiRVDGr2ovcpYqEBL" + }, { "__type__": "cc.PrefabInfo", "root": { @@ -22253,13 +22284,13 @@ }, "_children": [ { - "__id__": 513 + "__id__": 514 } ], "_active": false, "_components": [ { - "__id__": 516 + "__id__": 517 } ], "_prefab": null, @@ -22315,16 +22346,16 @@ "_name": "New Sprite(Splash)", "_objFlags": 0, "_parent": { - "__id__": 512 + "__id__": 513 }, "_children": [], "_active": true, "_components": [ { - "__id__": 514 + "__id__": 515 }, { - "__id__": 515 + "__id__": 516 } ], "_prefab": null, @@ -22380,7 +22411,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 513 + "__id__": 514 }, "_enabled": true, "_materials": [ @@ -22412,7 +22443,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 513 + "__id__": 514 }, "_enabled": true, "_id": "59BOMZmhdPJajqBGyoUDBU" @@ -22422,7 +22453,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 512 + "__id__": 513 }, "_enabled": true, "_materials": [ @@ -22468,19 +22499,19 @@ }, "_children": [ { - "__id__": 518 + "__id__": 519 }, { - "__id__": 521 + "__id__": 522 }, { - "__id__": 523 + "__id__": 524 } ], "_active": false, "_components": [ { - "__id__": 525 + "__id__": 526 } ], "_prefab": null, @@ -22536,16 +22567,16 @@ "_name": "New Sprite(Splash)", "_objFlags": 0, "_parent": { - "__id__": 517 + "__id__": 518 }, "_children": [], "_active": true, "_components": [ { - "__id__": 519 + "__id__": 520 }, { - "__id__": 520 + "__id__": 521 } ], "_prefab": null, @@ -22601,7 +22632,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 518 + "__id__": 519 }, "_enabled": true, "_materials": [ @@ -22633,7 +22664,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 518 + "__id__": 519 }, "_enabled": true, "_id": "f7VWpZp11LWprv6A8lnYhR" @@ -22643,13 +22674,13 @@ "_name": "load", "_objFlags": 0, "_parent": { - "__id__": 517 + "__id__": 518 }, "_children": [], "_active": true, "_components": [ { - "__id__": 522 + "__id__": 523 } ], "_prefab": null, @@ -22705,7 +22736,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 521 + "__id__": 522 }, "_enabled": true, "_materials": [ @@ -22737,13 +22768,13 @@ "_name": "New Label", "_objFlags": 0, "_parent": { - "__id__": 517 + "__id__": 518 }, "_children": [], "_active": true, "_components": [ { - "__id__": 524 + "__id__": 525 } ], "_prefab": null, @@ -22799,7 +22830,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 523 + "__id__": 524 }, "_enabled": true, "_materials": [ @@ -22832,7 +22863,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 517 + "__id__": 518 }, "_enabled": true, "alignMode": 1, @@ -22966,14 +22997,14 @@ "_children": [], "_active": true, "_components": [ - { - "__id__": 530 - }, { "__id__": 531 }, { "__id__": 532 + }, + { + "__id__": 533 } ], "_prefab": null, @@ -23029,7 +23060,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 529 + "__id__": 530 }, "_enabled": true, "_materials": [ @@ -23062,7 +23093,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 529 + "__id__": 530 }, "_enabled": true, "alignMode": 1, @@ -23089,11 +23120,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 529 + "__id__": 530 }, "_enabled": true, "uid_Number": { - "__id__": 530 + "__id__": 531 }, "_id": "67zCbKKV9PvYlB9x+eob0L" } diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index f15361b..25ff1d3 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -2506,36 +2506,24 @@ export default class JiaZai extends cc.Component { // 获取CareerList组件实例 let careerList = scrollVIew.getComponent("CareerList"); let address = cc.fx.StorageMessage.getStorage("address"); + //没缓存过,没授权过 if (address == "" || address == null || address == undefined) { - console.log("没有地址"); - MiniGameSdk.API.getWechatCityInfo((success, data, error) => { - console.log("解析地址:", success, data, error); - if (success) { - console.log('详细城市信息:', data); - console.log("给用户移动到他所在的区域"); - - top.getChildByName("posBtn").active = false; - top.getChildByName("topBtn").active = true; - //缓存地址 - // cc.fx.StorageMessage.setStorage("address", cc.fx.GameConfig.GM_INFO.address); - // 在需要的地方调用 - // 滚动到其他城市(自定义位置和动画时间) - if (cc.fx.GameConfig.GM_INFO.address == "") { - cc.fx.GameConfig.GM_INFO.address = "其他"; - } - careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画,屏幕30%位置 - } - else { - // cc.fx.StorageMessage.setStorage("address", cc.fx.GameConfig.GM_INFO.address); - cc.fx.GameConfig.GM_INFO.address = "其他"; - careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画,屏幕30%位置 - top.getChildByName("posBtn").active = false; - top.getChildByName("topBtn").active = true; - } - }, true); // 第二个参数设为true启用逆解析 + this.runAuthorize(); } + //缓存,但是没有授权 + else if (address.authorize == false || address.authorize == undefined) { + let nowTime = Math.floor(Date.now() / 1000); + if (nowTime - address.time > 60 * 60 * 24) { + this.runAuthorize(); + } else { + careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画,屏幕30%位置 + top.getChildByName("posBtn").active = false; + top.getChildByName("topBtn").active = true; + } + } + //有缓存,并且授权了 else { - if (cc.fx.GameConfig.GM_INFO.address == "") { + if (cc.fx.GameConfig.GM_INFO.address == "" || cc.fx.GameConfig.GM_INFO.address == null || cc.fx.GameConfig.GM_INFO.address == undefined) { cc.fx.GameConfig.GM_INFO.address = "其他"; } careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画,屏幕30%位置 @@ -2544,6 +2532,54 @@ export default class JiaZai extends cc.Component { } } + runAuthorize() { + let scrollVIew = this.RankNode.getChildByName("ScrollView"); + let top = this.node.getChildByName("Load").getChildByName("Top"); + // 获取CareerList组件实例 + let careerList = scrollVIew.getComponent("CareerList"); + MiniGameSdk.API.getWechatCityInfo((success, data, error) => { + console.log("解析地址:", success, data, error); + if (success) { + console.log('详细城市信息:', data); + console.log("给用户移动到他所在的区域"); + console.log("没有地址"); + top.getChildByName("posBtn").active = false; + top.getChildByName("topBtn").active = true; + if (data != null && data != "" && data != undefined) cc.fx.GameConfig.GM_INFO.address = data; + let nowTime = Math.floor(Date.now() / 1000); + let addressInfo = { + address: data, + time: nowTime, + authorize: true + } + Utils.setCityInfo(null, cc.fx.GameConfig.GM_INFO.address, true); + //缓存地址 + cc.fx.StorageMessage.setStorage("address", addressInfo); + // 在需要的地方调用 + // 滚动到其他城市(自定义位置和动画时间) + if (cc.fx.GameConfig.GM_INFO.address == "") { + cc.fx.GameConfig.GM_INFO.address = "其他"; + } + careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画,屏幕30%位置 + } + else { + // cc.fx.StorageMessage.setStorage("address", cc.fx.GameConfig.GM_INFO.address); + cc.fx.GameConfig.GM_INFO.address = "其他"; + let nowTime = Math.floor(Date.now() / 1000); + let addressInfo = { + address: data, + time: nowTime, + authorize: false + } + cc.fx.StorageMessage.setStorage("address", addressInfo); + careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画,屏幕30%位置 + top.getChildByName("posBtn").active = false; + top.getChildByName("topBtn").active = true; + Utils.setFailCityInfo(); + } + }, true); // 第二个参数设为true启用逆解析 + } + backTop() { console.log("给用户移动到列表顶部"); let top = this.node.getChildByName("Load").getChildByName("Top"); diff --git a/assets/Script/Map.ts b/assets/Script/Map.ts index 2c18a96..f5ea2a9 100644 --- a/assets/Script/Map.ts +++ b/assets/Script/Map.ts @@ -4022,6 +4022,20 @@ export default class MapConroler extends cc.Component { let Career = this.node.parent.parent.getChildByName("Win").getChildByName("Career"); let progress = Career.getChildByName("progress"); let max = false; + if (cc.fx.GameConfig.GM_INFO.addLevel == 4) { + let address = cc.fx.StorageMessage.getStorage("address"); + //没缓存过,没授权过 + if (address == "" || address == null || address == undefined) { + this.node.parent.parent.getChildByName("Win").getChildByName("Ruzhi").active = true; + } + //缓存,但是没有授权 + else if (address.authorize == false || address.authorize == undefined) { + let nowTime = Math.floor(Date.now() / 1000); + if (nowTime - address.time > 60 * 60 * 24) { + this.node.parent.parent.getChildByName("Win").getChildByName("Ruzhi").active = true; + } + } + } cc.fx.GameConfig.GM_INFO.addLevel += 1; if (cc.fx.GameConfig.GM_INFO.addLevel > 5) { cc.fx.GameConfig.GM_INFO.addLevel = 5; @@ -4368,6 +4382,46 @@ export default class MapConroler extends cc.Component { this.hitSoundTime = Date.now(); // 记录当前播放时间 } + runAuthorize() { + this.node.parent.parent.getChildByName("Win").getChildByName("Ruzhi").active = false; + console.log("点击授权了"); + // 获取CareerList组件实例 + MiniGameSdk.API.getWechatCityInfo((success, data, error) => { + console.log("解析地址:", success, data, error); + if (success) { + console.log('详细城市信息:', data); + console.log("给用户移动到他所在的区域"); + if (data != null && data != "" && data != undefined) cc.fx.GameConfig.GM_INFO.address = data; + let nowTime = Math.floor(Date.now() / 1000); + let addressInfo = { + address: data, + time: nowTime, + authorize: true + } + //缓存地址 + cc.fx.StorageMessage.setStorage("address", addressInfo); + Utils.setCityInfo(null, cc.fx.GameConfig.GM_INFO.address, true) + // 在需要的地方调用 + // 滚动到其他城市(自定义位置和动画时间) + if (cc.fx.GameConfig.GM_INFO.address == "") { + cc.fx.GameConfig.GM_INFO.address = "其他"; + } + } + else { + // cc.fx.StorageMessage.setStorage("address", cc.fx.GameConfig.GM_INFO.address); + cc.fx.GameConfig.GM_INFO.address = "其他"; + let nowTime = Math.floor(Date.now() / 1000); + let addressInfo = { + address: cc.fx.GameConfig.GM_INFO.address, + time: nowTime, + authorize: false + } + cc.fx.StorageMessage.setStorage("address", addressInfo); + Utils.setFailCityInfo(); + } + }, true); // 第二个参数设为true启用逆解析 + } + update(dt) { // 检测连击超时,如果超过3秒没有播放音效,重置连击计数 if (this.hitSoundCount > 0 && this.hitSoundTime && Date.now() - this.hitSoundTime > 3000) { diff --git a/assets/Script/Sdk/MiniGameSdk.ts b/assets/Script/Sdk/MiniGameSdk.ts index 9397894..d83aba1 100644 --- a/assets/Script/Sdk/MiniGameSdk.ts +++ b/assets/Script/Sdk/MiniGameSdk.ts @@ -1,4 +1,5 @@ import Utils from "../module/Pay/Utils"; +import { getProvinceName } from "../module/Position/GetPosition"; // import { getProvinceName } from "../module/Position/ProvinceLocator"; /** @@ -1942,12 +1943,13 @@ export namespace MiniGameSdk { API._getCityInfo(callback, useReverseGeocoding); } else { callback(false, null, '用户拒绝授权位置权限'); - API._setCityInfo(null, useReverseGeocoding); + Utils.setFailCityInfo(); } }, fail: (err) => { console.log('打开设置失败:', err); - API._setCityInfo(callback, useReverseGeocoding); + callback(false, null, '用户拒绝授权位置权限'); + Utils.setFailCityInfo(); } }); } @@ -1976,26 +1978,19 @@ export namespace MiniGameSdk { type: 'wgs84', // 使用国测局坐标系,更适合中国地图 success: (res) => { console.log('获取位置成功:', res); - if (useReverseGeocoding) { // 使用逆解析获取详细地址信息 API._reverseGeocoding(res.latitude, res.longitude, callback); } else { // 直接返回基本位置信息,包含经纬度 - const cityInfo = { - latitude: res.latitude, // 纬度 - longitude: res.longitude, // 经度 - province: '', // 省份(需要通过逆解析获取) - city: '', // 城市(需要通过逆解析获取) - district: '', // 区县(需要通过逆解析获取) - address: '' // 详细地址(需要通过逆解析获取) - }; + const cityInfo = "其他"; callback(true, cityInfo); } }, fail: (err) => { console.log('获取位置失败:', err); - API._setCityInfo(callback, useReverseGeocoding); + callback(false, null, '用户拒绝授权位置权限'); + Utils.setFailCityInfo(); // 处理错误码102:位置服务不可用 if (err.errCode === 102) { // 错误码102的常见原因和解决方案: @@ -2030,67 +2025,65 @@ export namespace MiniGameSdk { }); } - private static _setCityInfo(callback: (success: boolean, data?: any, error?: any) => void, useReverseGeocoding: boolean) { - //@ts-ignore - // let cityData = data; - Utils.setCityInfo(callback, data); - } + /** * 逆解析经纬度获取详细地址信息 */ private static _reverseGeocoding(latitude: number, longitude: number, callback: (success: boolean, data?: any, error?: any) => void) { //@ts-ignore - // if (typeof wx !== "undefined" && wx.getLocation) { + if (typeof wx !== "undefined" && wx.getLocation) { - // const lat = latitude; - // const lng = longitude; + let lat = latitude; + let lng = longitude; + const province = getProvinceName(lat, lng); - // const province = getProvinceName(lat, lng); - // console.log("玩家省份:", province); + console.log("玩家省份1:", province); + let cityInfo = this.getCityChange(province); + callback(true, cityInfo); + // TODO: 这里写你的逻辑:埋点、排行榜、活动分组等 - // // TODO: 这里写你的逻辑:埋点、排行榜、活动分组等 + } else { + // 非微信环境(比如 Cocos 预览),用个测试坐标 + const province = getProvinceName(39.9, 116.4); + console.log("测试坐标所在省份:", province); + let cityInfo = this.getCityChange(province); + callback(true, cityInfo); + } - // } else { - // // 非微信环境(比如 Cocos 预览),用个测试坐标 - // const province = getProvinceName(39.9, 116.4); - // console.log("测试坐标所在省份:", province); - // } - - - const key = '6PPBZ-VBEHW-XE3RU-3XNC5-TQH6H-KLBTF'; // 需要替换为实际的key - const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}&get_poi=0`; - // 注意:微信小游戏本身不提供逆解析API,需要调用第三方服务或自己的服务器 - // 这里提供一个示例,实际使用时需要替换为你的服务器接口 - //@ts-ignore - wx.request({ - url: url, - method: 'GET', - success: (res) => { - if (res.statusCode === 200 && res.data.status === 0) { - const result = res.data.result; - const cityInfo = { - latitude: latitude, - longitude: longitude, - province: result.address_component.province, // 省份 - city: result.address_component.city, // 城市 - district: result.address_component.district, // 区县 - address: result.address, // 详细地址 - formatted_address: result.formatted_addresses?.recommend || result.address // 格式化地址 - }; - console.log('逆解析成功:', cityInfo); - callback(true, cityInfo); - } else { - console.log('逆解析失败:', res.data); - callback(true, null, '逆解析失败'); - } - }, - fail: (err) => { - console.log('逆解析请求失败:', err); - callback(true, null, '逆解析请求失败'); - } - }); + // const key = '6PPBZ-VBEHW-XE3RU-3XNC5-TQH6H-KLBTF'; // 需要替换为实际的key + // const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}&get_poi=0`; + // // 注意:微信小游戏本身不提供逆解析API,需要调用第三方服务或自己的服务器 + // // 这里提供一个示例,实际使用时需要替换为你的服务器接口 + // //@ts-ignore + // wx.request({ + // url: url, + // method: 'GET', + // success: (res) => { + // if (res.statusCode === 200 && res.data.status === 0) { + // const result = res.data.result; + // const cityInfo = { + // latitude: latitude, + // longitude: longitude, + // province: result.address_component.province, // 省份 + // city: result.address_component.city, // 城市 + // district: result.address_component.district, // 区县 + // address: result.address, // 详细地址 + // formatted_address: result.formatted_addresses?.recommend || result.address // 格式化地址 + // }; + // console.log('逆解析成功:', cityInfo); + // callback(true, cityInfo); + // } else { + // console.log('逆解析失败:', res.data); + // callback(true, null, '逆解析失败'); + // } + // }, + // fail: (err) => { + // console.log('逆解析请求失败:', err); + // callback(true, null, '逆解析请求失败'); + // } + // }); } /** @@ -2159,6 +2152,24 @@ export namespace MiniGameSdk { return ''; } + private static getCityChange(city) { + if (city == "未知") { + city = "其他"; + } + else if (city == "北京市" || city == "天津市" || city == "上海市" || city == "重庆市" || city == "广西自治区" || city == "西藏自治区" + || city == "宁夏回族自治区" || city == "新疆维吾尔自治区" + ) { + city = city.substring(0, 2); + } + else if (city == "内蒙古自治区") { + city = "内蒙古"; + } + else if (city == "台湾省" || city == "香港特别行政区" || city == "澳门特别行政区") { + city = "港澳台"; + } + return city; + } + /** * 获取用户IP地址对应的城市信息(不需要位置权限) * @param callback 回调函数 diff --git a/assets/Script/module/Pay/Utils.ts b/assets/Script/module/Pay/Utils.ts index 9c104e7..71e0840 100644 --- a/assets/Script/module/Pay/Utils.ts +++ b/assets/Script/module/Pay/Utils.ts @@ -1342,7 +1342,36 @@ export default class Utils { } } - static setCityInfo(callBack, data) { + static setCityInfo(callBack, data, useReverseGeocoding) { + //@ts-ignore + if (typeof wx !== 'undefined' && wx !== null) { + let uid = cc.fx.StorageMessage.getStorage("uid"); + //旧的读取数据设置数据方法,以强联网为主 + if (uid != undefined && uid != "" && uid != null) { + cc.fx.GameConfig.GM_INFO.uid = uid; + } + + let setData = { + uid: cc.fx.GameConfig.GM_INFO.uid, + action: 'save', + address: data, + } + if (useReverseGeocoding == false) { + setData.address = "其他"; + } + console.log("设置城市信息数据:", setData); + Utils.POST("address", setData, res => { + if (res.code === 1) { + console.log("设置城市信息成功", res); + if (callBack) callBack(res); + } else { + console.log("设置城市信息失败", res); + } + }) + } + } + + static setFailCityInfo() { //@ts-ignore if (typeof wx !== 'undefined' && wx !== null) { let uid = cc.fx.StorageMessage.getStorage("uid"); @@ -1359,7 +1388,6 @@ export default class Utils { Utils.POST("address", setData, res => { if (res.code === 1) { console.log("设置城市信息成功", res); - if (callBack) callBack(res); } else { console.log("设置城市信息失败", res); } diff --git a/assets/Script/module/Position/GetPosition.ts b/assets/Script/module/Position/GetPosition.ts new file mode 100644 index 0000000..67c5334 --- /dev/null +++ b/assets/Script/module/Position/GetPosition.ts @@ -0,0 +1,109 @@ +// import { JsonAsset, BufferAsset, resources } from "cc"; + +type MetaType = { + MIN_LAT: number; + MAX_LAT: number; + MIN_LNG: number; + MAX_LNG: number; + STEP_DEG: number; + ROWS: number; + COLS: number; + id2name: Record; +}; + +let _ready = false; +let _meta: MetaType | null = null; +let _grid: Uint8Array | null = null; +let _ID2NAME: Record = {}; + +/** + * 初始化省份定位(游戏启动时调一次) + * pathJson: resources 下的 json 路径,不含扩展名 + * pathBin: resources 下的 bin 路径,不含扩展名 + */ +export function initProvinceLocator( + pathJson: string = "geo/province_names", + pathBin: string = "geo/province_grid" +): Promise { + return new Promise((resolve, reject) => { + // 1. 先加载 meta json + cc.resources.load(pathJson, cc.JsonAsset, (err, jsonAsset) => { + if (err) { + console.error("[ProvinceLocator] 加载 JSON 失败", err); + reject(err); + return; + } + //@ts-ignore + const meta = jsonAsset.json as MetaType; + + // 2. 再加载二进制网格 + cc.resources.load(pathBin, cc.BufferAsset, (err2, bufAsset) => { + if (err2) { + console.error("[ProvinceLocator] 加载 BIN 失败", err2); + reject(err2); + return; + } + + // BufferAsset 的底层数据在 _nativeAsset 里,是 ArrayBuffer + const arrayBuffer = (bufAsset as any)._nativeAsset as ArrayBuffer; + const grid = new Uint8Array(arrayBuffer); + + _meta = meta; + _grid = grid; + _ID2NAME = {}; + for (const k in meta.id2name) { + _ID2NAME[parseInt(k, 10)] = meta.id2name[k]; + } + + _ready = true; + console.log( + "[ProvinceLocator] 初始化成功,网格大小", + meta.ROWS, + "x", + meta.COLS + ); + resolve(); + }); + }); + }); +} + +/** + * 根据经纬度返回省份名称 + * 调用前务必先 initProvinceLocator + */ +export function getProvinceName(lat: number, lng: number): string { + if (!_ready || !_meta || !_grid) { + console.warn("[ProvinceLocator] 尚未初始化,返回未知"); + return "未知"; + } + + const { + MIN_LAT, + MAX_LAT, + MIN_LNG, + MAX_LNG, + STEP_DEG, + ROWS, + COLS, + } = _meta; + + if (lat < MIN_LAT || lat > MAX_LAT || lng < MIN_LNG || lng > MAX_LNG) { + return "未知或海外"; + } + + let r = Math.floor((lat - MIN_LAT) / STEP_DEG); + let c = Math.floor((lng - MIN_LNG) / STEP_DEG); + + // 边界保护 + if (r < 0) r = 0; + if (r >= ROWS) r = ROWS - 1; + if (c < 0) c = 0; + if (c >= COLS) c = COLS - 1; + + const index = r * COLS + c; + const pid = _grid[index]; + + if (!pid) return "未知"; + return _ID2NAME[pid] || "未知"; +} \ No newline at end of file diff --git a/assets/Script/module/Position/GetPosition.ts.meta b/assets/Script/module/Position/GetPosition.ts.meta new file mode 100644 index 0000000..2ce81c5 --- /dev/null +++ b/assets/Script/module/Position/GetPosition.ts.meta @@ -0,0 +1,10 @@ +{ + "ver": "1.1.0", + "uuid": "39f51946-fe1c-426a-9cf3-fceabfda5d6c", + "importer": "typescript", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/Script/module/Tool/GameTool.ts b/assets/Script/module/Tool/GameTool.ts index bb38769..ad5c0d4 100644 --- a/assets/Script/module/Tool/GameTool.ts +++ b/assets/Script/module/Tool/GameTool.ts @@ -399,8 +399,8 @@ var GameTool = { //关卡上限 maxLevel() { let jg = false; - if (cc.fx.GameConfig.GM_INFO.level > 649) { - cc.fx.GameConfig.GM_INFO.level = 650; + if (cc.fx.GameConfig.GM_INFO.level > 669) { + cc.fx.GameConfig.GM_INFO.level = 670; jg = true; } return jg; diff --git a/assets/resources/geo.meta b/assets/resources/geo.meta new file mode 100644 index 0000000..5de4678 --- /dev/null +++ b/assets/resources/geo.meta @@ -0,0 +1,13 @@ +{ + "ver": "1.1.3", + "uuid": "bca08d20-e9bc-4e38-99ce-ffeb89bd5ab2", + "importer": "folder", + "isBundle": false, + "bundleName": "", + "priority": 1, + "compressionType": {}, + "optimizeHotUpdate": {}, + "inlineSpriteFrames": {}, + "isRemoteBundle": {}, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/resources/geo/province_grid.bin b/assets/resources/geo/province_grid.bin new file mode 100644 index 0000000..fbe6681 Binary files /dev/null and b/assets/resources/geo/province_grid.bin differ diff --git a/assets/resources/geo/province_grid.bin.meta b/assets/resources/geo/province_grid.bin.meta new file mode 100644 index 0000000..a10914a --- /dev/null +++ b/assets/resources/geo/province_grid.bin.meta @@ -0,0 +1,6 @@ +{ + "ver": "1.0.2", + "uuid": "678dd3a2-f376-45a1-aadd-79709550c901", + "importer": "buffer", + "subMetas": {} +} \ No newline at end of file diff --git a/assets/resources/geo/province_names.json b/assets/resources/geo/province_names.json new file mode 100644 index 0000000..597b35d --- /dev/null +++ b/assets/resources/geo/province_names.json @@ -0,0 +1,45 @@ +{ + "MIN_LAT": 18.0, + "MAX_LAT": 54.0, + "MIN_LNG": 73.0, + "MAX_LNG": 135.0, + "STEP_DEG": 0.125, + "ROWS": 288, + "COLS": 496, + "id2name": { + "1": "北京市", + "2": "天津市", + "3": "河北省", + "4": "山西省", + "5": "内蒙古自治区", + "6": "辽宁省", + "7": "吉林省", + "8": "黑龙江省", + "9": "上海市", + "10": "江苏省", + "11": "浙江省", + "12": "安徽省", + "13": "福建省", + "14": "江西省", + "15": "山东省", + "16": "河南省", + "17": "湖北省", + "18": "湖南省", + "19": "广东省", + "20": "广西壮族自治区", + "21": "海南省", + "22": "重庆市", + "23": "四川省", + "24": "贵州省", + "25": "云南省", + "26": "西藏自治区", + "27": "陕西省", + "28": "甘肃省", + "29": "青海省", + "30": "宁夏回族自治区", + "31": "新疆维吾尔自治区", + "32": "台湾省", + "33": "香港特别行政区", + "34": "澳门特别行政区" + } +} \ No newline at end of file diff --git a/assets/resources/geo/province_names.json.meta b/assets/resources/geo/province_names.json.meta new file mode 100644 index 0000000..946a080 --- /dev/null +++ b/assets/resources/geo/province_names.json.meta @@ -0,0 +1,6 @@ +{ + "ver": "1.0.2", + "uuid": "14ca6166-da19-4045-b3b0-44750317e9c7", + "importer": "json", + "subMetas": {} +} \ No newline at end of file