How to use XmlText method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

editor_blocklyconfig.js

Source:editor_blocklyconfig.js Github

copy

Full Screen

1editor_blocklyconfig=(function(){2// start mark sfergsvae3(function(){4 var getCategory = function(name,custom){5 for(var node of document.getElementById('toolbox').children) {6 if(node.getAttribute('name')==name) return node;7 }8 var node = document.createElement('category');9 node.setAttribute('name',name);10 if(custom)node.setAttribute('custom',custom);11 document.getElementById('toolbox').appendChild(node);12 return node;13 }14 var toolboxObj = {15 '入口方块':[16 '<label text="入口方块会根据当前类型在此数组中筛选,具体控制在editor_blockly.entranceCategoryCallback中"></label>',17 MotaActionFunctions.actionParser.parse([18 "欢迎使用事件编辑器",19 "本事件触发一次后会消失",20 {"type": "hide", "time": 500},21 ],'event'),22 MotaActionFunctions.actionParser.parse({23 "condition": "flag:__door__===2",24 "currentFloor": true,25 "priority": 0,26 "delayExecute": false,27 "multiExecute": false,28 "data": [29 {"type": "openDoor", "loc": [10,5]}30 ],31 },'autoEvent'),32 MotaActionBlocks['changeFloor_m'].xmlText(),33 MotaActionFunctions.actionParser.parse([{34 "id": "shop1",35 "text": "\t[贪婪之神,moneyShop]勇敢的武士啊, 给我${20+2*flag:shop1}金币就可以:", 36 "textInList": "1F金币商店", 37 "choices": [ 38 {"text": "生命+800", "need": "status:money>=20+2*flag:shop1", "action": [39 {"type": "comment", "text": "新版商店中需要手动扣减金币和增加访问次数"},40 {"type": "setValue", "name": "status:money", "operator": "-=", "value": "20+2*flag:shop1"},41 {"type": "setValue", "name": "flag:shop1", "operator": "+=", "value": "1"},42 {"type": "setValue", "name": "status:hp", "operator": "+=", "value": "800"}43 ]}44 ]45 },{46 "id": "itemShop",47 "item": true,48 "textInList": "道具商店",49 "choices": [50 {"id": "yellowKey", "number": 10, "money": 10}51 ]52 },{53 "id": "keyShop1",54 "textInList": "回收钥匙商店",55 "commonEvent": "回收钥匙商店",56 "args": ""57 }],'shop'),58 MotaActionBlocks['common_m'].xmlText(),59 MotaActionBlocks['beforeBattle_m'].xmlText(),60 MotaActionBlocks['afterBattle_m'].xmlText(),61 MotaActionBlocks['afterGetItem_m'].xmlText(),62 MotaActionBlocks['afterOpenDoor_m'].xmlText(),63 MotaActionBlocks['firstArrive_m'].xmlText(),64 MotaActionBlocks['eachArrive_m'].xmlText(),65 MotaActionBlocks['level_m'].xmlText(),66 MotaActionFunctions.actionParser.parse([67 ['MTx', '']68 ], 'floorPartition'),69 MotaActionBlocks['commonEvent_m'].xmlText(),70 MotaActionBlocks['item_m'].xmlText(),71 MotaActionFunctions.actionParser.parse([72 {"title":"简单", "name": "Easy", "hard": 1, "action": [73 {"type": "comment", "text": "在这里写该难度需执行的事件"}74 ]}75 ], 'levelChoose'),76 MotaActionFunctions.actionParser.parse({77 "type": 0, "value": {"atk": 10}, "percentage": {"speed": 10},78 }, 'equip'),79 MotaActionFunctions.actionParser.parse([{80 "name": "bg.jpg", "x": 0, "y": 0, "canvas": "bg"81 }], 'floorImage'),82 MotaActionFunctions.actionParser.parse({83 "time": 160, "openSound": "door.mp3", "closeSound": "door.mp3", "keys": {"yellowKey": 1, "orangeKey": 1}84 }, 'doorInfo'),85 MotaActionBlocks['faceIds_m'].xmlText(),86 MotaActionBlocks['mainStyle_m'].xmlText(),87 MotaActionFunctions.actionParser.parse({88 "背景音乐": "bgm.mp3", "确定": "confirm.mp3", "攻击": "attack.mp3", "背景图": "bg.jpg", "领域": "zone", "文件名": "file.jpg"89 }, 'nameMap'),90 MotaActionFunctions.actionParser.parse([91 {"name": "hero.png", "width": 32, "height": 32, "prefix": "hero_"},92 ], 'splitImages'),93 ],94 '显示文字':[95 MotaActionBlocks['text_0_s'].xmlText(),96 MotaActionBlocks['text_1_s'].xmlText(),97 MotaActionFunctions.actionParser.parseList("\t[小妖精,fairy]\f[fairy.png,0,0]欢迎使用事件编辑器(双击方块可直接预览)"),98 MotaActionBlocks['moveTextBox_s'].xmlText(),99 MotaActionBlocks['clearTextBox_s'].xmlText(),100 MotaActionBlocks['comment_s'].xmlText(),101 MotaActionBlocks['autoText_s'].xmlText(),102 MotaActionBlocks['scrollText_s'].xmlText(),103 MotaActionBlocks['setText_s'].xmlText(),104 MotaActionBlocks['tip_s'].xmlText(),105 MotaActionBlocks['confirm_s'].xmlText(),106 MotaActionBlocks['choices_s'].xmlText([107 '选择剑或者盾','流浪者','man',0,'',MotaActionBlocks['choicesContext'].xmlText([108 '剑','','',null,'','',MotaActionFunctions.actionParser.parseList([{"type": "openDoor", "loc": [3,3]}]),109 ])110 ]),111 MotaActionBlocks['win_s'].xmlText(),112 MotaActionBlocks['lose_s'].xmlText(),113 MotaActionBlocks['restart_s'].xmlText(),114 ],115 '数据相关':[116 MotaActionBlocks['setValue_s'].xmlText([117 MotaActionBlocks['idIdList_e'].xmlText(['status','生命']), '=', '', false118 ]),119 MotaActionBlocks['setEnemy_s'].xmlText(),120 MotaActionBlocks['setEnemyOnPoint_s'].xmlText(),121 MotaActionBlocks['resetEnemyOnPoint_s'].xmlText(),122 MotaActionBlocks['moveEnemyOnPoint_s'].xmlText(),123 MotaActionBlocks['moveEnemyOnPoint_1_s'].xmlText(),124 MotaActionBlocks['setEquip_s'].xmlText(),125 MotaActionBlocks['setFloor_s'].xmlText(),126 MotaActionBlocks['setGlobalAttribute_s'].xmlText(),127 MotaActionBlocks['setGlobalValue_s'].xmlText(),128 MotaActionBlocks['setGlobalFlag_s'].xmlText(),129 MotaActionBlocks['setNameMap_s'].xmlText(),130 MotaActionBlocks['input_s'].xmlText(),131 MotaActionBlocks['input2_s'].xmlText(),132 MotaActionBlocks['update_s'].xmlText(),133 MotaActionBlocks['moveAction_s'].xmlText(),134 MotaActionBlocks['changeFloor_s'].xmlText(),135 MotaActionBlocks['changePos_s'].xmlText(),136 MotaActionBlocks['battle_s'].xmlText(),137 MotaActionBlocks['useItem_s'].xmlText(),138 MotaActionBlocks['loadEquip_s'].xmlText(),139 MotaActionBlocks['unloadEquip_s'].xmlText(),140 MotaActionBlocks['openShop_s'].xmlText(),141 MotaActionBlocks['disableShop_s'].xmlText(),142 MotaActionBlocks['setHeroIcon_s'].xmlText(),143 MotaActionBlocks['follow_s'].xmlText(),144 MotaActionBlocks['unfollow_s'].xmlText(),145 ],146 '地图处理':[147 MotaActionBlocks['battle_1_s'].xmlText(),148 MotaActionBlocks['openDoor_s'].xmlText(),149 MotaActionBlocks['closeDoor_s'].xmlText(),150 MotaActionBlocks['show_s'].xmlText(),151 MotaActionBlocks['hide_s'].xmlText(),152 MotaActionBlocks['setBlock_s'].xmlText(),153 MotaActionBlocks['setBlockOpacity_s'].xmlText(),154 MotaActionBlocks['setBlockFilter_s'].xmlText(),155 MotaActionBlocks['turnBlock_s'].xmlText(),156 MotaActionBlocks['moveHero_s'].xmlText(),157 MotaActionBlocks['move_s'].xmlText(),158 MotaActionBlocks['jumpHero_s'].xmlText(),159 MotaActionBlocks['jumpHero_1_s'].xmlText(),160 MotaActionBlocks['jump_s'].xmlText(),161 MotaActionBlocks['jump_1_s'].xmlText(),162 MotaActionBlocks['showBgFgMap_s'].xmlText(),163 MotaActionBlocks['hideBgFgMap_s'].xmlText(),164 MotaActionBlocks['setBgFgBlock_s'].xmlText(),165 MotaActionBlocks['showFloorImg_s'].xmlText(),166 MotaActionBlocks['hideFloorImg_s'].xmlText(),167 ],168 '事件控制':[169 MotaActionBlocks['if_1_s'].xmlText(),170 MotaActionBlocks['if_s'].xmlText(),171 MotaActionFunctions.actionParser.parseList({"type": "switch", "condition": "判别值", "caseList": [172 {"action": [{"type": "comment", "text": "当判别值是值的场合执行此事件"}]},173 {"case": "default", "action": [{"type": "comment", "text": "当没有符合的值的场合执行default事件"}]},174 ]}),175 MotaActionFunctions.actionParser.parseList({"type": "for", "name": "temp:A", "from": "0", "to": "12", "step": "1", "data": []}),176 MotaActionFunctions.actionParser.parseList({"type": "forEach", "name": "temp:A", "list": ["status:atk","status:def"], "data": []}),177 MotaActionBlocks['while_s'].xmlText(),178 MotaActionBlocks['dowhile_s'].xmlText(),179 MotaActionBlocks['break_s'].xmlText(),180 MotaActionBlocks['continue_s'].xmlText(),181 MotaActionBlocks['exit_s'].xmlText(),182 MotaActionBlocks['trigger_s'].xmlText(),183 MotaActionBlocks['insert_1_s'].xmlText(),184 MotaActionBlocks['insert_2_s'].xmlText(),185 ],186 '特效表现':[187 MotaActionBlocks['sleep_s'].xmlText(),188 MotaActionFunctions.actionParser.parseList({"type": "wait", "timeout": 0, "data": [189 {"case": "keyboard", "keycode": "13,32", "action": [{"type": "comment", "text": "当按下回车(keycode=13)或空格(keycode=32)时执行此事件\n超时剩余时间会写入flag:timeout"}]},190 {"case": "mouse", "px": [0,32], "py": [0,32], "action": [{"type": "comment", "text": "当点击地图左上角时执行此事件\n超时剩余时间会写入flag:timeout"}]},191 {"case": "condition", "condition": "flag:type==0\n&&flag:keycode==13", "action": [{"type": "comment", "text": "当满足自定义条件时会执行此事件\n超时剩余时间会写入flag:timeout"}]},192 {"case": "timeout", "action": [{"type": "comment", "text": "当超时未操作时执行此事件"}]},193 ]}),194 MotaActionBlocks['waitAsync_s'].xmlText(),195 MotaActionBlocks['stopAsync_s'].xmlText(),196 MotaActionBlocks['vibrate_s'].xmlText(),197 MotaActionBlocks['animate_s'].xmlText(),198 MotaActionBlocks['animate_1_s'].xmlText(),199 MotaActionBlocks['stopAnimate_s'].xmlText(),200 MotaActionBlocks['setViewport_s'].xmlText(),201 MotaActionBlocks['setViewport_1_s'].xmlText(),202 MotaActionBlocks['lockViewport_s'].xmlText(), 203 MotaActionBlocks['showStatusBar_s'].xmlText(),204 MotaActionBlocks['hideStatusBar_s'].xmlText(),205 MotaActionBlocks['setHeroOpacity_s'].xmlText(),206 MotaActionBlocks['setCurtain_0_s'].xmlText(),207 MotaActionBlocks['setCurtain_1_s'].xmlText(),208 MotaActionBlocks['screenFlash_s'].xmlText(),209 MotaActionBlocks['setWeather_s'].xmlText(),210 MotaActionBlocks['callBook_s'].xmlText(),211 MotaActionBlocks['callSave_s'].xmlText(),212 MotaActionBlocks['autoSave_s'].xmlText(),213 MotaActionBlocks['forbidSave_s'].xmlText(),214 MotaActionBlocks['callLoad_s'].xmlText(),215 ],216 '音像处理':[217 MotaActionBlocks['showImage_s'].xmlText(),218 MotaActionBlocks['showImage_1_s'].xmlText(),219 MotaActionBlocks['hideImage_s'].xmlText(),220 MotaActionBlocks['showTextImage_s'].xmlText(),221 MotaActionBlocks['moveImage_s'].xmlText(),222 MotaActionBlocks['rotateImage_s'].xmlText(),223 MotaActionBlocks['scaleImage_s'].xmlText(),224 MotaActionBlocks['showGif_s'].xmlText(),225 MotaActionBlocks['playBgm_s'].xmlText(),226 MotaActionBlocks['pauseBgm_s'].xmlText(),227 MotaActionBlocks['resumeBgm_s'].xmlText(),228 MotaActionBlocks['loadBgm_s'].xmlText(),229 MotaActionBlocks['freeBgm_s'].xmlText(),230 MotaActionBlocks['playSound_s'].xmlText(),231 MotaActionBlocks['playSound_1_s'].xmlText(),232 MotaActionBlocks['stopSound_s'].xmlText(),233 MotaActionBlocks['setVolume_s'].xmlText(),234 MotaActionBlocks['setBgmSpeed_s'].xmlText(),235 ],236 'UI绘制':[237 MotaActionBlocks['previewUI_s'].xmlText(),238 MotaActionBlocks['clearMap_s'].xmlText(),239 MotaActionBlocks['setAttribute_s'].xmlText(),240 MotaActionBlocks['setFilter_s'].xmlText(),241 MotaActionBlocks['fillText_s'].xmlText(),242 MotaActionBlocks['fillBoldText_s'].xmlText(),243 MotaActionBlocks['drawTextContent_s'].xmlText(),244 MotaActionBlocks['fillRect_s'].xmlText(),245 MotaActionBlocks['strokeRect_s'].xmlText(),246 MotaActionBlocks['drawLine_s'].xmlText(),247 MotaActionBlocks['drawArrow_s'].xmlText(),248 MotaActionBlocks['fillPolygon_s'].xmlText(),249 MotaActionBlocks['strokePolygon_s'].xmlText(),250 MotaActionBlocks['fillEllipse_s'].xmlText(),251 MotaActionBlocks['strokeEllipse_s'].xmlText(),252 MotaActionBlocks['fillArc_s'].xmlText(),253 MotaActionBlocks['strokeArc_s'].xmlText(),254 MotaActionBlocks['drawImage_s'].xmlText(),255 MotaActionBlocks['drawImage_1_s'].xmlText(),256 MotaActionBlocks['drawIcon_s'].xmlText(),257 MotaActionBlocks['drawBackground_s'].xmlText(),258 MotaActionBlocks['drawSelector_s'].xmlText(),259 MotaActionBlocks['drawSelector_1_s'].xmlText(),260 ],261 '原生脚本':[262 MotaActionBlocks['function_s'].xmlText(),263 MotaActionBlocks['unknown_s'].xmlText(),264 ],265 '值块':[266 MotaActionBlocks['setValue_s'].xmlText([267 MotaActionBlocks['idIdList_e'].xmlText(['status','生命']), '=', '', false268 ]),269 MotaActionBlocks['expression_arithmetic_0'].xmlText(),270 MotaActionBlocks['idFlag_e'].xmlText(),271 MotaActionBlocks['idTemp_e'].xmlText(),272 MotaActionBlocks['negate_e'].xmlText(),273 MotaActionBlocks['unaryOperation_e'].xmlText(),274 MotaActionBlocks['bool_e'].xmlText(),275 MotaActionBlocks['idString_e'].xmlText(),276 MotaActionBlocks['idIdList_e'].xmlText(),277 MotaActionBlocks['idFixedList_e'].xmlText(),278 MotaActionBlocks['enemyattr_e'].xmlText(),279 MotaActionBlocks['blockId_e'].xmlText(),280 MotaActionBlocks['blockNumber_e'].xmlText(),281 MotaActionBlocks['blockCls_e'].xmlText(),282 MotaActionBlocks['hasEquip_e'].xmlText(),283 MotaActionBlocks['equip_e'].xmlText(),284 MotaActionBlocks['nextXY_e'].xmlText(),285 MotaActionBlocks['isReplaying_e'].xmlText(),286 MotaActionBlocks['hasVisitedFloor_e'].xmlText(),287 MotaActionBlocks['isShopVisited_e'].xmlText(),288 MotaActionBlocks['canBattle_e'].xmlText(),289 MotaActionBlocks['damage_e'].xmlText(),290 MotaActionBlocks['damage_1_e'].xmlText(),291 MotaActionBlocks['rand_e'].xmlText(),292 MotaActionBlocks['evalString_e'].xmlText(),293 ],294 '常见事件模板':[295 '<label text="检测音乐如果没有开启则系统提示开启"></label>',296 MotaActionFunctions.actionParser.parseList({"type": "if", "condition": "!core.musicStatus.bgmStatus",297 "true": [298 "\t[系统提示]你当前音乐处于关闭状态,本塔开音乐游戏效果更佳"299 ],300 "false": []301 }),302 '<label text="仿新新魔塔一次性商人"></label>',303 MotaActionFunctions.actionParser.parse([304 {305 "type": "if",306 "condition": "switch:A",307 "true": [308 "\t[行商,trader]\b[this]这是购买我的道具后我给玩家的提示。",309 {310 "type": "comment",311 "text": "下一条指令可视情况使用或不使用"312 },313 {314 "type": "hide",315 "remove": true,316 "time": 250317 }318 ],319 "false": [320 {321 "type": "confirm",322 "text": "我有3把黄钥匙,\n你出50金币就卖给你。",323 "yes": [324 {325 "type": "if",326 "condition": "status:money>=50",327 "true": [328 {329 "type": "setValue",330 "name": "status:money",331 "operator": "-=",332 "value": "50"333 },334 {335 "type": "setValue",336 "name": "item:yellowKey",337 "operator": "+=",338 "value": "3"339 },340 {341 "type": "playSound",342 "name": "确定",343 "stop": true344 },345 {346 "type": "setValue",347 "name": "switch:A",348 "value": "true"349 }350 ],351 "false": [352 {353 "type": "playSound",354 "name": "操作失败"355 },356 "\t[行商,trader]\b[this]你的金币不足!"357 ]358 }359 ],360 "no": []361 }362 ]363 }364 ], 'event'),365 '<label text="全地图选中一个点"></label>',366 MotaActionFunctions.actionParser.parse([367 {368 "type": "comment",369 "text": "全地图选中一个点,需要用鼠标或触屏操作"370 },371 {372 "type": "setValue",373 "name": "temp:X",374 "value": "status:x"375 },376 {377 "type": "setValue",378 "name": "temp:Y",379 "value": "status:y"380 },381 {382 "type": "tip",383 "text": "再次点击闪烁位置确认"384 },385 {386 "type": "while",387 "condition": "true",388 "data": [389 {390 "type": "drawSelector",391 "image": "winskin.png",392 "code": 1,393 "x": "32*temp:X",394 "y": "32*temp:Y",395 "width": 32,396 "height": 32397 },398 {399 "type": "wait"400 },401 {402 "type": "if",403 "condition": "(flag:type === 1)",404 "true": [405 {406 "type": "if",407 "condition": "((temp:X===flag:x)&&(temp:Y===flag:y))",408 "true": [409 {410 "type": "break",411 "n": 1412 }413 ]414 },415 {416 "type": "setValue",417 "name": "temp:X",418 "value": "flag:x"419 },420 {421 "type": "setValue",422 "name": "temp:Y",423 "value": "flag:y"424 }425 ]426 }427 ]428 },429 {430 "type": "drawSelector",431 "code": 1432 },433 {434 "type": "comment",435 "text": "流程进行到这里可以对[X,Y]点进行处理,比如"436 },437 {438 "type": "closeDoor",439 "id": "yellowDoor",440 "loc": [441 "temp:X",442 "temp:Y"443 ]444 }445 ],'event'),446 '<label text="多阶段Boss战斗"></label>',447 MotaActionFunctions.actionParser.parse([448 {449 "type": "comment",450 "text": "多阶段boss,请直接作为战后事件使用"451 },452 {453 "type": "setValue",454 "name": "switch:A",455 "operator": "+=",456 "value": "1"457 },458 {459 "type": "switch",460 "condition": "switch:A",461 "caseList": [462 {463 "case": "1",464 "action": [465 {466 "type": "setBlock",467 "number": "redSlime"468 },469 "\t[2阶段boss,redSlime]\b[this]你以为你已经打败我了吗?没听说过史莱姆有九条命吗?"470 ]471 },472 {473 "case": "2",474 "action": [475 {476 "type": "setBlock",477 "number": "blackSlime"478 },479 "\t[3阶段boss,blackSlime]\b[this]不能消灭我的,只会让我更强大!"480 ]481 },482 {483 "case": "3",484 "action": [485 {486 "type": "setBlock",487 "number": "slimelord"488 },489 "\t[4阶段boss,slimelord]\b[this]我还能打!"490 ]491 },492 {493 "case": "4",494 "action": [495 "\t[4阶段boss,slimelord]我一定会回来的!"496 ]497 }498 ]499 }500 ],'afterBattle'),501 ],502 '最近使用事件':[503 '<label text="此处只是占位符,实际定义在editor_blockly.searchBlockCategoryCallback中"></label>',504 ]505 }506 var toolboxgap = '<sep gap="5"></sep>'507 //xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event')508 //MotaActionBlocks['idString_e'].xmlText()509 for (var name in toolboxObj){510 var custom = null;511 if(name=='最近使用事件')custom='searchBlockCategory';512 if(name=='入口方块')custom='entranceCategory';513 getCategory(name,custom).innerHTML = toolboxObj[name].join(toolboxgap);514 }515var blocklyArea = document.getElementById('blocklyArea');516var blocklyDiv = document.getElementById('blocklyDiv');517var workspace = Blockly.inject(blocklyDiv,{518 media: '_server/blockly/media/',519 toolbox: document.getElementById('toolbox'),520 zoom:{521 controls: true,522 wheel: false,//滚轮改为上下(shift:左右)翻滚523 startScale: 1.0,524 maxScale: 3,525 minScale: 0.3,526 scaleSpeed: 1.08527 },528 trashcan: false,529});530editor_blockly.isCommonEntry = function () {531 var commonEntries = ['beforeBattle', 'afterBattle', 'afterOpenDoor', 'firstArrive', 'eachArrive', 'commonEvent', 'item'];532 return commonEntries.indexOf(editor_blockly.entryType) >= 0;533}534editor_blockly.entranceCategoryCallback = function(workspace) {535 var list=toolboxObj['入口方块']536 var xmlList = [];537 var eventType = (editor_blockly.isCommonEntry() ? 'common' : editor_blockly.entryType)+'_m';538 for(var ii=0,blockText;blockText=list[ii];ii++){539 if(new RegExp('<block type="'+eventType+'">').exec(blockText)){540 var block = Blockly.Xml.textToDom('<xml>'+blockText+'</xml>').firstChild;541 block.setAttribute("gap", 5);542 xmlList.push(block);543 }544 }545 return xmlList;546}547workspace.registerToolboxCategoryCallback(548 'entranceCategory', editor_blockly.entranceCategoryCallback);549editor_blockly.searchBlockCategoryCallback = function(workspace) {550 var xmlList = [];551 var labels = editor_blockly.searchBlock();552 for (var i = 0; i < labels.length; i++) {553 var blockText = '<xml>' +554 MotaActionBlocks[labels[i]].xmlText() +555 '</xml>';556 var block = Blockly.Xml.textToDom(blockText).firstChild;557 block.setAttribute("gap", 5);558 xmlList.push(block);559 }560 return xmlList;561};562workspace.registerToolboxCategoryCallback(563 'searchBlockCategory', editor_blockly.searchBlockCategoryCallback);564 565var onresize = function(e) {566 blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';567 blocklyDiv.style.height = blocklyArea.offsetHeight + 'px';568 Blockly.svgResize(workspace);569};570if(typeof editor !== "undefined" && !editor.isMobile)window.addEventListener('resize', onresize, false);571onresize();572//Blockly.svgResize(workspace);573//Blockly.bindEventWithChecks_(workspace.svgGroup_,"wheel",workspace,function(e){});574document.getElementById('blocklyDiv').onmousewheel = function(e){575 //console.log(e);576 e.preventDefault();577 var hvScroll = e.shiftKey?'hScroll':'vScroll';578 var mousewheelOffsetValue=20/380*workspace.scrollbar[hvScroll].handleLength_*3;579 workspace.scrollbar[hvScroll].handlePosition_+=( ((e.deltaY||0)+(e.detail||0)) >0?mousewheelOffsetValue:-mousewheelOffsetValue);580 workspace.scrollbar[hvScroll].onScroll_();581 // workspace.setScale(workspace.scale);582}583var doubleClickCheck=[[0,'abc']];584function omitedcheckUpdateFunction(event) {585 if(event.type==='create'){586 editor_blockly.addIntoLastUsedType(event.blockId);587 }588 if(event.type==='ui' && event.element == 'click'){589 var newClick = [new Date().getTime(),event.blockId];590 var lastClick = doubleClickCheck.shift();591 doubleClickCheck.push(newClick);592 if(newClick[0]-lastClick[0]<500){593 if(newClick[1]===lastClick[1]){594 editor_blockly.doubleClickBlock(newClick[1]);595 }596 }597 }598 // Only handle these events599 if (["create", "move", "change", "delete"].indexOf(event.type) < 0) return;600 if(editor_blockly.workspace.topBlocks_.length>=2){601 editor_blockly.setValue('入口方块只能有一个');602 return;603 }604 var eventType = editor_blockly.entryType;605 if(editor_blockly.workspace.topBlocks_.length==1){606 var blockType = editor_blockly.workspace.topBlocks_[0].type;607 if(blockType!==eventType+'_m' && !(editor_blockly.isCommonEntry() && blockType == 'common_m')){608 editor_blockly.setValue('入口方块类型错误');609 return;610 }611 }612 try {613 var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\(i|c|d|e|g|z)/g, '\\\\$1');614 editor_blockly.setValue(code);615 } catch (error) {616 editor_blockly.setValue(String(error));617 if (error instanceof OmitedError){618 var blockName = error.blockName;619 var varName = error.varName;620 var block = error.block;621 }622 // console.log(error);623 }624 }625 workspace.addChangeListener(omitedcheckUpdateFunction);626 workspace.addChangeListener(Blockly.Events.disableOrphans);627 editor_blockly.workspace = workspace;628 MotaActionFunctions.workspace = function(){629 return editor_blockly.workspace;630 }631 // 因为在editor_blockly.parse里已经HTML转义过一次了,所以这里要覆盖掉以避免在注释中出现&lt;等632 MotaActionFunctions.xmlText = function (ruleName,inputs,isShadow,comment,collapsed,disabled) {633 var rule = MotaActionBlocks[ruleName];634 var blocktext = isShadow?'shadow':'block';635 var xmlText = [];636 xmlText.push('<'+blocktext+' type="'+ruleName+'"'+(collapsed ? ' collapsed="true"' : '')+(disabled ? ' disabled="true"' : '')+'>');637 if(!inputs)inputs=[];638 for (var ii=0,inputType;inputType=rule.argsType[ii];ii++) {639 var input = inputs[ii];640 var _input = '';641 var noinput = (input===null || input===undefined);642 if(noinput && inputType==='field' && MotaActionBlocks[rule.argsGrammarName[ii]].type!=='field_dropdown') continue;643 if(noinput && inputType==='field') {644 noinput = false;645 input = rule.fieldDefault(rule.args[ii])646 }647 if(noinput) input = '';648 if(inputType==='field' && MotaActionBlocks[rule.argsGrammarName[ii]].type==='field_checkbox')input=input?'TRUE':'FALSE';649 if(inputType!=='field') {650 var subList = false;651 var subrulename = rule.argsGrammarName[ii];652 var subrule = MotaActionBlocks[subrulename];653 if (subrule instanceof Array) {654 subrulename=subrule[subrule.length-1];655 subrule = MotaActionBlocks[subrulename];656 subList = true;657 }658 _input = subrule.xmlText([],true);659 if(noinput && !subList && !isShadow) {660 //无输入的默认行为是: 如果语句块的备选方块只有一个,直接代入方块661 input = subrule.xmlText();662 }663 }664 xmlText.push('<'+inputType+' name="'+rule.args[ii]+'">');665 xmlText.push(_input+input);666 xmlText.push('</'+inputType+'>');667 }668 if(comment){669 xmlText.push('<comment>');670 xmlText.push(comment);671 xmlText.push('</comment>');672 }673 var next = inputs[rule.args.length];674 if (next) {//next675 xmlText.push('<next>');676 xmlText.push(next);677 xmlText.push('</next>');678 }679 xmlText.push('</'+blocktext+'>');680 return xmlText.join('');681 }682})();683// end mark sfergsvae...

Full Screen

Full Screen

book.ts

Source:book.ts Github

copy

Full Screen

1import { Language, cordovaApp, state, KaiDiscipline, projectAon, Section, MgnDiscipline, GndDiscipline, BookSeriesId, SectionRenderer, BookSeries, mechanicsEngine } from "..";2/** Book disciplines table */3export interface DisciplinesTable {4 /** Discipline id */5 [disciplineId: string]: {6 /** Discipline id */7 id: string,8 /** Discipline translated name */9 name: string,10 /** Discipline translated description */11 description: string,12 /** Discipline image HTML. Only for series >= Grand Master, empty string otherwise */13 imageHtml: string14 };15}16/**17 * Class to handle the Project Aon books XML18 */19export class Book {20 /** Initial books section */21 public static readonly INITIAL_SECTION = "tssf";22 /** Special unexistent section where to store objects on the Kai monastery */23 public static readonly KAIMONASTERY_SECTION = "kaimonastery";24 /** Books equipment section */25 public static readonly EQUIPMENT_SECTION = "equipmnt";26 /** Game rules section */27 public static readonly GAMERULZ_SECTION = "gamerulz";28 public static readonly COMBATRULESSUMMARY_SECTION = "crsumary";29 public static readonly KAILEVELS_SECTION = "levels";30 public static readonly HOWTOCARRY_SECTION = "howcarry";31 public static readonly HOWTOUSE_SECTION = "howuse";32 public static readonly LORECIRCLES_SECTION = "lorecrcl";33 public static readonly IMPROVEDDISCIPLINES_SECTION = "imprvdsc";34 public static readonly DISCIPLINES_SECTION = "discplnz";35 public static readonly MAP_SECTION = "map";36 /** Book index number (1 = first book) */37 public bookNumber: number;38 /** The book language */39 public language: Language;40 /** The book XML document */41 public bookXml: any;42 /**43 * Array of 100 positions with the random table numbers as they appear on the book44 */45 public bookRandomTable: number[];46 /** The book title cache, plain text */47 private bookTitle: string = null;48 /** The book copyright text cache, HTML formatted */49 private bookCopyrightHtml: string = null;50 /** The book disciplines cache */51 private disciplines: DisciplinesTable = null;52 /**53 * Constructor54 * @param number The book index number to create (1 = first)55 * @param language The book language ('es' = spanish / 'en' = english )56 */57 public constructor(num: number, language: Language) {58 this.bookNumber = num;59 this.language = language;60 this.bookXml = null;61 this.bookRandomTable = [];62 }63 /**64 * Get the root URL to download book contents65 * @return The base URL66 */67 public static getBaseUrl(): string {68 if ( cordovaApp.isRunningApp() ) {69 // Return the local downloaded books directory70 return state.localBooksLibrary.BOOKS_PATH + "/";71 } else {72 return "data/projectAon/";73 }74 }75 /** Do replacements on original XML to have a valid standalone XML.76 * It removes inclusions and replaces77 * @param xmlText The original XML78 * @return The fixed XML79 */80 public static fixXml(xmlText: string): string {81 // Code taken from Lone Wolf Adventures, by Liquid State Limited.82 // remove general directives83 // TODO: Handle all inclusions with a regex?84 xmlText = xmlText.replaceAll("%general.links;", "");85 xmlText = xmlText.replaceAll("%xhtml.links;", "");86 xmlText = xmlText.replaceAll("%general.inclusions;", "");87 xmlText = xmlText.replaceAll("%xhtml.characters;", "");88 xmlText = xmlText.replaceAll("&inclusion.joe.dever.bio.lw;", "");89 xmlText = xmlText.replaceAll("&inclusion.gary.chalk.bio.lw;", "");90 xmlText = xmlText.replaceAll("&inclusion.project.aon.license;", "");91 xmlText = xmlText.replaceAll("&inclusion.joe.dever.endowment;", "");92 xmlText = xmlText.replaceAll("&inclusion.action.chart;", "");93 xmlText = xmlText.replaceAll("&inclusion.combat.results.table;", "");94 xmlText = xmlText.replaceAll("&inclusion.action.chart.magnakai;", "");95 xmlText = xmlText.replaceAll("&inclusion.brian.williams.bio.lw;", "");96 // Link to readers handbook (Book 13)97 xmlText = xmlText.replaceAll("&link.rh;", "https://www.projectaon.org/en/ReadersHandbook/Home");98 /*xmlText = xmlText.replaceAll('&link.project.website;', '')99 xmlText = xmlText.replaceAll('&link.staff.contact;', '')100 xmlText = xmlText.replaceAll('&link.01hdlo;', '');*/101 // Replace links102 // 12-21 12:37:11.655: E/browser(1884): Console: Uncaught TypeError: Cannot supply flags when constructing one RegExp from another http://10.0.2.2/ls/statskeeper3/model/book.js:51103 // xmlText = xmlText.replace( new RegExp( /\&link\..+?\;/ , 'g' ) , '' );104 let exp = /\&link\..+?\;/g;105 xmlText = xmlText.replace( exp , "" );106 xmlText = xmlText.replaceAll("&copy;", "&amp;copy;" );107 xmlText = xmlText.replaceAll("&endash;", "-" );108 xmlText = xmlText.replaceAll("&lellips;", "&amp;hellip;" );109 // replace non-valid special characters with html special characters110 xmlText = xmlText.replaceAll("<ch.ellips/>", "&amp;hellip;");111 xmlText = xmlText.replaceAll("<ch.lellips/>", "&amp;hellip;");112 xmlText = xmlText.replaceAll("<ch.emdash/>", "&amp;mdash;");113 xmlText = xmlText.replaceAll("<ch.endash/>", "&amp;ndash;");114 xmlText = xmlText.replaceAll("<ch.apos/>", "&amp;rsquo;");115 xmlText = xmlText.replaceAll("<ch.blankline/>", "<br />");116 xmlText = xmlText.replaceAll("<ch.minus/>", "-");117 xmlText = xmlText.replaceAll("<ch.ampersand/>", "&amp;amp;");118 xmlText = xmlText.replaceAll("<ch.thinspace/>", " ");119 xmlText = xmlText.replaceAll("<ch.percent/>", "&amp;percnt;");120 // replace html special characters121 // 12-21 12:42:19.090: E/browser(1884): Console: Uncaught TypeError: Cannot supply flags when constructing one RegExp from another http://10.0.2.2/ls/statskeeper3/model/book.js:68122 // xmlText = xmlText.replace( new RegExp( /<ch\.(.+?)\/>/ , 'g' ) , "&amp;$1;");123 exp = /<ch\.(.+?)\/>/g;124 xmlText = xmlText.replace( exp , "&amp;$1;");125 // This code was previously at SectionRenderer.illustration:126 // Fix single quote markup127 xmlText = xmlText.replaceAll("&amp;rsquot;", "&amp;rsquo;");128 xmlText = xmlText.replaceAll("&amp;lsquot;", "&amp;lsquo;");129 // Fix double quote markup130 xmlText = xmlText.replaceAll("&amp;rdquot;", "&amp;rdquo;");131 xmlText = xmlText.replaceAll("&amp;ldquot;", "&amp;ldquo;");132 // On book 4, English version, the discipline id "mndblst" has been changed to "mndblast"133 // This will break the game mechanics, so keep it as "mndblst":134 xmlText = xmlText.replaceAll('"mndblast"', `"${KaiDiscipline.Mindblast}"`);135 return xmlText;136 }137 /**138 * Start the download and fix a game book139 * @return Promise with the download / fix task140 */141 public downloadBookXml(): JQueryPromise<void> {142 const self = this;143 const bookXmlUrl = this.getBookXmlURL();144 // console.log( 'Downloading book XML URL: ' + bookXmlUrl);145 return $.ajax({146 url: bookXmlUrl,147 dataType: "text"148 })149 .done((xml) => {150 self.setXml(xml);151 });152 }153 public setXml(xml: string) {154 try {155 xml = Book.fixXml(xml);156 this.bookXml = $.parseXML(xml);157 this.bookRandomTable = this.getRandomTable();158 } catch (e) {159 mechanicsEngine.debugWarning(e);160 throw e;161 }162 }163 /**164 * Start promises to download authors info165 * Added on v 1.8166 * @returns The download promises. The promises text is the author XML bio, fixed167 */168 public downloadAuthorsBio(): Array<JQueryPromise<string>> {169 try {170 const promises: Array<JQueryPromise<string>> = [];171 for ( const authorId of projectAon.supportedBooks[this.bookNumber - 1].biographies ) {172 promises.push( this.downloadAuthorInfo( authorId ) );173 }174 return promises;175 } catch (ex) {176 mechanicsEngine.debugWarning(ex);177 return null;178 }179 }180 /**181 * Start a promise to download an author info182 * @param authorId The author id (ex. "jdbiolw")183 * @returns The download promise. The promise text is the author XML bio, fixed184 */185 private downloadAuthorInfo( authorId: string ): JQueryPromise<string> {186 const authorFileUrl = Book.getBaseUrl() + this.bookNumber + "/" + authorId + "-" + this.language + ".inc";187 return $.ajax({188 url: authorFileUrl,189 dataType: "text"190 });191 }192 /**193 * Get the code name given to the book by the Project Aon194 * @param language The language for the book. If null, the current book language195 * will be used196 * @returns The book code name. null if it was not found197 */198 public getProjectAonBookCode(language: string = null): string {199 if ( !language ) {200 language = this.language;201 }202 const bookMetadata = projectAon.supportedBooks[ this.bookNumber - 1 ];203 if ( !bookMetadata ) {204 return null;205 }206 const languageCode = "code_" + language;207 const bookCode = bookMetadata[ languageCode ];208 if ( !bookCode ) {209 return null;210 }211 return bookCode;212 }213 /**214 * Returns the book XML source URL215 */216 public getBookXmlURL() {217 return Book.getBaseUrl() + this.bookNumber + "/" + this.getProjectAonBookCode() +218 ".xml";219 }220 /**221 * Returns an illustration URL222 * @param fileName The illustration file name223 * @param {Mechanics} mechanics The book mechanics. It can be null. In this case,224 * no translated images will be searched225 * @returns The image URL, relative to application root226 */227 public getIllustrationURL(fileName: string, mechanics: any = null): string {228 let illDirectory;229 if ( mechanics && mechanics.imageIsTranslated(fileName) ) {230 illDirectory = "ill_" + this.language;231 } else {232 illDirectory = "ill_en";233 }234 const illUrl = Book.getBaseUrl() + this.bookNumber + "/" + illDirectory + "/" +235 fileName;236 // console.log('Image URL: ' + illUrl);237 return illUrl;238 }239 /**240 * Returns the book HTML directory on the Project Aon web site241 * @param language The book language to get. null to get the current book242 * language243 */244 public getBookProjectAonHtmlDir(language: string): string {245 if (!language) {246 language = this.language;247 }248 return "https://projectaon.org/" + language + "/xhtml/" +249 ( language === "en" ? "lw" : "ls" ) + "/" +250 this.getProjectAonBookCode(language) + "/";251 }252 /**253 * Returns the book title254 * @returns The book title, plain text255 */256 public getBookTitle(): string {257 if ( !this.bookTitle ) {258 this.bookTitle = $( this.bookXml ).find( "gamebook > meta > title").first().text();259 }260 return this.bookTitle;261 }262 /**263 * Returns a dictionary with the disciplines info264 */265 public getDisciplinesTable(): DisciplinesTable {266 if ( !this.disciplines ) {267 const bookSeries = this.getBookSeries();268 const disciplinesSection = new Section(this, Book.DISCIPLINES_SECTION, state.mechanics);269 this.disciplines = {};270 const self = this;271 // Parse the disciplines section272 $(this.bookXml).find('section[id=discplnz] > data > section[id!="mksumary"]')273 .each( function(disciplineSection) {274 const $node = $(this);275 const disciplineId = $node.attr("id");276 let description: string;277 if ( disciplineId === MgnDiscipline.PsiSurge) {278 // Magnakai: Special case, with useful info on second paragraph. Exclude last paragraph279 description = $node.find("p:not(:last)").text();280 } else if (disciplineId === GndDiscipline.KaiSurge) {281 // Grand Master: Other special case (different). Include both (all) paragraphs282 description = $node.find("p").text();283 } else {284 description = $node.find("p").first().text();285 }286 let imageHtml: string = "";287 if (bookSeries.id >= BookSeriesId.GrandMaster) {288 const $disciplineIll = $node.find("> data > illustration").first();289 imageHtml = SectionRenderer.renderIllustration(disciplinesSection, $disciplineIll);290 }291 self.disciplines[disciplineId] = {292 id: disciplineId,293 name: $node.find("> meta > title").text(),294 description,295 imageHtml296 };297 });298 }299 return this.disciplines;300 }301 /**302 * Get the book section with the given id.303 * @param sectionId The section id to get304 * @return The related section. An empty selection if the section id was not found305 */306 public getSectionXml(sectionId: string): JQuery<Element> {307 return $(this.bookXml).find("section[id=" + sectionId + "]");308 }309 /**310 * Check if the book contains a section id311 * @param sectionId The section id to search312 * @return True if the book contains the given section313 */314 public hasSection(sectionId: string): boolean {315 return this.getSectionXml(sectionId).length > 0;316 }317 /**318 * Get the book copyright HTML319 * @returns The book copyright text, HTML formatted320 */321 public getCopyrightHtml(): string {322 if ( !this.bookCopyrightHtml ) {323 const fakeSection = new Section(this, "fakeSection", null);324 const renderer = new SectionRenderer(fakeSection);325 const selector = 'rights[class="copyrights"]';326 this.bookCopyrightHtml = renderer.renderNodeChildren( $(this.bookXml).find(selector) , 0 );327 }328 return this.bookCopyrightHtml;329 }330 /**331 * Get the Kai title for a given number of disciplines332 * @param nDisciplines Number of disciplines333 * @return The kai title334 */335 public getKaiTitle(nDisciplines: number): string {336 // Normalize337 if ( nDisciplines < 1 ) {338 nDisciplines = 1;339 } else if ( nDisciplines > 10 ) {340 nDisciplines = 10;341 }342 // Get the title343 let title = $(this.bookXml)344 .find('section[id="levels"] > data > ol > li:eq(' + (nDisciplines - 1) + ")")345 .text();346 if ( !title ) {347 title = "Unknown";348 }349 // For the level 5, there is an extra explanation to remove:350 // &mdash;You begin the Lone Wolf adventures with this level of Kai training351 let idx = title.indexOf( "&mdash;");352 if ( idx >= 0 ) {353 title = title.substr(0, idx).trim();354 }355 // On book 6 (spanish), there is a parenthesis: Maestro Superior del Kai (con este...356 idx = title.indexOf( "(");357 if ( idx >= 0 ) {358 title = title.substr(0, idx).trim();359 }360 return title;361 }362 /**363 * Get sections that have a choice to go to some section364 * @param sectionId The destination section365 * @return Section ids that can go to the given section366 */367 public getOriginSections(sectionId: string): string[] {368 const sourceSectionIds = [];369 const sourceSections = $(this.bookXml)370 .find('section[class="numbered"]' )371 .has( 'data > choice[idref="' + sectionId + '"]')372 .each( (index, section) => {373 sourceSectionIds.push( $(section).attr("id") );374 }) ;375 return sourceSectionIds;376 }377 /**378 * Get the book cover image URL379 */380 public getCoverURL(): string {381 return Book.getBaseUrl() + this.bookNumber + "/cover.jpg";382 }383 /**384 * Return an array of 2 positions with the combat tables images385 */386 public getCombatTablesImagesUrls(mechanics) {387 const images = [];388 images.push( this.getIllustrationURL( "crtpos.png", mechanics) );389 images.push( this.getIllustrationURL( "crtneg.png", mechanics ) );390 return images;391 }392 /**393 * Get the book random table number394 * @return Array with the 100 numbers of the random table395 */396 public getRandomTable(): number[] {397 const $randomCells = $(this.bookXml)398 .find("section[id=random] > data > illustration > instance[class=text]")399 .find("td");400 const numbers = [];401 for (const cell of $randomCells.toArray()) {402 numbers.push( parseInt( $(cell).text(), 10 ) );403 }404 return numbers;405 }406 public getBookSeries(): BookSeries {407 return BookSeries.getBookNumberSeries(this.bookNumber);408 }409 public getSectionsIds(): string[] {410 const sectionIds: string[] = [];411 let sectionId = Book.INITIAL_SECTION;412 while (sectionId != null) {413 sectionIds.push(sectionId);414 const section = new Section(this, sectionId, state.mechanics);415 sectionId = section.getNextSectionId();416 }417 return sectionIds;418 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { XmlText } = require('pact-foundation/pact-node');2console.log(XmlText);3const pact = require('pact-foundation/pact-node');4console.log(pact.XmlText);5const pact = require('pact-foundation/pact-node');6console.log(pact.default.XmlText);7const pact = require('pact-foundation/pact-node');8console.log(pact.default);9const pact = require('pact-foundation/pact-node');10console.log(pact.default.default);11const pact = require('pact-foundation/pact-node');12console.log(pact.default.default.XmlText);13const pact = require('pact-foundation/pact-node');14console.log(pact.XmlText);15const pact = require('pact-foundation/pact-node');16console.log(pact.default.XmlText);17const pact = require('pact-foundation/pact-node');18console.log(pact.default.default.XmlText);19const pact = require('pact-foundation/pact-node');20console.log(pact.default.default.XmlText);21const pact = require('pact-foundation/pact-node');22console.log(pact.default.default.default.XmlText);23const pact = require('pact-foundation/pact-node');24console.log(pact.default.default.default.default.XmlText);

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation/pact-node');2var path = require('path');3var opts = {4 pactUrls: [path.resolve(process.cwd(), 'pacts', 'test-provider-test-consumer.json')]5};6pact.verifyPacts(opts).then(function () {7 console.log('Pact Verification Complete!')8 console.log('')9 console.log('Do you want to publish the pact file to a broker?')10}).catch(function (e) {11 console.log('Pact Verification Failed: ', e)12});13var pact = require('pact-foundation/pact-node');14var path = require('path');15var opts = {16 pactUrls: [path.resolve(process.cwd(), 'pacts', 'test-provider-test-consumer.json')],17};18pact.publishPacts(opts).then(function () {19 console.log('Pact contract publishing complete!')20 console.log('')21 console.log('=> Username: dX

Full Screen

Using AI Code Generation

copy

Full Screen

1const pact = require('pact-foundation/pact-node');2pact.run(['--help'], {logLevel: 'debug'}).then(function (res) {3 console.log('res:', res);4});5const pact = require('pact-foundation/pact-node');6pact.run(['--help'], {logLevel: 'debug'}).then(function (res) {7 console.log('res:', res);8});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful