cocos creator 通过uuid查找对应的文件

 1 for (
 2     var e = require("node-uuid"),
 3       t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
 4       r = new Array(128),
 5       i = 0;
 6     i < 128;
 7     ++i
 8   )
 9     r[i] = 0;
10   for (i = 0; i < 64; ++i) r[t.charCodeAt(i)] = i;
11   const n = /-/g,
12     s = /^[0-9a-fA-F-]{36}$/,
13     o = /^[0-9a-fA-F]{32}$/,
14     u = /^[0-9a-zA-Z+/]{22,23}$/,
15     a = /.*[/\\][0-9a-fA-F]{2}[/\\]([0-9a-fA-F-]{8,})/;
16   var c = {
17     Reg_UuidInLibPath: a,
18     NonUuidMark: ".",
19     compressUuid: function (e, t) {
20       if (s.test(e)) e = e.replace(n, "");
21       else if (!o.test(e)) return e;
22       var r = !0 === t ? 2 : 5;
23       return c.compressHex(e, r);
24     },
25     compressHex: function (e, r) {
26       var i,
27         n = e.length;
28       i = void 0 !== r ? r : n % 3;
29       for (var s = e.slice(0, i), o = []; i < n; ) {
30         var u = parseInt(e[i], 16),
31           a = parseInt(e[i + 1], 16),
32           c = parseInt(e[i + 2], 16);
33         o.push(t[(u << 2) | (a >> 2)]), o.push(t[((3 & a) << 4) | c]), (i += 3);
34       }
35       return s + o.join("");
36     },
37     decompressUuid: function (e) {
38       if (23 === e.length) {
39         let t = [];
40         for (let i = 5; i < 23; i += 2) {
41           let n = r[e.charCodeAt(i)],
42             s = r[e.charCodeAt(i + 1)];
43           t.push((n >> 2).toString(16)),
44             t.push((((3 & n) << 2) | (s >> 4)).toString(16)),
45             t.push((15 & s).toString(16));
46         }
47         e = e.slice(0, 5) + t.join("");
48       } else {
49         if (22 !== e.length) return e;
50         {
51           let t = [];
52           for (let i = 2; i < 22; i += 2) {
53             let n = r[e.charCodeAt(i)],
54               s = r[e.charCodeAt(i + 1)];
55             t.push((n >> 2).toString(16)),
56               t.push((((3 & n) << 2) | (s >> 4)).toString(16)),
57               t.push((15 & s).toString(16));
58           }
59           e = e.slice(0, 2) + t.join("");
60         }
61       }
62       return [
63         e.slice(0, 8),
64         e.slice(8, 12),
65         e.slice(12, 16),
66         e.slice(16, 20),
67         e.slice(20),
68       ].join("-");
69     },
70     isUuid: function (e) {
71       return u.test(e) || o.test(e) || s.test(e);
72     },
73     getUuidFromLibPath(e) {
74       var t = e.match(a);
75       return t ? t[1] : "";
76     },
77     uuid: function () {
78       var t = e.v4();
79       return c.compressUuid(t, !0);
80     },
81   };
82 
83 // console.log(c.uuid());
84 console.log(c.decompressUuid("9b5c7tWwo1G27PRicov4DIX"));

 

posted @ 2022-04-20 21:51  Please Call me 小强  阅读(1005)  评论(0编辑  收藏  举报