Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;###########################################################################################################################################
  2. ;                                                               Mini-framework
  3.  
  4. /**
  5.   * The code depends on a "settings" global variable that should be defined in each script as such : settings := checkSettingsFile()
  6.   */
  7.  
  8. checkSettingsFile() {
  9.     dir := A_WorkingDir
  10.     file := dir . "\settings.xml"
  11.     settingsFile :=  dir . "\bin\createSettings"
  12.     format1 := ".exe"
  13.     format2 := ".ahk"
  14.     If not FileExist(file)
  15.     {
  16.         ;MsgBox % "Have to recreate settings file"
  17.         IfExist, %settingsFile%%format1%
  18.             Run, %settingsFile%%format1%
  19.         IfExist, %settingsFile%%format2%
  20.             Run, %settingsFile%%format2%
  21.         IfNotExist, %settingsFile%%format1%
  22.         {
  23.             IfNotExist, %settingsFile%%format2%
  24.             {
  25.                 MsgBox % "No bin\createSettings.exe file found"
  26.                 ExitApp
  27.             }
  28.         }
  29.     }
  30.     ; if it still doesn't exist wait for it to be created
  31. WaitForSettingsFile:
  32.     If not FileExist(file)
  33.         goto WaitForSettingsFile
  34.    
  35.     return loadSettings(file)   ; once it's created, load it
  36. }
  37.  
  38. loadSettings(filepath) {
  39.     FileRead, settingsXML, %filepath%
  40.     doc := ComObjCreate("MSXML2.DOMDocument.6.0")   ; Initialize the xml object
  41.     doc.async := false                         
  42.     doc.loadXML(settingsxml)       
  43.     return doc
  44. }
  45.  
  46. ;https://msdn.microsoft.com/en-us/library/ms757828(v=vs.85).aspx
  47. getSettingFrom(path,settings) {
  48.     return settings.selectSingleNode(path).text
  49. }
  50.  
  51. writeSettingTo(path,settings,setting) {
  52.     settings.selectSingleNode(path).text := setting
  53. }
  54.  
  55. flushXML(settings) {
  56.     settings.save("settings.xml")
  57. }
  58.  
  59. cNXRef(imageName) {
  60.     Loop
  61.     {
  62.         FileReadLine, line, bin\CNXRef.txt, %A_Index%
  63.         if ErrorLevel
  64.             break
  65.         xrefArray := StrSplit(line,":")
  66.         if (xrefArray[1]=imageName)
  67.             return xrefArray[2]
  68.     }
  69. }
  70.  
  71. rCNXRef(champName) {
  72.     Loop
  73.     {
  74.         FileReadLine, line, bin\CNXRef.txt, %A_Index%
  75.         if ErrorLevel
  76.             break
  77.         xrefArray := StrSplit(line,":")
  78.         if (xrefArray[2]=champName)
  79.             return xrefArray[1]
  80.     }
  81. }
  82.  
  83. find(xi,yi,xf,yf,p) {
  84.     ImageSearch,,, %xi%, %yi%, %xf%, %yf%, *%tolerance% %p%
  85. }
  86.  
  87. findAndExec(xi,yi,xf,yf,p,l,e=0) {
  88.     ImageSearch, fx, fy, %xi%, %yi%, %xf%, %yf%, *%tolerance% %p%
  89.     if (ErrorLevel=e and isLabel(l))
  90.         gosub %l%
  91. }
  92.  
  93. findAndClick(xi,yi,xf,yf,p,w,h) {
  94.     ImageSearch, fx, fy, %xi%, %yi%, %xf%, %yf%, *%tolerance% %p%
  95.     if (ErrorLevel = 0) {
  96.         fx := fx + w/2
  97.         fy := fy + h/2
  98.         ClickAndReturn(fx,fy)
  99.     }
  100. }
  101.  
  102. findOptionsAndExec(xi,yi,xf,yf,o,p,l,e=0) {
  103.     ImageSearch, fx, fy, %xi%, %yi%, %xf%, %yf%, *%tolerance% %o% %p%
  104.     if (ErrorLevel=e and isLabel(l))
  105.         gosub %l%
  106. }
  107.  
  108. findUntilClick(xi,yi,xf,yf,p,w,h) {
  109. WaitTillFound:
  110.     findAndClick(xi,yi,xf,yf,p,w,h)
  111.     if (ErrorLevel=1)
  112.         goto WaitTillFound
  113. }
  114.  
  115. clickAndReturn(x,y) {
  116.     CoordMode, Mouse, Screen
  117.     MouseGetPos, iniX, iniY
  118.     CoordMode, Mouse, Window
  119.     MouseMove, %x%, %y%
  120.     Click, %x%, %y%
  121.     CoordMode, Mouse, Screen
  122.     MouseMove, %iniX%, %iniY%
  123.     CoordMode, Mouse, Window
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement