1/* 2 * Copyright (c) 2022-2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15export class XTools { 16 constructor() { } 17 static MOUSE_POS = { 18 x: 0, 19 y: 0, 20 }; 21 static InRect(xx, yy, x, y, w, h) { 22 if (xx < x) return false; 23 if (yy < y) return false; 24 if (xx > x + w) return false; 25 if (yy > y + h) return false; 26 return true; 27 } 28 static PROC_TO = 0; 29 static CONFIG = null; 30 static LoadConfig() { 31 const xhr = new XMLHttpRequest(); 32 xhr.open('GET', "config.json"); 33 xhr.onreadystatechange = () => { 34 if (xhr.readyState === XMLHttpRequest.DONE) { 35 if (xhr.status === 200) { 36 try { 37 XTools.CONFIG = JSON.parse(xhr.responseText); 38 for (let k in XTools.CONFIG.NodeColor) { 39 XTools.CONFIG.NodeColor[k]=parseInt(XTools.CONFIG.NodeColor[k],16); 40 } 41 for (let k in XTools.CONFIG.LineColor) { 42 XTools.CONFIG.LineColor[k]=parseInt(XTools.CONFIG.LineColor[k],16); 43 } 44 } catch (e) { 45 alert('Config file error'); 46 } 47 } else { 48 alert('Failed to load config file'); 49 } 50 } 51 }; 52 xhr.send(); 53 } 54} 55export function fAngle(x, y) { 56 return (Math.atan2(-y, x) * 180) / Math.PI; 57} 58export function iDistance(x, y) { 59 return Math.sqrt(x * x + y * y); 60} 61 62export var timeMs = 0; 63export function freshTime() { 64 let t = new Date(); 65 timeMs = t.getTime(); 66} 67freshTime(); 68export function TimeMS() { 69 let t = new Date(); 70 return t.getTime(); 71} 72export function RandInt(min = 0, max = 100) { 73 return Math.floor(Math.random() * (max - min)) + min; 74} 75 76export function GetURL() { 77 if ('undefined' != typeof wx) { 78 return 'https://7465-testegg-19e3c9-1301193145.tcb.qcloud.la/'; 79 } else return ''; 80} 81