温馨提示: 这篇文章于935天前编写,现在可能不再适用或落后.

img

PVPIN Blockly Development Google Blockly 二次开发教程

Google Blockly 二次开发工作量不小,阅读本教程不能让人从简单的一块主函数搭建出墨染空大佬万余块积木拼合而成的 Basis Plugin,也不能让人几天内从一行 Blockly.inject() 写出当年我站用于定义积木的近两万行 JavaScript 程序。

教程地址:https://mikudoc.com/PVPIN/BlocklyDev#/

备用地址:https://william-shi233.gitbook.io/pvpinblocklydev

原文 GitHub 项目:https://github.com/PVPINStudio/PVPINBlocklyDev

示例项目:https://github.com/PVPINStudio/PVPINBlocklyDevProj

第十章问题答案:

console.log("Loading Connection Checker...");

/**
 * @implements {Blockly.IConnectionChecker}
 */
class PVPINConnectionChecker extends Blockly.ConnectionChecker {
    constructor() {
        super();
    }

    /**
     * Type check arrays must either intersect or both be null.
     * @override
     */
    doTypeChecks(a, b) {
        const checkArrayOne = a.getCheck();
        // Output
        const checkArrayTwo = b.getCheck();
        // Input
        return this.doChecks_(checkArrayOne, checkArrayTwo);
    }

    // Internal use only.
    doChecks_(checkArrayOne, checkArrayTwo) {
        if (!checkArrayOne || !checkArrayTwo) {
            // One is null, permit connection.
            return true;
        }
        // Find any intersection in the check lists.
        for (let i = 0; i < checkArrayOne.length; i++) {
            for (let j = 0; j < checkArrayTwo.length; j++) {
                if (checkArrayOne[i] == checkArrayTwo[j]) {
                    return true;
                }
            }
        }
        for (let i = 0; i < checkArrayOne.length; i++) {
            for (let j = 0; j < checkArrayTwo.length; j++) {
                if (!MAP[checkArrayOne[i]]) {
                    return false;
                }
                if (MAP[checkArrayOne[i]].indexOf(checkArrayTwo[j]) > -1) {
                    return true;
                }
            }
        }
        return false;
    }
}

const registrationType = Blockly.registry.Type.CONNECTION_CHECKER;
const registrationName = "PVPINConnectionChecker";

// Register the checker so that it can be used by name.
Blockly.registry.register(registrationType, registrationName, PVPINConnectionChecker);

const pluginInfo = {
    [registrationType]: registrationName,
};

const MAP = {
    // 按需生成 
};

阁下需要登录后才可以查看评论哦~

随便看看

    载入中...

    正在准备穿越次元,阁下请稍等片刻~