Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;###########################################################################################################################################
- ; Mini-framework
- /**
- * The code depends on a "settings" global variable that should be defined in each script as such : settings := checkSettingsFile()
- */
- checkSettingsFile() {
- dir := A_WorkingDir
- file := dir . "\settings.xml"
- settingsFile := dir . "\bin\createSettings"
- format1 := ".exe"
- format2 := ".ahk"
- If not FileExist(file)
- {
- ;MsgBox % "Have to recreate settings file"
- IfExist, %settingsFile%%format1%
- Run, %settingsFile%%format1%
- IfExist, %settingsFile%%format2%
- Run, %settingsFile%%format2%
- IfNotExist, %settingsFile%%format1%
- {
- IfNotExist, %settingsFile%%format2%
- {
- MsgBox % "No bin\createSettings.exe file found"
- ExitApp
- }
- }
- }
- ; if it still doesn't exist wait for it to be created
- WaitForSettingsFile:
- If not FileExist(file)
- goto WaitForSettingsFile
- return loadSettings(file) ; once it's created, load it
- }
- loadSettings(filepath) {
- FileRead, settingsXML, %filepath%
- doc := ComObjCreate("MSXML2.DOMDocument.6.0") ; Initialize the xml object
- doc.async := false
- doc.loadXML(settingsxml)
- return doc
- }
- ;https://msdn.microsoft.com/en-us/library/ms757828(v=vs.85).aspx
- getSettingFrom(path,settings) {
- return settings.selectSingleNode(path).text
- }
- writeSettingTo(path,settings,setting) {
- settings.selectSingleNode(path).text := setting
- }
- flushXML(settings) {
- settings.save("settings.xml")
- }
- cNXRef(imageName) {
- Loop
- {
- FileReadLine, line, bin\CNXRef.txt, %A_Index%
- if ErrorLevel
- break
- xrefArray := StrSplit(line,":")
- if (xrefArray[1]=imageName)
- return xrefArray[2]
- }
- }
- rCNXRef(champName) {
- Loop
- {
- FileReadLine, line, bin\CNXRef.txt, %A_Index%
- if ErrorLevel
- break
- xrefArray := StrSplit(line,":")
- if (xrefArray[2]=champName)
- return xrefArray[1]
- }
- }
- find(xi,yi,xf,yf,p) {
- ImageSearch,,, %xi%, %yi%, %xf%, %yf%, *%tolerance% %p%
- }
- findAndExec(xi,yi,xf,yf,p,l,e=0) {
- ImageSearch, fx, fy, %xi%, %yi%, %xf%, %yf%, *%tolerance% %p%
- if (ErrorLevel=e and isLabel(l))
- gosub %l%
- }
- findAndClick(xi,yi,xf,yf,p,w,h) {
- ImageSearch, fx, fy, %xi%, %yi%, %xf%, %yf%, *%tolerance% %p%
- if (ErrorLevel = 0) {
- fx := fx + w/2
- fy := fy + h/2
- ClickAndReturn(fx,fy)
- }
- }
- findOptionsAndExec(xi,yi,xf,yf,o,p,l,e=0) {
- ImageSearch, fx, fy, %xi%, %yi%, %xf%, %yf%, *%tolerance% %o% %p%
- if (ErrorLevel=e and isLabel(l))
- gosub %l%
- }
- findUntilClick(xi,yi,xf,yf,p,w,h) {
- WaitTillFound:
- findAndClick(xi,yi,xf,yf,p,w,h)
- if (ErrorLevel=1)
- goto WaitTillFound
- }
- clickAndReturn(x,y) {
- CoordMode, Mouse, Screen
- MouseGetPos, iniX, iniY
- CoordMode, Mouse, Window
- MouseMove, %x%, %y%
- Click, %x%, %y%
- CoordMode, Mouse, Screen
- MouseMove, %iniX%, %iniY%
- CoordMode, Mouse, Window
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement