融合 后更新

This commit is contained in:
COMPUTER\EDY 2025-11-17 14:35:04 +08:00
parent a075de538c
commit 7f5c11c102
14 changed files with 495 additions and 144 deletions

View File

@ -18688,10 +18688,12 @@
}, },
{ {
"__type__": "cc.ClickEvent", "__type__": "cc.ClickEvent",
"target": null, "target": {
"__id__": 76
},
"component": "", "component": "",
"_componentId": "", "_componentId": "2234assp7RIvpDgrnqljp2R",
"handler": "", "handler": "runAuthorize",
"customEventData": "" "customEventData": ""
}, },
{ {

View File

@ -20,7 +20,7 @@
"__id__": 5 "__id__": 5
}, },
{ {
"__id__": 529 "__id__": 530
} }
], ],
"_active": false, "_active": false,
@ -286,22 +286,22 @@
"__id__": 479 "__id__": 479
}, },
{ {
"__id__": 512 "__id__": 513
}, },
{ {
"__id__": 517 "__id__": 518
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 526
},
{ {
"__id__": 527 "__id__": 527
}, },
{ {
"__id__": 528 "__id__": 528
},
{
"__id__": 529
} }
], ],
"_prefab": null, "_prefab": null,
@ -21058,9 +21058,13 @@
} }
], ],
"_active": false, "_active": false,
"_components": [], "_components": [
{
"__id__": 511
}
],
"_prefab": { "_prefab": {
"__id__": 511 "__id__": 512
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -21117,7 +21121,7 @@
"__id__": 479 "__id__": 479
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 481 "__id__": 481
@ -21132,7 +21136,7 @@
"_prefab": { "_prefab": {
"__id__": 484 "__id__": 484
}, },
"_opacity": 210, "_opacity": 200,
"_color": { "_color": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 0, "r": 0,
@ -21142,8 +21146,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 1180, "width": 1080,
"height": 2340 "height": 1920
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -21221,11 +21225,11 @@
"_enabled": true, "_enabled": true,
"alignMode": 1, "alignMode": 1,
"_target": null, "_target": null,
"_alignFlags": 40, "_alignFlags": 45,
"_left": -50, "_left": 0,
"_right": -50, "_right": 0,
"_top": -210, "_top": 0,
"_bottom": -210, "_bottom": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_isAbsLeft": true, "_isAbsLeft": true,
@ -22233,6 +22237,33 @@
"fileId": "cdCj6iBydMHLooCJU2lGg3", "fileId": "cdCj6iBydMHLooCJU2lGg3",
"sync": false "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", "__type__": "cc.PrefabInfo",
"root": { "root": {
@ -22253,13 +22284,13 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 513 "__id__": 514
} }
], ],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 516 "__id__": 517
} }
], ],
"_prefab": null, "_prefab": null,
@ -22315,16 +22346,16 @@
"_name": "New Sprite(Splash)", "_name": "New Sprite(Splash)",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 512 "__id__": 513
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 514 "__id__": 515
}, },
{ {
"__id__": 515 "__id__": 516
} }
], ],
"_prefab": null, "_prefab": null,
@ -22380,7 +22411,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 513 "__id__": 514
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -22412,7 +22443,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 513 "__id__": 514
}, },
"_enabled": true, "_enabled": true,
"_id": "59BOMZmhdPJajqBGyoUDBU" "_id": "59BOMZmhdPJajqBGyoUDBU"
@ -22422,7 +22453,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 512 "__id__": 513
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -22468,19 +22499,19 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 518 "__id__": 519
}, },
{ {
"__id__": 521 "__id__": 522
}, },
{ {
"__id__": 523 "__id__": 524
} }
], ],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 525 "__id__": 526
} }
], ],
"_prefab": null, "_prefab": null,
@ -22536,16 +22567,16 @@
"_name": "New Sprite(Splash)", "_name": "New Sprite(Splash)",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 517 "__id__": 518
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 519 "__id__": 520
}, },
{ {
"__id__": 520 "__id__": 521
} }
], ],
"_prefab": null, "_prefab": null,
@ -22601,7 +22632,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 518 "__id__": 519
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -22633,7 +22664,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 518 "__id__": 519
}, },
"_enabled": true, "_enabled": true,
"_id": "f7VWpZp11LWprv6A8lnYhR" "_id": "f7VWpZp11LWprv6A8lnYhR"
@ -22643,13 +22674,13 @@
"_name": "load", "_name": "load",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 517 "__id__": 518
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 522 "__id__": 523
} }
], ],
"_prefab": null, "_prefab": null,
@ -22705,7 +22736,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 521 "__id__": 522
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -22737,13 +22768,13 @@
"_name": "New Label", "_name": "New Label",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 517 "__id__": 518
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 524 "__id__": 525
} }
], ],
"_prefab": null, "_prefab": null,
@ -22799,7 +22830,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 523 "__id__": 524
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -22832,7 +22863,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 517 "__id__": 518
}, },
"_enabled": true, "_enabled": true,
"alignMode": 1, "alignMode": 1,
@ -22966,14 +22997,14 @@
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 530
},
{ {
"__id__": 531 "__id__": 531
}, },
{ {
"__id__": 532 "__id__": 532
},
{
"__id__": 533
} }
], ],
"_prefab": null, "_prefab": null,
@ -23029,7 +23060,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 529 "__id__": 530
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -23062,7 +23093,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 529 "__id__": 530
}, },
"_enabled": true, "_enabled": true,
"alignMode": 1, "alignMode": 1,
@ -23089,11 +23120,11 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 529 "__id__": 530
}, },
"_enabled": true, "_enabled": true,
"uid_Number": { "uid_Number": {
"__id__": 530 "__id__": 531
}, },
"_id": "67zCbKKV9PvYlB9x+eob0L" "_id": "67zCbKKV9PvYlB9x+eob0L"
} }

