====== About the script ====== * Purpose : This script converts any shortcut in one of those puzzles where there is a hole and you need to move tiles to make a picture. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/u/1/105066926163073195690/posts/WxnVvQnzTmv (with video) ====== How to use the script ====== Instructions: * Run the script from the item, if it is the first time it will override the default item with the custom one, otherwise it will recover that saved item. * Choose the grid size and the color of the piece (hole). It will automatically set the script to the four swipe directions, swipe from the item and solve the item. Optionally it will disable the tap to launch action. At the beginning there is the function that runs when solved, by default it launches the item, you can modify it if prefer. Note 1: the randomize function is random, it won't never leave the puzzle resolved, but can leave it with a one-move-to-solve. Note 2: it uses some bitmap copies, for me it works but maybe it freezes in devices with less memory. Note 3: I tested it personally in my main screen, and it works well, however I didn't add checks, so be sure the inputs in the setup are ok. If it crash or makes an error write a comment. I know it is just another mini-game made with scripts and no really useful, but: you can set it as a lock screen! No need to remember patterns, only resolve a not so easy puzzle. Or set it to protect apps, or even as a way to self control if you don't want to open an app a lot of times ;D ====== Script code ====== //this is launched when resolved, modify as you want function completed(){ //alert("yes!"); it.launch(); } var e=LL.getEvent(); var it=e.getItem(); if(it==null){alert("no item");return;} var img=it.getCustomIcon(); if(img==null){ alert("No custom icon, assigning default one"); it.setCustomIcon(copyImage(it.getDefaultIcon())); img=it.getCustomIcon(); } var bit=img.getBitmap(); var grid=[null,null]; var orig=[null,null]; var hole=[null,null]; var size=[null,null]; var data=JSON.parse(it.getTag("puzzle")); if(data==null){ initialize(true); return; } grid=data.g; hole=data.h; orig=data.o; size=[ bit.getWidth()/grid[0] , bit.getHeight()/grid[1] ]; var dir=e.getSource(); if(dir=="MENU_ITEM"){initialize(false);return;} if(dir=="I_RESUMED"||dir=="bug I_PAUSED"){randomize();return;} var to=null; if(dir=="I_SWIPE_LEFT"&&hole[0]0)to=[-1,0]; if(dir=="I_SWIPE_UP"&&hole[1]0)to=[0,-1]; if(to==null)return; var newhole=sum(hole,to); //exchange var one=getSlot(hole,bit); var two=getSlot(newhole,bit); setSlot(hole,two,bit); setSlot(newhole,one,bit); hole=newhole; img.update(); img.save(); //save it.setTag("puzzle",JSON.stringify({g:grid,o:orig,h:hole})); //check var def=it.getDefaultIcon(); var original=def.getBitmap(); var current=copyImage(img).getBitmap(); setSlot(hole,getSlot(orig,original),current); if(current.sameAs(original)){ //save and set the original img=copyImage(img); bit=img.getBitmap(); it.setCustomIcon(def); setTimeout(function(){ completed(); //restore the saved (randomizated) setTimeout(function(){randomize(); it.setCustomIcon(img);},0); },250); } function randomize(){ var a=[];//virtual image for(var i=0;i=grid[0]||n[1]<0||n[1]>=grid[1])continue; var temp=a[h[0]][h[1]]; a[h[0]][h[1]]=a[n[0]][n[1]]; a[n[0]][n[1]]=temp; h=n; } hole=h; //virtual->real var original=copyImage(img).getBitmap(); for(var i=0;i