-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from 54145a/main
- Loading branch information
Showing
7 changed files
with
383 additions
and
1,734 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* !Info {Project} -来自145a | ||
* 145powerTag 1.1 | ||
*/ | ||
world.querySelectorAll(".powerTag").forEach(entity=>{ | ||
entity.tags().forEach(tag=>{ | ||
if(tag[0]="?"){ | ||
const entry = tag.slice(1).split("="); | ||
entity[entry[0]] = eval(entry[1]); | ||
entity.removeTag(tag); | ||
} | ||
}); | ||
}); | ||
//请勿删除最后一行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* !Info {Module} -来自145a | ||
* 145terrain 1.0 | ||
*/ | ||
class Terrain { | ||
constructor() { | ||
this.data = []; | ||
} | ||
/** | ||
* @param {GameVector3} spot | ||
*/ | ||
at(spot){ | ||
if(!this.data[spot.x]||!this.data[spot.x][spot.y])return 0; | ||
return this.data[spot.x][spot.y][spot.z]; | ||
} | ||
/** | ||
* @param {GameBounds3} bounds | ||
*/ | ||
read(bounds) { | ||
for (let x = 0; x < bounds.hi.x - bounds.lo.x; x++) { | ||
this.data[x] = []; | ||
for (let y = 0; y < bounds.hi.y - bounds.lo.y; y++) { | ||
this.data[x][y] = []; | ||
for (let z = 0; z < bounds.hi.z - bounds.lo.z; z++) { | ||
this.data[x][y][z] = voxels.getVoxelId(x + bounds.lo.x, y + bounds.lo.y, z + bounds.lo.z); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* @param {GameBounds3} bounds | ||
*/ | ||
write(bounds) { | ||
for (let x = 0; x < bounds.hi.x - bounds.lo.x; x++) { | ||
for (let y = 0; y < bounds.hi.y - bounds.lo.y; y++) { | ||
for (let z = 0; z < bounds.hi.z - bounds.lo.z; z++) { | ||
voxels.setVoxelId(x + bounds.lo.x, y + bounds.lo.y, z + bounds.lo.z, this.data[x][y][z]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* @param {GameBounds3} bounds | ||
*/ | ||
voxels.clear = function (bounds) { | ||
for (let x = 0; x < bounds.hi.x - bounds.lo.x; x++) { | ||
for (let y = 0; y < bounds.hi.y - bounds.lo.y; y++) { | ||
for (let z = 0; z < bounds.hi.z - bounds.lo.z; z++) { | ||
voxels.setVoxel(x + bounds.lo.x, y + bounds.lo.y, z + bounds.lo.z, 0); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* @param {GameBounds3} bounds | ||
*/ | ||
voxels.read = function (bounds) { | ||
let terrain = new Terrain(); | ||
terrain.read(bounds); | ||
return terrain; | ||
} | ||
/** | ||
* @param {GameBounds3} bounds | ||
* @param {Terrain} terrain | ||
*/ | ||
voxels.write = function (bounds, terrain) { | ||
terrain.write(bounds); | ||
} | ||
//请勿删除最后一行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* !Info {Module} -来自145a | ||
* 145Storage 3.2 | ||
*/ | ||
/** | ||
* 缓冲时间,防止http报错429 | ||
* @type {number} | ||
*/ | ||
storage.REQUEST_MIN_INTERVAL = 64; | ||
/** | ||
* 初始化云属性 | ||
* @param {object} host | ||
* @param {string} key | ||
* @param {any} defaultValue | ||
* @param {function(JSONValue)} updater | ||
*/ | ||
storage.setupCloudVariable = async function (host, key, defaultValue, updater) { | ||
const cacheKey = `_${key}_cache`; | ||
const isWaitingKey = `_${key}_isWaiting`; | ||
const scheduleUpdateKey = `_${key}_scheduleUpdate`; | ||
host[cacheKey] = defaultValue; | ||
host[isWaitingKey] = false; | ||
host[scheduleUpdateKey] = async function () { | ||
if (host[isWaitingKey]) return; | ||
host[isWaitingKey] = true; | ||
await sleep(storage.REQUEST_MIN_INTERVAL); | ||
host[isWaitingKey] = false; | ||
updater(host[cacheKey]); | ||
} | ||
if (typeof host[cacheKey] === "object") { | ||
host[key] = new Proxy(host[cacheKey], { | ||
set(target, property, value, receiver) { | ||
Reflect.set(target, property, value, receiver); | ||
host[scheduleUpdateKey](); | ||
return true; | ||
} | ||
}); | ||
} else { | ||
Object.defineProperty(host, key, { | ||
get() { | ||
return host[cacheKey]; | ||
}, | ||
set(value) { | ||
host[cacheKey] = value; | ||
host[scheduleUpdateKey](); | ||
return true; | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* @typedef {function(a,b):number} Sorter | ||
* @type {Object<Sorter>} | ||
*/ | ||
Array.SorterType = { | ||
DESC: (a, b) => b - a, | ||
ASC: (a, b) => a - b | ||
} | ||
/** | ||
* 初始化一个145DataStorage | ||
* @param {String} name | ||
* @param {JSONValue} defaultUserData 用户默认属性和数据类型 | ||
* @returns {GameDataStorage} | ||
*/ | ||
storage.get145DataStorage = function (name, defaultUserData) { | ||
let host = storage.getDataStorage(name); | ||
Object.assign(defaultUserData, { | ||
name: "游客",//此项不可删除 | ||
joinTimes: 0,//此项不可删除 | ||
}); | ||
/** | ||
* 为用户初始化 | ||
* @param {GamePlayerEntity} user | ||
*/ | ||
host.setupUser = async function (user) { | ||
if (!user || !user.isPlayer) throw `setupUser的参数不太对劲`; | ||
if (!user.player.userId) return; | ||
let dataStorage = this; | ||
const data = await dataStorage.get(user.player.userId); | ||
if (!data) { | ||
await dataStorage.set(user.player.userId, defaultUserData); | ||
return await dataStorage.setupUser(user); | ||
} | ||
user._isPreparingUpdate_ = false; | ||
user._storageUpdateCache_ = {}; | ||
Object.keys(defaultUserData).forEach(key => { | ||
if(typeof data.value[key] !== typeof defaultUserData[key]){ | ||
data.value[key] = defaultUserData[key]; | ||
} | ||
user._storageUpdateCache_[key] = data.value[key]; | ||
storage.setupCloudVariable(user, key, data.value[key], async (value) => { | ||
user._storageUpdateCache_[key] = value; | ||
if (user._isPreparingUpdate_) return; | ||
user._isPreparingUpdate_ = true; | ||
await sleep(storage.REQUEST_MIN_INTERVAL); | ||
dataStorage.set(user.player.userId, user._storageUpdateCache_); | ||
user._isPreparingUpdate_ = false; | ||
}); | ||
}); | ||
user.name = user.player.name; | ||
user.joinTime += 1; | ||
} | ||
/** | ||
* 获取排行榜 | ||
* {@link Array.SorterType} | ||
* @param {string} type | ||
* @param {string} displayType | ||
* @param {number} num | ||
* @param {Sorter} sorter | ||
*/ | ||
host.getRank = async function (type, displayType, num = 10, sorter) { | ||
let data = (await this.list({ | ||
cursor: 0, | ||
pageSize: Number.MAX_SAFE_INTEGER - 1 | ||
})).getCurrentPage().map(v => ({ | ||
key: v.key, | ||
value: v.value | ||
})).filter(v=>!["null","undefined"].includes(typeof v.value[type])); | ||
data.sort((a, b) => sorter(a.value[type], b.value[type])); | ||
let result = `用户名 ${displayType}\n` + data.slice(0, num).map((v) => `${v.value.name} ${v.value[type]}`).join("\n"); | ||
return result; | ||
} | ||
return host; | ||
} | ||
//请勿删除最后一行 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.