View File

@ -2506,36 +2506,24 @@ export default class JiaZai extends cc.Component {
// 获取CareerList组件实例 // 获取CareerList组件实例
let careerList = scrollVIew.getComponent("CareerList"); let careerList = scrollVIew.getComponent("CareerList");
let address = cc.fx.StorageMessage.getStorage("address"); let address = cc.fx.StorageMessage.getStorage("address");
//没缓存过,没授权过
if (address == "" || address == null || address == undefined) { if (address == "" || address == null || address == undefined) {
console.log("没有地址"); this.runAuthorize();
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启用逆解析
} }
//缓存,但是没有授权
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 { 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 = "其他"; cc.fx.GameConfig.GM_INFO.address = "其他";
} }
careerList.scrollToCity(cc.fx.GameConfig.GM_INFO.address, 1.0, 0.5); // 1秒动画屏幕30%位置 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() { backTop() {
console.log("给用户移动到列表顶部"); console.log("给用户移动到列表顶部");
let top = this.node.getChildByName("Load").getChildByName("Top"); let top = this.node.getChildByName("Load").getChildByName("Top");

View File

@ -4022,6 +4022,20 @@ export default class MapConroler extends cc.Component {
let Career = this.node.parent.parent.getChildByName("Win").getChildByName("Career"); let Career = this.node.parent.parent.getChildByName("Win").getChildByName("Career");
let progress = Career.getChildByName("progress"); let progress = Career.getChildByName("progress");
let max = false; 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; cc.fx.GameConfig.GM_INFO.addLevel += 1;
if (cc.fx.GameConfig.GM_INFO.addLevel > 5) { if (cc.fx.GameConfig.GM_INFO.addLevel > 5) {
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(); // 记录当前播放时间 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) { update(dt) {
// 检测连击超时如果超过3秒没有播放音效重置连击计数 // 检测连击超时如果超过3秒没有播放音效重置连击计数
if (this.hitSoundCount > 0 && this.hitSoundTime && Date.now() - this.hitSoundTime > 3000) { if (this.hitSoundCount > 0 && this.hitSoundTime && Date.now() - this.hitSoundTime > 3000) {

View File

@ -1,4 +1,5 @@
import Utils from "../module/Pay/Utils"; import Utils from "../module/Pay/Utils";
import { getProvinceName } from "../module/Position/GetPosition";
// import { getProvinceName } from "../module/Position/ProvinceLocator"; // import { getProvinceName } from "../module/Position/ProvinceLocator";
/** /**
@ -1942,12 +1943,13 @@ export namespace MiniGameSdk {
API._getCityInfo(callback, useReverseGeocoding); API._getCityInfo(callback, useReverseGeocoding);
} else { } else {
callback(false, null, '用户拒绝授权位置权限'); callback(false, null, '用户拒绝授权位置权限');
API._setCityInfo(null, useReverseGeocoding); Utils.setFailCityInfo();
} }
}, },
fail: (err) => { fail: (err) => {
console.log('打开设置失败:', err); console.log('打开设置失败:', err);
API._setCityInfo(callback, useReverseGeocoding); callback(false, null, '用户拒绝授权位置权限');
Utils.setFailCityInfo();
} }
}); });
} }
@ -1976,26 +1978,19 @@ export namespace MiniGameSdk {
type: 'wgs84', // 使用国测局坐标系,更适合中国地图 type: 'wgs84', // 使用国测局坐标系,更适合中国地图
success: (res) => { success: (res) => {
console.log('获取位置成功:', res); console.log('获取位置成功:', res);
if (useReverseGeocoding) { if (useReverseGeocoding) {
// 使用逆解析获取详细地址信息 // 使用逆解析获取详细地址信息
API._reverseGeocoding(res.latitude, res.longitude, callback); API._reverseGeocoding(res.latitude, res.longitude, callback);
} else { } else {
// 直接返回基本位置信息,包含经纬度 // 直接返回基本位置信息,包含经纬度
const cityInfo = { const cityInfo = "其他";
latitude: res.latitude, // 纬度
longitude: res.longitude, // 经度
province: '', // 省份(需要通过逆解析获取)
city: '', // 城市(需要通过逆解析获取)
district: '', // 区县(需要通过逆解析获取)
address: '' // 详细地址(需要通过逆解析获取)
};
callback(true, cityInfo); callback(true, cityInfo);
} }
}, },
fail: (err) => { fail: (err) => {
console.log('获取位置失败:', err); console.log('获取位置失败:', err);
API._setCityInfo(callback, useReverseGeocoding); callback(false, null, '用户拒绝授权位置权限');
Utils.setFailCityInfo();
// 处理错误码102位置服务不可用 // 处理错误码102位置服务不可用
if (err.errCode === 102) { if (err.errCode === 102) {
// 错误码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) { private static _reverseGeocoding(latitude: number, longitude: number, callback: (success: boolean, data?: any, error?: any) => void) {
//@ts-ignore //@ts-ignore
// if (typeof wx !== "undefined" && wx.getLocation) { if (typeof wx !== "undefined" && wx.getLocation) {
// const lat = latitude; let lat = latitude;
// const lng = longitude; let lng = longitude;
const province = getProvinceName(lat, lng);
// const province = getProvinceName(lat, lng); console.log("玩家省份1", province);
// console.log("玩家省份:", 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 { // const key = '6PPBZ-VBEHW-XE3RU-3XNC5-TQH6H-KLBTF'; // 需要替换为实际的key
// // 非微信环境(比如 Cocos 预览),用个测试坐标 // const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}&get_poi=0`;
// const province = getProvinceName(39.9, 116.4); // // 注意微信小游戏本身不提供逆解析API需要调用第三方服务或自己的服务器
// console.log("测试坐标所在省份:", province); // // 这里提供一个示例,实际使用时需要替换为你的服务器接口
// } // //@ts-ignore
// wx.request({
// url: url,
const key = '6PPBZ-VBEHW-XE3RU-3XNC5-TQH6H-KLBTF'; // 需要替换为实际的key // method: 'GET',
const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}&get_poi=0`; // success: (res) => {
// 注意微信小游戏本身不提供逆解析API需要调用第三方服务或自己的服务器 // if (res.statusCode === 200 && res.data.status === 0) {
// 这里提供一个示例,实际使用时需要替换为你的服务器接口 // const result = res.data.result;
//@ts-ignore // const cityInfo = {
wx.request({ // latitude: latitude,
url: url, // longitude: longitude,
method: 'GET', // province: result.address_component.province, // 省份
success: (res) => { // city: result.address_component.city, // 城市
if (res.statusCode === 200 && res.data.status === 0) { // district: result.address_component.district, // 区县
const result = res.data.result; // address: result.address, // 详细地址
const cityInfo = { // formatted_address: result.formatted_addresses?.recommend || result.address // 格式化地址
latitude: latitude, // };
longitude: longitude, // console.log('逆解析成功:', cityInfo);
province: result.address_component.province, // 省份 // callback(true, cityInfo);
city: result.address_component.city, // 城市 // } else {
district: result.address_component.district, // 区县 // console.log('逆解析失败:', res.data);
address: result.address, // 详细地址 // callback(true, null, '逆解析失败');
formatted_address: result.formatted_addresses?.recommend || result.address // 格式化地址 // }
}; // },
console.log('逆解析成功:', cityInfo); // fail: (err) => {
callback(true, cityInfo); // console.log('逆解析请求失败:', err);
} else { // callback(true, null, '逆解析请求失败');
console.log('逆解析失败:', res.data); // }
callback(true, null, '逆解析失败'); // });
}
},
fail: (err) => {
console.log('逆解析请求失败:', err);
callback(true, null, '逆解析请求失败');
}
});
} }
/** /**
@ -2159,6 +2152,24 @@ export namespace MiniGameSdk {
return ''; 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地址对应的城市信息 * IP地址对应的城市信息
* @param callback * @param callback

View File

@ -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 //@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) { if (typeof wx !== 'undefined' && wx !== null) {
let uid = cc.fx.StorageMessage.getStorage("uid"); let uid = cc.fx.StorageMessage.getStorage("uid");
@ -1359,7 +1388,6 @@ export default class Utils {
Utils.POST("address", setData, res => { Utils.POST("address", setData, res => {
if (res.code === 1) { if (res.code === 1) {
console.log("设置城市信息成功", res); console.log("设置城市信息成功", res);
if (callBack) callBack(res);
} else { } else {
console.log("设置城市信息失败", res); console.log("设置城市信息失败", res);
} }

View File

@ -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<string, string>;
};
let _ready = false;
let _meta: MetaType | null = null;
let _grid: Uint8Array | null = null;
let _ID2NAME: Record<number, string> = {};
/**
*
* pathJson: resources json
* pathBin: resources bin
*/
export function initProvinceLocator(
pathJson: string = "geo/province_names",
pathBin: string = "geo/province_grid"
): Promise<void> {
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] || "未知";
}

View File

@ -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": {}
}

View File

@ -399,8 +399,8 @@ var GameTool = {
//关卡上限 //关卡上限
maxLevel() { maxLevel() {
let jg = false; let jg = false;
if (cc.fx.GameConfig.GM_INFO.level > 649) { if (cc.fx.GameConfig.GM_INFO.level > 669) {
cc.fx.GameConfig.GM_INFO.level = 650; cc.fx.GameConfig.GM_INFO.level = 670;
jg = true; jg = true;
} }
return jg; return jg;

13
assets/resources/geo.meta Normal file
View File

@ -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": {}
}

Binary file not shown.

View File

@ -0,0 +1,6 @@
{
"ver": "1.0.2",
"uuid": "678dd3a2-f376-45a1-aadd-79709550c901",
"importer": "buffer",
"subMetas": {}
}

View File

@ -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": "澳门特别行政区"
}
}

View File

@ -0,0 +1,6 @@
{
"ver": "1.0.2",
"uuid": "14ca6166-da19-4045-b3b0-44750317e9c7",
"importer": "json",
"subMetas": {}
}