From 7f5c11c102d90b04d8963d83f68253bd025e2f71 Mon Sep 17 00:00:00 2001 From: "COMPUTER\\EDY" <249929363@qq.com> Date: Mon, 17 Nov 2025 14:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=9E=8D=E5=90=88=20=E5=90=8E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scene/GameScene.fire | 8 +- assets/Scene/HomeScene.fire | 127 +++++++++------- assets/Script/JiaZai.ts | 90 ++++++++---- assets/Script/Map.ts | 54 +++++++ assets/Script/Sdk/MiniGameSdk.ts | 135 ++++++++++-------- assets/Script/module/Pay/Utils.ts | 32 ++++- assets/Script/module/Position/GetPosition.ts | 109 ++++++++++++++ .../module/Position/GetPosition.ts.meta | 10 ++ assets/Script/module/Tool/GameTool.ts | 4 +- assets/resources/geo.meta | 13 ++ assets/resources/geo/province_grid.bin | Bin 0 -> 142848 bytes assets/resources/geo/province_grid.bin.meta | 6 + assets/resources/geo/province_names.json | 45 ++++++ assets/resources/geo/province_names.json.meta | 6 + 14 files changed, 495 insertions(+), 144 deletions(-) create mode 100644 assets/Script/module/Position/GetPosition.ts create mode 100644 assets/Script/module/Position/GetPosition.ts.meta create mode 100644 assets/resources/geo.meta create mode 100644 assets/resources/geo/province_grid.bin create mode 100644 assets/resources/geo/province_grid.bin.meta create mode 100644 assets/resources/geo/province_names.json create mode 100644 assets/resources/geo/province_names.json.meta 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 0000000000000000000000000000000000000000..fbe6681cd1b205f37a238a6b09574ebe9c0fc934 GIT binary patch literal 142848 zcmeI)3!Bua(g5IIJ+8azI*#iZ?>gW2|9|A6fPw<5xFm$o-Q?MwKtXQ2DU$9{FPF8f z5m+OzM&M3I;J>ik>9ybAWozvvekbrwd!_h&h*R)2so%VLz`dU0%lqa>;Jz*}%I`I! z-#CA@_qr2q;!ddczKN?{7jd~n;%i85eFPTxtqaH37mCNNtA1l65OS{dNxkK^@RTb)3)Bv zxjw6{W&}dmYz=n@U!T@41UFYKd^Sh!XFP?q-Z}zV;jqyhqE_1U%OMACx$}42Yevrv zQ>iV~tf;{b+ql{9Rs&~O$(^kS&-Geu`4OlPj=QJ_c^kOnEEh5->%E^dy;f6x1Y*p} zdJ}k=+4qni;>$ZPS=Uq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+vh6GH3D8+omZ7^+9~y( z>l)YDh$E0fNHLC46 z=RM#%4!brzYXsWC?Sy{T39sYs8i8hSe17jb>e~3U5s<+_R)5*zzHd=|k$e3{>@=~R z2Nu9RtSOmpF1queYxC1apwc_~TPCNS?mF<^5n#bxA`6AR2VL8rI0B5gz>MJ&Pj(%; z!w4ke2+OZK9C7X9)Deild1etse7_fCn$k>GNO8I>V|Fu;P4Dt0?@Xz^WasPS-O6QgUC<6|6IDAAu;x Z+jp?GSR=4TV2!{Ufi(ha1a5T%{s;3uldAv# literal 0 HcmV?d00001 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