feat:弹幕插件
This commit is contained in:
parent
633d2a7bba
commit
45586df338
@ -1316,9 +1316,10 @@ utils.prototype._unzip_readEntries = function (entries, success, convertToText)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.prototype.http = function (type, url, formData, success, error, mimeType, responseType, onprogress) {
|
utils.prototype.http = function (type, url, formData, success, error, mimeType, responseType, onprogress, timeout) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open(type, url, true);
|
xhr.open(type, url, true);
|
||||||
|
xhr.timeout = timeout;
|
||||||
if (mimeType) xhr.overrideMimeType(mimeType);
|
if (mimeType) xhr.overrideMimeType(mimeType);
|
||||||
if (responseType) xhr.responseType = responseType;
|
if (responseType) xhr.responseType = responseType;
|
||||||
xhr.onload = function (e) {
|
xhr.onload = function (e) {
|
||||||
|
|||||||
@ -159,6 +159,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
|||||||
core.setWeather(weather[0], weather[1]);
|
core.setWeather(weather[0], weather[1]);
|
||||||
else core.setWeather();
|
else core.setWeather();
|
||||||
|
|
||||||
|
core.deleteAllTickers(); // 摧毁所有现存的高级动画
|
||||||
|
|
||||||
// ...可以新增一些其他内容,比如创建个画布在右上角显示什么内容等等
|
// ...可以新增一些其他内容,比如创建个画布在右上角显示什么内容等等
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
@ -3193,6 +3193,38 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
core.registerReplayAction("equip", core.control._replayAction_equip);
|
core.registerReplayAction("equip", core.control._replayAction_equip);
|
||||||
core.registerReplayAction("unEquip", core.control._replayAction_unEquip);
|
core.registerReplayAction("unEquip", core.control._replayAction_unEquip);
|
||||||
},
|
},
|
||||||
|
"FloatingText": function () {
|
||||||
|
// 本插件定义了一些字符绘制相关效果
|
||||||
|
|
||||||
|
const { Animation, linear } = core.plugin.animate;
|
||||||
|
const ctx = 'scrollingText';
|
||||||
|
|
||||||
|
new Animation().ticker.add(() => {
|
||||||
|
core.createCanvas(ctx, 0, 0, core.__PIXELS__, core.__PIXELS__, 200); //每帧重绘该画布
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绘制弹幕
|
||||||
|
* @example
|
||||||
|
* core.plugin.drawCommentStr('OK', 450, 200, 0.1);
|
||||||
|
* @param {string} content 弹幕的内容
|
||||||
|
* @param {number} x 弹幕的初始x坐标
|
||||||
|
* @param {number} y 弹幕的初始y坐标
|
||||||
|
* @param {number} vx 弹幕的横向滚动速度
|
||||||
|
*/
|
||||||
|
this.drawCommentStr = function (content, x, y, vx) {
|
||||||
|
if (core.isReplaying()) return;
|
||||||
|
const ani = new Animation();
|
||||||
|
ani.ticker.add(() => {
|
||||||
|
core.fillText(ctx, content, x + ani.x, y, 'white', '16px Verdana');
|
||||||
|
})
|
||||||
|
ani.mode(linear())
|
||||||
|
.time(600 / vx)
|
||||||
|
.absolute()
|
||||||
|
.move(-600, 0)
|
||||||
|
ani.all().then(() => { ani.ticker.destroy(); });
|
||||||
|
}
|
||||||
|
},
|
||||||
"MenuBase": function () {
|
"MenuBase": function () {
|
||||||
// 本插件定义了一些用于绘制的基类
|
// 本插件定义了一些用于绘制的基类
|
||||||
class ButtonBase {
|
class ButtonBase {
|
||||||
@ -3289,57 +3321,13 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
|
|
||||||
/** 塔的英文名 */
|
/** 塔的英文名 */
|
||||||
const towerName = core.firstData.name;
|
const towerName = core.firstData.name;
|
||||||
let W, H, WIDTH, HEIGHT;
|
|
||||||
if (core._WIDTH_ && core._HEIGHT_) {
|
|
||||||
[W, H] = [core._WIDTH_, core._HEIGHT_];
|
|
||||||
} else if (core.__SIZE__) {
|
|
||||||
[W, H] = [core.__SIZE__, core.__SIZE__];
|
|
||||||
} else {
|
|
||||||
[W, H] = [13, 13];
|
|
||||||
}
|
|
||||||
if (core._PX_ && core._PY_) {
|
|
||||||
[WIDTH, HEIGHT] = [core._PX_, core._PY_];
|
|
||||||
} else if (core.__SIZE__) {
|
|
||||||
[WIDTH, HEIGHT] = [core.__PIXELS__, core.__PIXELS__];
|
|
||||||
} else {
|
|
||||||
[WIDTH, HEIGHT] = [416, 416];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let [W, H] = [core.__SIZE__, core.__SIZE__];
|
||||||
|
let [WIDTH, HEIGHT] = [core.__PIXELS__, core.__PIXELS__];
|
||||||
|
|
||||||
utils.prototype.http = function (type, url, formData, success, error, mimeType, responseType, onprogress, timeout) {
|
//#region 弹幕的收发
|
||||||
let xhr = new XMLHttpRequest();
|
|
||||||
xhr.open(type, url, true);
|
|
||||||
|
|
||||||
xhr.timeout = timeout;
|
|
||||||
if (mimeType) xhr.overrideMimeType(mimeType);
|
|
||||||
if (responseType) xhr.responseType = responseType;
|
|
||||||
xhr.onload = function (e) {
|
|
||||||
if (xhr.status == 200) {
|
|
||||||
if (success) success(xhr.response);
|
|
||||||
} else {
|
|
||||||
if (error) error("HTTP " + xhr.status);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.onprogress = function (e) {
|
|
||||||
if (e.lengthComputable) {
|
|
||||||
if (onprogress) onprogress(e.loaded, e.total);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xhr.onabort = function () {
|
|
||||||
if (error) error("Abort");
|
|
||||||
}
|
|
||||||
xhr.ontimeout = function () {
|
|
||||||
if (error) error("Timeout");
|
|
||||||
}
|
|
||||||
xhr.onerror = function () {
|
|
||||||
if (error) error("Error on Connection");
|
|
||||||
}
|
|
||||||
if (formData)
|
|
||||||
xhr.send(formData);
|
|
||||||
else xhr.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getComment = function () {
|
this.getComment = function () {
|
||||||
|
if (core.isReplaying()) return;
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append('type', 1);
|
form.append('type', 1);
|
||||||
form.append('towername', towerName);
|
form.append('towername', towerName);
|
||||||
@ -3348,20 +3336,19 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
'https://h5mota.com/backend/tower/barrage.php',
|
'https://h5mota.com/backend/tower/barrage.php',
|
||||||
form,
|
form,
|
||||||
function (res) {
|
function (res) {
|
||||||
|
try {
|
||||||
res = JSON.parse(res);
|
res = JSON.parse(res);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
core.drawTip('接收成功!')
|
core.drawTip('接收成功!')
|
||||||
core.playSound('item.mp3');
|
core.playSound('item.mp3');
|
||||||
let commentCollection = {};
|
let commentCollection = {};
|
||||||
const commentList = res?.list;
|
const commentList = res?.list;
|
||||||
|
const isEmpty = /^\s*$/;
|
||||||
for (let i = 0, l = commentList.length; i <= l - 1; i++) {
|
for (let i = 0, l = commentList.length; i <= l - 1; i++) {
|
||||||
if (commentList[i]?.comment?.length === 0 || commentList[i]?.comment.match(/^[ ]*$/)) continue;
|
if (isEmpty.test(commentList[i]?.comment)) continue;
|
||||||
const commentTags = commentList[i].tags;
|
const commentTagsList = commentList[i].tags.split(',');
|
||||||
const cFloorId = commentTags.split(',')[0],
|
const [cFloorId, cX, cY] = commentTagsList;
|
||||||
cX = parseInt(commentTags.split(',')[1]),
|
if (0 <= cX && cX <= W - 1 && 0 <= cY && cY <= H - 1 && core.floorIds.includes(cFloorId)) {
|
||||||
cY = parseInt(commentTags.split(',')[2]);
|
|
||||||
if (0 <= cX && cX <= W - 1 && 0 <= cY &&
|
|
||||||
cY <= H - 1 && core.floorIds.includes(cFloorId)) {
|
|
||||||
if (!commentCollection.hasOwnProperty(cFloorId)) { commentCollection[cFloorId] = {}; }
|
if (!commentCollection.hasOwnProperty(cFloorId)) { commentCollection[cFloorId] = {}; }
|
||||||
const str = cX + ',' + cY;
|
const str = cX + ',' + cY;
|
||||||
if (!commentCollection[cFloorId].hasOwnProperty(str)) { commentCollection[cFloorId][str] = []; }
|
if (!commentCollection[cFloorId].hasOwnProperty(str)) { commentCollection[cFloorId][str] = []; }
|
||||||
@ -3369,6 +3356,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.setFlag('commentCollection', commentCollection);
|
core.setFlag('commentCollection', commentCollection);
|
||||||
|
} catch (err) {
|
||||||
|
core.drawTip('接收消息失败!' + err.message);
|
||||||
|
core.playSound('error.mp3');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
err = JSON.parse(err);
|
err = JSON.parse(err);
|
||||||
@ -3381,6 +3372,13 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.postComment = function (comment, tags) {
|
this.postComment = function (comment, tags) {
|
||||||
|
if (core.isReplaying()) return;
|
||||||
|
const isEmpty = /^\s*$/;
|
||||||
|
if (isEmpty.test(comment)){
|
||||||
|
core.drawTip('您输入的消息为空,请重发!');
|
||||||
|
core.playSound('error.mp3');
|
||||||
|
return;
|
||||||
|
}
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append('type', 2);
|
form.append('type', 2);
|
||||||
form.append('towername', towerName);
|
form.append('towername', towerName);
|
||||||
@ -3391,6 +3389,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
'https://h5mota.com/backend/tower/barrage.php',
|
'https://h5mota.com/backend/tower/barrage.php',
|
||||||
form,
|
form,
|
||||||
function (res) {
|
function (res) {
|
||||||
|
try {
|
||||||
res = JSON.parse(res);
|
res = JSON.parse(res);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if (res?.code === 0) {
|
if (res?.code === 0) {
|
||||||
@ -3400,6 +3399,11 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
core.drawTip('提交失败!' + res?.message);
|
core.drawTip('提交失败!' + res?.message);
|
||||||
core.playSound('error.mp3');
|
core.playSound('error.mp3');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
core.drawTip('接收消息失败!' + err.message);
|
||||||
|
core.playSound('error.mp3');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
err = JSON.parse(err);
|
err = JSON.parse(err);
|
||||||
@ -3410,6 +3414,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
null, null, null, 1000
|
null, null, null, 1000
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
this.drawCommentSign = function () {
|
this.drawCommentSign = function () {
|
||||||
if (!core.getFlag('comment') || core.isReplaying()) return;
|
if (!core.getFlag('comment') || core.isReplaying()) return;
|
||||||
@ -3419,29 +3424,26 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
core.setOpacity('sign', 0.6);
|
core.setOpacity('sign', 0.6);
|
||||||
if (commentCollection.hasOwnProperty(floorId)) {
|
if (commentCollection.hasOwnProperty(floorId)) {
|
||||||
for (let pos in commentCollection[floorId]) {
|
for (let pos in commentCollection[floorId]) {
|
||||||
if (commentCollection[floorId][pos].length > 0) {
|
const l = commentCollection[floorId][pos].length;
|
||||||
for (let i = 0, l = commentCollection[floorId][pos].length; i <= l - 1; i++) {
|
for (let i = 0; i <= l - 1; i++) {
|
||||||
if (!(commentCollection[floorId][pos][i].match(/^[ ]*$/))) {
|
const [x, y] = pos.split(',');
|
||||||
const x = pos.split(',')[0],
|
|
||||||
y = pos.split(',')[1];
|
|
||||||
core.drawImage('sign', 'sign.png', 32 * x, 32 * y);
|
core.drawImage('sign', 'sign.png', 32 * x, 32 * y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.clearCommentSign = function () {
|
this.clearCommentSign = function () {
|
||||||
core.deleteCanvas('sign');
|
core.deleteCanvas('sign');
|
||||||
}
|
}
|
||||||
|
|
||||||
const showNum = 5;
|
/** 返回从commentArr中挑选showNum个comment组成的数组*/
|
||||||
|
function pickComment(commentArr, showNum) {
|
||||||
function pickComment(commentArr, showNum = 5) {
|
|
||||||
let showList = [];
|
let showList = [];
|
||||||
if (commentArr.length <= showNum) { showList = commentArr; } else {
|
if (commentArr.length <= showNum) {
|
||||||
|
showList = commentArr;
|
||||||
|
} else {
|
||||||
for (let i = 0; i <= showNum - 1; i++) {
|
for (let i = 0; i <= showNum - 1; i++) {
|
||||||
const l = commentArr.length,
|
const l = commentArr.length,
|
||||||
n = core.plugin.dice(l - 1);
|
n = core.plugin.dice(l - 1);
|
||||||
@ -3452,6 +3454,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
return showList;
|
return showList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 生成count个随机数,范围从min到max,作为弹幕的y坐标*/
|
||||||
function generateCommentYList(min, max, count) {
|
function generateCommentYList(min, max, count) {
|
||||||
let yList = Array(count).fill(0);
|
let yList = Array(count).fill(0);
|
||||||
const distance = (max - min) / (count + 1);
|
const distance = (max - min) / (count + 1);
|
||||||
@ -3474,6 +3477,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
|||||||
return result.slice(len - count);
|
return result.slice(len - count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 默认一次显示的弹幕数 */
|
||||||
|
const showNum = 5;
|
||||||
|
|
||||||
function drawComment(commentArr) {
|
function drawComment(commentArr) {
|
||||||
const l = commentArr.length;
|
const l = commentArr.length;
|
||||||
let yList = generateCommentYList(20, HEIGHT - 20, showNum);
|
let yList = generateCommentYList(20, HEIGHT - 20, showNum);
|
||||||
|
|||||||
4
runtime.d.ts
vendored
4
runtime.d.ts
vendored
@ -2714,8 +2714,10 @@ interface utils {
|
|||||||
* @param formData 如果是POST请求则为表单数据
|
* @param formData 如果是POST请求则为表单数据
|
||||||
* @param success 成功后的回调
|
* @param success 成功后的回调
|
||||||
* @param error 失败后的回调
|
* @param error 失败后的回调
|
||||||
|
* @param timeout 超时时间
|
||||||
*/
|
*/
|
||||||
http(type: 'GET' | 'POST', url: string, formData: FormData, success: () => void, error: () => void): void
|
http(type: 'GET' | 'POST', url: string, formData: FormData, success: () => void, error: () => void,
|
||||||
|
mimeType: string, responseType: XMLHttpRequestResponseType, onprogress: boolean, timeout: number): void
|
||||||
|
|
||||||
/** 获得浏览器唯一的guid */
|
/** 获得浏览器唯一的guid */
|
||||||
getGuid(): string
|
getGuid(): string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user