blockly方块嵌入文档
This commit is contained in:
parent
fdd65bc028
commit
d2d93589b9
55
_docs/blocksdemo.md
Normal file
55
_docs/blocksdemo.md
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
http://127.0.0.1:1055/_docs/#/blocksdemo
|
||||||
|
|
||||||
|
方便测试用
|
||||||
|
|
||||||
|
这种写法不会生成按钮
|
||||||
|
```js
|
||||||
|
'run';
|
||||||
|
return bg.parseList(['行内']);
|
||||||
|
// return bg.parse(['asdasd','df'],'event')+'<br>'+bg.parseList(['asfewg','sty']);
|
||||||
|
```
|
||||||
|
并且是行内的
|
||||||
|
|
||||||
|
这种写法之后的版本会补一个按钮'添加到常用事件', 目前先这样吧
|
||||||
|
|
||||||
|
``` MotaAction.event
|
||||||
|
[
|
||||||
|
'显示文章',
|
||||||
|
'...'
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
``` MotaAction.shop
|
||||||
|
[{
|
||||||
|
"id": "shop1",
|
||||||
|
"text": "\t[贪婪之神,moneyShop]勇敢的武士啊, 给我${20+2*flag:shop1}金币就可以:",
|
||||||
|
"textInList": "1F金币商店",
|
||||||
|
"choices": [
|
||||||
|
{"text": "生命+800", "need": "status:money>=20+2*flag:shop1", "action": [
|
||||||
|
{"type": "setValue", "name": "status:money", "operator": "-=", "value": "20+2*flag:shop1"},
|
||||||
|
{"type": "setValue", "name": "flag:shop1", "operator": "+=", "value": "1"},
|
||||||
|
{"type": "setValue", "name": "status:hp", "operator": "+=", "value": "800"}
|
||||||
|
]}
|
||||||
|
]
|
||||||
|
},{
|
||||||
|
"id": "itemShop",
|
||||||
|
"item": true,
|
||||||
|
"textInList": "道具商店",
|
||||||
|
"choices": [
|
||||||
|
{"id": "yellowKey", "number": 10, "money": 10}
|
||||||
|
]
|
||||||
|
},{
|
||||||
|
"id": "keyShop1",
|
||||||
|
"textInList": "回收钥匙商店",
|
||||||
|
"commonEvent": "回收钥匙商店",
|
||||||
|
"args": ""
|
||||||
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
|
``` MotaAction.action
|
||||||
|
'显示文章'
|
||||||
|
```
|
||||||
|
|
||||||
|
``` MotaAction
|
||||||
|
['MotaAction.action的anction可以省略','只写MotaAction']
|
||||||
|
```
|
||||||
145
_docs/index.html
145
_docs/index.html
@ -11,9 +11,77 @@
|
|||||||
<meta http-equiv="expires" content="0">
|
<meta http-equiv="expires" content="0">
|
||||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
<link href="https://cdn.bootcss.com/docsify/4.5.5/themes/vue.css" rel="stylesheet">
|
<link href="https://cdn.bootcss.com/docsify/4.5.5/themes/vue.css" rel="stylesheet">
|
||||||
|
<script>
|
||||||
|
//先下载着
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', 'https://cdn.bootcss.com/docsify/4.5.5/docsify.min.js', true);
|
||||||
|
xhr.send(null);
|
||||||
|
xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', 'https://cdn.bootcss.com/docsify/4.5.5/plugins/search.min.js', true);
|
||||||
|
xhr.send(null);
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
window.bg={replaceToken:{}}
|
||||||
|
bg.guid=function () {
|
||||||
|
return 'id_' + 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
|
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
bg.table=function(ths,tdss,args){
|
||||||
|
return `<table class="${((args||{}).class||[]).join(' ')}"><thead><tr>${ths.map(v=>`<th style="text-align:left">${v}</th>`).join('')}</tr></thead><tbody>${tdss.map(tds=>`<tr>${tds.map(v=>`<td style="text-align:left">${v}</td>`).join('')}</tr>`).join('')}</tbody></table>`;
|
||||||
|
}
|
||||||
|
bg.pattern=/```\s*MotaAction.*?\r?\n[^]*?\r?\n\s*```/g;
|
||||||
|
bg.replaceFunc=function(str){
|
||||||
|
var content=null;
|
||||||
|
try {
|
||||||
|
content=eval(str.split('\n').slice(1,-1).join('\n'))
|
||||||
|
} catch (ee) {
|
||||||
|
}
|
||||||
|
var match=/```\s*MotaAction(\.)?(\w+)?/.exec(str);
|
||||||
|
var blocksvg=''
|
||||||
|
if (!match[2] || match[2]=='action')blocksvg= bg.parseList(content);
|
||||||
|
else blocksvg=bg.parse(content,match[2]);
|
||||||
|
return '<p>'+blocksvg+'</p>\n\n';
|
||||||
|
}
|
||||||
|
bg.parse=function(obj,type){
|
||||||
|
|
||||||
|
MotaActionFunctions.workspace().clear();
|
||||||
|
xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event');
|
||||||
|
xml = Blockly.Xml.textToDom('<xml>'+xml_text+'</xml>');
|
||||||
|
Blockly.Xml.domToWorkspace(xml, MotaActionFunctions.workspace());
|
||||||
|
|
||||||
|
svgBlock=document.querySelector("g.blocklyBlockCanvas > g.blocklyDraggable")
|
||||||
|
svgBlock.setAttribute('transform','translate(0,0)')
|
||||||
|
tmp={width:svgBlock.getBBox().width,height:svgBlock.getBBox().height}
|
||||||
|
|
||||||
|
var id=`<span>${bg.guid()}</span>`
|
||||||
|
bg.replaceToken[id]=`<svg width="${tmp.width}px" height="${tmp.height}px">`+svgBlock.outerHTML+'</svg>'
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
bg.parseList=function(obj){
|
||||||
|
|
||||||
|
MotaActionFunctions.workspace().clear();
|
||||||
|
xml_text = MotaActionFunctions.actionParser.parseList(obj);
|
||||||
|
xml = Blockly.Xml.textToDom('<xml>'+xml_text+'</xml>');
|
||||||
|
Blockly.Xml.domToWorkspace(xml, MotaActionFunctions.workspace());
|
||||||
|
|
||||||
|
svgBlock=document.querySelector("g.blocklyBlockCanvas > g.blocklyDraggable")
|
||||||
|
svgBlock.setAttribute('transform','translate(0,0)')
|
||||||
|
tmp={width:svgBlock.getBBox().width,height:svgBlock.getBBox().height}
|
||||||
|
|
||||||
|
var id=`<span>${bg.guid()}</span>`
|
||||||
|
bg.replaceToken[id]=`<svg width="${tmp.width}px" height="${tmp.height}px">`+svgBlock.outerHTML+'</svg>'
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
<xml id="toolbox" style="display:none"></xml>
|
||||||
|
<div id="blocklyArea" style="opacity: 0;z-index: -1;"><div id="blocklyDiv"></div></div>
|
||||||
|
<textarea id="codeArea" style="display:none" spellcheck="false"></textarea>
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
homepage: 'index.md',
|
homepage: 'index.md',
|
||||||
@ -41,9 +109,82 @@
|
|||||||
auto2top: true,
|
auto2top: true,
|
||||||
mergeNavbar: true,
|
mergeNavbar: true,
|
||||||
formatUpdated: '{YYYY}-{MM}-{DD} {HH}:{mm}:{ss}',
|
formatUpdated: '{YYYY}-{MM}-{DD} {HH}:{mm}:{ss}',
|
||||||
|
plugins: [
|
||||||
|
function(hook){
|
||||||
|
|
||||||
|
var renderScriptNode=function(str){
|
||||||
|
return str.replace(/```.*?\r?\n['"]run['"];[^]*?\r?\n```/g,function(x){
|
||||||
|
return eval(`(function(){${x.replace(/```.*?\r?\n['"]run['"];/,'').slice(0,-3)}})()`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var renderMotaAction=function(str){
|
||||||
|
return str.replace(bg.pattern,function(x){
|
||||||
|
return bg.replaceFunc(x)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
hook.beforeEach(function(content){
|
||||||
|
return renderMotaAction(renderScriptNode(
|
||||||
|
content
|
||||||
|
))
|
||||||
|
})
|
||||||
|
|
||||||
|
hook.doneEach(function(){
|
||||||
|
var map=bg.replaceToken
|
||||||
|
var node=document.querySelector('.markdown-section')
|
||||||
|
var str=node.innerHTML
|
||||||
|
for(var id in map){
|
||||||
|
str=str.replace(id,map[id])
|
||||||
|
}
|
||||||
|
node.innerHTML=str
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="https://cdn.bootcss.com/docsify/4.5.5/docsify.min.js"></script>
|
<!-- 为了保证时序用脚本加载 <script src="https://cdn.bootcss.com/docsify/4.5.5/docsify.min.js"></script>
|
||||||
<script src="https://cdn.bootcss.com/docsify/4.5.5/plugins/search.min.js"></script>
|
<script src="https://cdn.bootcss.com/docsify/4.5.5/plugins/search.min.js"></script> -->
|
||||||
|
<script src="../_server/blockly/Converter.bundle.min.js"></script>
|
||||||
|
<script src="../_server/blockly/blockly_compressed.js"></script>
|
||||||
|
<script src="../_server/blockly/blocks_compressed.js"></script>
|
||||||
|
<script src="../_server/blockly/javascript_compressed.js"></script>
|
||||||
|
<script src="../_server/blockly/zh-hans.js"></script>
|
||||||
|
<script src='../_server/MotaActionParser.js'></script>
|
||||||
|
<script>
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState != 4) return;
|
||||||
|
if (xhr.status != 200) {
|
||||||
|
alert("图块描述文件加载失败, 请在'启动服务.exe'中打开编辑器");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var grammerFile = xhr.responseText;
|
||||||
|
converter = new Converter().init();
|
||||||
|
converter.generBlocks(grammerFile);
|
||||||
|
//printf(converter.blocks);
|
||||||
|
converter.renderGrammerName();
|
||||||
|
//converter.generToolbox();
|
||||||
|
converter.generMainFile();
|
||||||
|
//printf(converter.mainFile.join(''));
|
||||||
|
//console.log(converter);
|
||||||
|
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.innerHTML = converter.mainFile[5] + converter.mainFile[6];
|
||||||
|
window.core={material:{items:[],enemys:[]}}
|
||||||
|
document.body.appendChild(script);
|
||||||
|
MotaActionFunctions.disableReplace = true;
|
||||||
|
MotaActionFunctions.disableExpandCompare = true;
|
||||||
|
|
||||||
|
script = document.createElement('script');
|
||||||
|
script.src='https://cdn.bootcss.com/docsify/4.5.5/docsify.min.js'
|
||||||
|
document.body.appendChild(script);
|
||||||
|
script = document.createElement('script');
|
||||||
|
script.src='https://cdn.bootcss.com/docsify/4.5.5/plugins/search.min.js'
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
xhr.open('GET', '../_server/MotaAction.g4', true);
|
||||||
|
xhr.send(null);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user