{"commit":"7b27dea4e9eed72f15be8233d341b284c236003c","subject":"Added config import.","message":"Added config import.\n\n--HG--\nextra : convert_revision : svn%3Ae934d3cd-0d57-f34a-94d0-9e8d31ae1c29\/trunk%4095\n","repos":"programmerby\/diddy-mirror,programmerby\/diddy-mirror,programmerby\/diddy-mirror,programmerby\/diddy-mirror","old_file":"src\/diddy\/diddy.monkey","new_file":"src\/diddy\/diddy.monkey","new_contents":"'\r\n' Module diddy.diddy\r\n'\r\n\r\nImport functions\r\nImport framework\r\nImport inputcache\r\nImport tween\r\nImport collections\r\nImport assert\r\nImport gui\r\nImport config\r\n\r\n","old_contents":"'\r\n' Module diddy.diddy\r\n'\r\n\r\nImport functions\r\nImport framework\r\nImport inputcache\r\nImport tween\r\nImport collections\r\nImport assert\r\nImport gui\r\n\r\n","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"e39cd8ded119665a31c5861861e93c53417a45cc","subject":"Added the option to make 'virtualos' a standalone module (For now).","message":"Added the option to make 'virtualos' a standalone module (For now).\n","repos":"Regal-Internet-Brothers\/virtualos","old_file":"virtualos.monkey","new_file":"virtualos.monkey","new_contents":"Strict\n\nPublic\n\n' Preprocessor related:\n#VIRTUALOS_FLAG_OS = True\n#VIRTUALOS_STANDALONE = True\n\n#If TARGET = \"html5\"\n\t#VIRTUALOS_JS_TARGET = True\n#End\n\n#If VIRTUALOS_JS_TARGET\n\t#VIRTUALOS_IMPLEMENTED = True\n\t#VIRTUALOS_MAP_ENV = True\n\t#VIRTUALOS_MAP_FILETIMES = True\n\t#VIRTUALOS_EXTENSION_DL = True\n\t#VIRTUALOS_EXTENSION_VFILE = True\n\t#VIRTUALOS_EXTENSION_REMOTEPATH = True\n\t'#VIRTUALOS_REAL_FILEPATH = True\n\t\n\t#If CONFIG = \"debug\"\n\t\t'#VIRTUALOS_DEBUG = True\n\t#End\n#Elseif LANG = \"cpp\" And TARGET <> \"win8\" And TARGET <> \"ios\"\n\t#VIRTUALOS_REAL = True\n#End\n\n#If VIRTUALOS_IMPLEMENTED\n\t#If VIRTUALOS_FLAG_OS\n\t\t#BRL_OS_IMPLEMENTED = True\n\t#End\n#End\n\n' Imports (Public):\n#If Not VIRTUALOS_IMPLEMENTED\n\t#If VIRTUALOS_REAL\n\t\tImport os\n\t#End\n#Else\n\tImport \"native\/os.${LANG}\"\n#End\n\n#If VIRTUALOS_REAL_FILEPATH\n\tImport brl.filepath\n#End\n\n' Imports (Private):\nPrivate\n\n#If VIRTUALOS_IMPLEMENTED\n\t#If Not VIRTUALOS_STANDALONE\n\t\tImport regal.stringutil\n\t\t\n\t\t#If VIRTUALOS_EXTENSION_DL And VIRTUALOS_EXTENSION_VFILE\n\t\t\tImport regal.ioutil.stringstream\n\t\t#End\n\t#Else\n\t\tImport brl.databuffer\n\t\tImport brl.datastream\n\t#End\n\t\n\tImport monkey.map\n\t\n\t#If VIRTUALOS_JS_TARGET\n\t\t'Import dom\n\t#End\n#End\n\nPublic\n\n#If VIRTUALOS_IMPLEMENTED\n\t' Constant variable(s) (Public):\n\t\n\t' File-types (Must be the same across borders):\n\tConst FILETYPE_NONE:=\t\t0\n\tConst FILETYPE_FILE:=\t\t1\n\tConst FILETYPE_DIR:=\t\t2\n\t\n\tConst FILETIME_UNAVAILABLE:= 0\n\t\n\t' Constant variable(s) (Private):\n\tPrivate\n\t\n\t#If VIRTUALOS_STANDALONE\n\t\tConst STRING_INVALID_LOCATION:= -1\n\t#End\n\t\n\tPublic\n\t\n\t' External bindings:\n\tExtern\n\t\n\t' Global variable(s) (External) (Private):\n\tExtern Private\n\t\n\t' If you are supporting these extensions, please provide '__OS_Storage'.\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\t#If VIRTUALOS_JS_TARGET\n\t\t\tGlobal __OS_Storage:StorageHandle=\"__os_storage\"\n\t\t#End\n\t#End\n\t\n\tExtern\n\t\n\t' Classes (External) (Private):\n\tExtern Private\n\t\n\t' API:\n\t' Nothing so far.\n\t\n\t' Extensions:\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\t#If VIRTUALOS_JS_TARGET\n\t\t\tClass StorageHandle = \"Storage\" ' Extends DOMObject\n\t\t\t\t' Methods:\n\t\t\t\t' Nothing so far.\n\t\t\tEnd\n\t\t#Else\n\t\t\t#Error \"Unable to resolve type: 'StorageHandle'\"\n\t\t#End\n\t#End\n\t\n\tExtern\n\t\n\t' Functions (External):\n\t\n\t' API:\n\tFunction HostOS:String()\n\tFunction AppPath:String()\n\tFunction AppArgs:String[]()\n\tFunction RealPath:String(Path:String)\n\tFunction FileType:Int(Path:String)\n\tFunction FileSize:Int(Path:String)\n\t\n\t#If Not VIRTUALOS_MAP_FILETIMES\n\t\tFunction FileTime:Int(Path:String)\n\t\t\n\t\tFunction CopyFile:Bool(Src:String, Dst:String)\n\t\tFunction DeleteFile:Bool(Path:String)\n\t#Else\n\t\tFunction _CopyFile:Bool(Src:String, Dst:String)=\"CopyFile\"\n\t\tFunction _DeleteFile:Bool(Path:String)=\"DeleteFile\"\n\t#End\n\t\n\tFunction LoadString:String(Path:String)\n\tFunction SaveString:Int(Str:String, Path:String)\n\tFunction LoadDir:String[](Path:String)\n\tFunction CreateDir:Bool(Path:String)\n\tFunction DeleteDir:Bool(Path:String)\n\tFunction ChangeDir:Int(Path:String)\n\tFunction CurrentDir:String()\n\t\n\t#If Not VIRTUALOS_MAP_ENV\n\t\tFunction SetEnv:Int(Name:String, Value:String)\n\t\tFunction GetEnv:String(Name:String)\n\t#End\n\t\n\tFunction Execute:Int(CMD:String)\n\t\n\t#If Not VIRTUALOS_DEBUG\n\t\tFunction ExitApp:Int(RetCode:Int)\n\t#Else\n\t\tFunction _ExitApp:Int(RetCode:Int)=\"ExitApp\"\n\t#End\n\t\n\t' Extensions:\n\t#If VIRTUALOS_EXTENSION_REMOTEPATH\n\t\tFunction __OS_ToRemotePath:String(RealPath:String)=\"__os_toRemotePath\"\n\t#End\n\t\n\t#If VIRTUALOS_EXTENSION_DL\n\t\tFunction __OS_Download:String(URL:String)=\"__os_download\"\n\t\t\n\t\t' Virtual file-system (JavaScript) extensions:\n\t\t#If VIRTUALOS_EXTENSION_VFILE ' VIRTUALOS_JS_TARGET\n\t\t\tFunction __OS_DownloadFileUsingRep:String(Storage:StorageHandle, URL:String, Rep:String)=\"__os_downloadFileUsingRep\"\n\t\t\tFunction __OS_DownloadFile:String(Storage:StorageHandle, RealPath:String)=\"__os_downloadFile\"\n\t\t#End\n\t#End\n\t\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\tFunction __OS_StorageSupported:Bool()=\"__os_storageSupported\"\n\t\tFunction __OS_CreateFileLink:Void(Rep:String)=\"__os_createFileLink\"\n\t#End\n\t\n\tPublic\n\t\n\t' Global variable(s) (Private):\n\tPrivate\n\t\n\t#If VIRTUALOS_MAP_ENV\n\t\tGlobal __OS_Env:= New StringMap()\n\t#End\n\t\n\t#If VIRTUALOS_MAP_FILETIMES\n\t\tGlobal __OS_FileTimes:= New StringMap()\n\t#End\n\t\n\tPublic\n\t\n\t' Functions (Monkey) (Public):\n\t\n\t' API:\n\t#If VIRTUALOS_MAP_ENV\n\t\tFunction SetEnv:Void(name:String, value:String)\n\t\t\t__OS_Env.Set(name, value)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction GetEnv:String(name:String)\n\t\t\tReturn __OS_Env.Get(name)\n\t\tEnd\n\t#End\n\t\n\t#If VIRTUALOS_MAP_FILETIMES\n\t\tFunction FileTime:Int(Path:String)\n\t\t\tReturn __OS_FileTimes.Get(RealPath(Path)) ' FILETIME_UNAVAILABLE\n\t\tEnd\n\t\t\n\t\tFunction CopyFile:Bool(Src:String, Dst:String)\n\t\t\tLocal Result:= _CopyFile(Src, Dst)\n\t\t\t\n\t\t\tIf (Result) Then\n\t\t\t\t__OS_SetFileTime(RealPath(Dst), FileTime(Src)) ' ; Return True\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Result ' False\n\t\tEnd\n\t\t\n\t\tFunction DeleteFile:Bool(Path:String)\n\t\t\tLocal Result:= _DeleteFile(Path)\n\t\t\t\n\t\t\tIf (Result) Then\n\t\t\t\t__OS_RemoveFileTime(RealPath(Path))\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Result\n\t\tEnd\n\t#End\n\t\n\tFunction LoadDir:String[](Path:String, Recursive:Bool, Hidden:Bool=False)\n\t\tLocal Dirs:= New StringDeque()\n\t\tLocal Files:= New StringDeque()\n\t\t\n\t\t' Add an initial value for safety.\n\t\tDirs.PushFirst(\"\")\n\t\t\n\t\tWhile (Not Dirs.IsEmpty)\n\t\t\tLocal Dir:= Dirs.PopFirst()\n\t\t\t\n\t\t\tFor Local F:= Eachin LoadDir(Path + \"\/\" + Dir)\n\t\t\t\tIf ((Not Hidden) And F.StartsWith(\".\")) Then\n\t\t\t\t\tContinue\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tIf (Dir.Length > 0) Then\n\t\t\t\t\tF = Dir + \"\/\" + F\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tSelect (FileType(Path + \"\/\" + F))\n\t\t\t\t\tCase FILETYPE_FILE\n\t\t\t\t\t\tFiles.PushLast(F)\n\t\t\t\t\tCase FILETYPE_DIR\n\t\t\t\t\t\tIf (Recursive) Then\n\t\t\t\t\t\t\tDirs.PushLast(F)\n\t\t\t\t\t\tElse\n\t\t\t\t\t\t\tFiles.PushLast(F)\n\t\t\t\t\t\tEndif\n\t\t\t\tEnd Select\n\t\t\tNext\n\t\tWend\n\t\n\t\tReturn Files.ToArray()\n\tEnd\n\t\n\tFunction CopyDir:Bool(SourcePath:String, DestinationPath:String, Recursive:Bool=True, Hidden:Bool=False)\n\t\tIf (FileType(SourcePath) <> FILETYPE_DIR) Then\n\t\t\tReturn False\n\t\tEndif\n\t\t\n\t\tLocal Files:= LoadDir(SourcePath)\n\t\t\n\t\tSelect (FileType(DestinationPath))\n\t\t\tCase FILETYPE_NONE\n\t\t\t\tIf (Not CreateDir(DestinationPath)) Then\n\t\t\t\t\tReturn False\n\t\t\t\tEndif\n\t\t\tCase FILETYPE_FILE\n\t\t\t\tReturn False\n\t\tEnd Select\n\t\t\n\t\tFor Local F:= Eachin Files\n\t\t\tIf ((Not Hidden) And F.StartsWith(\".\")) Then\n\t\t\t\tContinue\n\t\t\tEndif\n\t\t\t\n\t\t\tLocal SrcP:= (SourcePath + \"\/\" + F)\n\t\t\tLocal DstP$= (DestinationPath + \"\/\" + F)\n\t\t\t\n\t\t\tSelect (FileType(SrcP))\n\t\t\t\tCase FILETYPE_FILE\n\t\t\t\t\tIf (Not CopyFile(SrcP, DstP)) Then\n\t\t\t\t\t\tReturn False\n\t\t\t\t\tEndif\n\t\t\t\tCase FILETYPE_DIR\n\t\t\t\t\tIf (Recursive And (Not CopyDir(SrcP, DstP, Recursive, Hidden))) Then\n\t\t\t\t\t\tReturn False\n\t\t\t\t\tEndif\n\t\t\tEnd Select\n\t\tNext\n\t\t\n\t\t' Return the default response.\n\t\tReturn True\n\tEnd\n\t\n\tFunction DeleteDir:Bool(Path$, Recursive:Bool)\n\t\tIf (Not Recursive) Then\n\t\t\tReturn DeleteDir(Path)\n\t\tEndif\n\t\t\n\t\tSelect (FileType(Path))\n\t\t\tCase FILETYPE_NONE\n\t\t\t\tReturn True\n\t\t\tCase FILETYPE_FILE\n\t\t\t\tReturn False\n\t\tEnd Select\n\t\t\n\t\tFor Local F:= Eachin LoadDir(Path)\n\t\t\tIf (F = \".\" Or F = \"..\") Then\n\t\t\t\tContinue\n\t\t\tEndif\n\t\t\t\n\t\t\tLocal FPath:= (Path + \"\/\" + F)\n\t\n\t\t\tIf (FileType(FPath) = FILETYPE_DIR) Then\n\t\t\t\tIf (Not DeleteDir(FPath, True)) Then\n\t\t\t\t\tReturn False\n\t\t\t\tEndif\n\t\t\tElse\n\t\t\t\tIf (Not DeleteFile(FPath)) Then\n\t\t\t\t\tReturn False\n\t\t\t\tEndif\n\t\t\tEndif\n\t\tNext\n\t\n\t\tReturn DeleteDir(Path)\n\tEnd\n\t\n\t#If Not VIRTUALOS_REAL_FILEPATH\n\t\tFunction StripDir:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\"\/\")\n\t\t\t\n\t\t\tIf (I = STRING_INVALID_LOCATION) Then\n\t\t\t\tI = Path.FindLast( \"\\\" )\n\t\t\tEndif\n\t\t\t\n\t\t\tIf (I <> STRING_INVALID_LOCATION) Then\n\t\t\t\tReturn Path[I+1..]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Path\n\t\tEnd\n\t\t\n\t\tFunction ExtractDir:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\"\/\")\n\t\t\t\n\t\t\tIf (I = STRING_INVALID_LOCATION) Then\n\t\t\t\tI = Path.FindLast(\"\\\")\n\t\t\tEndif\n\t\t\t\n\t\t\tIf (I <> STRING_INVALID_LOCATION) Then\n\t\t\t\tReturn Path[..I]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn \"\"\n\t\tEnd\n\t\t\n\t\tFunction StripExt:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\".\")\n\t\t\tLocal SecondarySearchPos:= (I+1)\n\t\t\t\n\t\t\tIf ((I <> STRING_INVALID_LOCATION) And (Path.Find(\"\/\", SecondarySearchPos) = STRING_INVALID_LOCATION) And (Path.Find(\"\\\", SecondarySearchPos)= STRING_INVALID_LOCATION)) Then\n\t\t\t\tReturn Path[..I]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Path\n\t\tEnd\n\t\t\n\t\tFunction ExtractExt:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\".\")\n\t\t\tLocal SecondarySearchPos:= (I+1)\n\t\t\t\n\t\t\tIf ((I <> STRING_INVALID_LOCATION) And (Path.Find(\"\/\", SecondarySearchPos) = STRING_INVALID_LOCATION) And (Path.Find(\"\\\", SecondarySearchPos)= STRING_INVALID_LOCATION)) Then\n\t\t\t\tReturn Path[SecondarySearchPos..]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn \"\"\n\t\tEnd\n\t\t\n\t\tFunction StripAll:String(Path:String)\n\t\t\tReturn StripDir(StripExt(Path))\n\t\tEnd\n\t#End\n\t\n\t' Debugging related:\n\t#If VIRTUALOS_DEBUG\n\t\tFunction ExitApp:Int(RetCode:Int)\n\t\t\tDebugStop()\n\t\t\t\n\t\t\t_ExitApp(RetCode)\n\t\t\t\n\t\t\tReturn 0\n\t\tEnd\n\t#End\n\t\n\t' Extensions:\n\t#If VIRTUALOS_MAP_FILETIMES\n\t\tFunction __OS_SetFileTime:Void(RealPath:String, Time:Int)\n\t\t\t__OS_FileTimes.Set(RealPath, Time)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction __OS_RemoveFileTime:Void(RealPath:String)\n\t\t\t__OS_FileTimes.Remove(RealPath)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t#End\n\t\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\t#If VIRTUALOS_EXTENSION_DL\n\t\t\tFunction __OS_AddFileSystem:Void(URL:String)\n\t\t\t\tLocal FileData:= __OS_Download(URL)\n\t\t\t\t\n\t\t\t\t#If Not VIRTUALOS_STANDALONE\n\t\t\t\t\tLocal SS:= New StringStream(FileData, ,,,, True)\n\t\t\t\t#Else\n\t\t\t\t\tLocal Buf:= New DataBuffer(FileData.Length)\n\t\t\t\t\t\n\t\t\t\t\tBuf.PokeString(0, FileData)\n\t\t\t\t\t\n\t\t\t\t\tLocal SS:= New DataStream(Buf)\n\t\t\t\t#End\n\t\t\t\t\n\t\t\t\t__OS_ParseFileSystem(SS)\n\t\t\t\t\n\t\t\t\tReturn\n\t\t\tEnd\n\t\t#End\n\t\t\n\t\tFunction __OS_ParseFileSystem:Void(S:Stream) ' StringStream\n\t\t\t__OS_ParseFileSystem(S, New StringStack())\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction __OS_ParseFileSystem_Update_ContextRep:String(Context:Stack)\n\t\t\tLocal Rep:String\n\t\t\t\n\t\t\tFor Local Folder:= Eachin Context\n\t\t\t\tRep += (Folder + \"\/\")\n\t\t\tNext\n\t\t\t\n\t\t\tReturn Rep\n\t\tEnd\n\t\t\n\t\t' A simple parser that takes each line of a 'Stream', and decodes a folder structure from the input.\n\t\t' The 'OpenPrefix' argument is used to toggle adding an extra slash before generated paths.\n\t\tFunction __OS_ParseFileSystem:Void(S:Stream, Context:Stack, OpenPrefix:Bool=True) ' StringStream\n\t\t\t' Constant variable(s):\n\t\t\t#If Not VIRTUALOS_STANDALONE\n\t\t\t\tConst DIVIDER:= ASCII_CHARACTER_SPACE\n\t\t\t#Else\n\t\t\t\tConst DIVIDER:= 32\n\t\t\t#End\n\t\t\t\n\t\t\t' Local variable(s):\n\t\t\tLocal LastMasterPath:String\n\t\t\t\n\t\t\tLocal Cache_Context:String\n\t\t\t\n\t\t\tWhile (Not S.Eof) ' Eof()\n\t\t\t\tLocal Origin:= S.Position\n\t\t\t\tLocal IsFileDescriptor:Bool\n\t\t\t\t\n\t\t\t\t' Not the best of methods:\n\t\t\t\tLocal FirstChar:= S.ReadString(1) ' S.ReadByte() ' S.ReadChar()\n\t\t\t\t\n\t\t\t\tSelect FirstChar\n\t\t\t\t\tCase \"~n\", \"~r\", \"~t\", \" \" ' 10, 13, 9, 32\n\t\t\t\t\t\tContinue\n\t\t\t\t\tCase \"!\" ' 33\n\t\t\t\t\t\tIsFileDescriptor = True\n\t\t\t\t\tCase \"{\" ' 123\n\t\t\t\t\t\tContext.Push(LastMasterPath)\n\t\t\t\t\t\t\n\t\t\t\t\t\t' Update the current context-cache.\n\t\t\t\t\t\tCache_Context = __OS_ParseFileSystem_Update_ContextRep(Context)\n\t\t\t\t\t\t\n\t\t\t\t\t\tContinue\n\t\t\t\t\tCase \"}\" ' 125\n\t\t\t\t\t\tIf (Not Context.IsEmpty) Then\n\t\t\t\t\t\t\tContext.Pop()\n\t\t\t\t\t\tEndif\n\t\t\t\t\t\t\n\t\t\t\t\t\tCache_Context = __OS_ParseFileSystem_Update_ContextRep(Context)\n\t\t\t\t\t\t\n\t\t\t\t\t\tContinue\n\t\t\t\t\tDefault\n\t\t\t\t\t\tIsFileDescriptor = False\n\t\t\t\t\t\t\n\t\t\t\t\t\tS.Seek(Origin)\n\t\t\t\tEnd Select\n\t\t\t\t\n\t\t\t\tLocal Line:= S.ReadLine() ' Line.Replace(\"~t\", \"\")\n\t\t\t\t\n\t\t\t\tLocal Entries:String[] = Line.Split(\",\")\n\t\t\t\t\n\t\t\t\tIf (Not IsFileDescriptor) Then\n\t\t\t\t\tLastMasterPath = Entries[Entries.Length-1]\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\t' Not using 'EachIn' for performance reasons:\n\t\t\t\tFor Local I:= 0 Until Entries.Length\n\t\t\t\t\tLocal E:= Entries[I]\n\t\t\t\t\tLocal E_Length:= E.Length\n\t\t\t\t\t\n\t\t\t\t\tE = Cache_Context + SmartClip(E, DIVIDER, E_Length)\n\t\t\t\t\t\n\t\t\t\t\t' Extensions:\n\t\t\t\t\tLocal Time_First:= E.Find(\"[\")\n\t\t\t\t\t\n\t\t\t\t\tIf (Time_First <> STRING_INVALID_LOCATION) Then\n\t\t\t\t\t\tLocal Processed_E:= E[..Time_First]\n\t\t\t\t\t\t\n\t\t\t\t\t\t#If VIRTUALOS_MAP_FILETIMES\n\t\t\t\t\t\t\tLocal Time_Second:= E.Find(\"]\")\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tIf (Time_Second <> STRING_INVALID_LOCATION) Then\n\t\t\t\t\t\t\t\tLocal FTime:= Int(E[Time_First+1..Time_Second])\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tIf (FTime <> FILETIME_UNAVAILABLE) Then\n\t\t\t\t\t\t\t\t\t__OS_SetFileTime(RealPath(Processed_E), FTime)\n\t\t\t\t\t\t\t\tEndif\n\t\t\t\t\t\t\tEndif\n\t\t\t\t\t\t#End\n\t\t\t\t\t\t\n\t\t\t\t\t\tE = Processed_E\n\t\t\t\t\tEndif\n\t\t\t\t\t\n\t\t\t\t\tIf (IsFileDescriptor) Then\n\t\t\t\t\t\t__OS_CreateFileLink(RealPath(E)) ' __OS_DownloadFile(__OS_Storage, RealPath(E))\n\t\t\t\t\tElse\n\t\t\t\t\t\tCreateDir(E)\n\t\t\t\t\tEndif\n\t\t\t\tNext\n\t\t\tWend\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t#Else\n\t\tFunction __OS_StorageSupported:Bool()\n\t\t\tReturn False\n\t\tEnd\n\t#End\n\t\n\t' Functions (Monkey) (Private):\n\tPrivate\n\t\n\t#If VIRTUALOS_STANDALONE\n\t\t' Ripped from 'regal.stringutil':\n\t\tFunction SmartClip:String(Input:String, Symbol:Int)\n\t\t\tReturn SmartClip(Input, Symbol, Input.Length)\n\t\tEnd\n\t\t\n\t\tFunction SmartClip:String(Input:String, Symbol:Int, Length:Int)\n\t\t\t' Local variable(s):\n\t\t\tLocal FinalChar:= (Length - 1)\n\t\t\t\n\t\t\tLocal XClip:Int\n\t\t\tLocal YClip:Int\n\t\t\t\n\t\t\tIf (Input[0] = Symbol) Then\n\t\t\t\tXClip = 1\n\t\t\tElse\n\t\t\t\tXClip = 0\n\t\t\tEndif\n\t\t\t\n\t\t\tIf (Input[FinalChar] = Symbol) Then\n\t\t\t\tYClip = FinalChar\n\t\t\tElse\n\t\t\t\tYClip = Length\n\t\t\tEndif\n\t\t\t\n\t\t\tIf (XClip <> 0 Or YClip <> 0) Then\n\t\t\t\tReturn Input[XClip..YClip]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Input\n\t\tEnd\n\t#End\n\t\n\tPublic\n#End","old_contents":"Strict\n\nPublic\n\n' Preprocessor related:\n#VIRTUALOS_FLAG_OS = True\n\n#If TARGET = \"html5\"\n\t#VIRTUALOS_JS_TARGET = True\n#End\n\n#If VIRTUALOS_JS_TARGET\n\t#VIRTUALOS_IMPLEMENTED = True\n\t#VIRTUALOS_MAP_ENV = True\n\t#VIRTUALOS_MAP_FILETIMES = True\n\t#VIRTUALOS_EXTENSION_DL = True\n\t#VIRTUALOS_EXTENSION_VFILE = True\n\t#VIRTUALOS_EXTENSION_REMOTEPATH = True\n\t'#VIRTUALOS_REAL_FILEPATH = True\n\t\n\t#If CONFIG = \"debug\"\n\t\t'#VIRTUALOS_DEBUG = True\n\t#End\n#Elseif LANG = \"cpp\" And TARGET <> \"win8\" And TARGET <> \"ios\"\n\t#VIRTUALOS_REAL = True\n#End\n\n#If VIRTUALOS_IMPLEMENTED\n\t#If VIRTUALOS_FLAG_OS\n\t\t#BRL_OS_IMPLEMENTED = True\n\t#End\n#End\n\n' Imports (Public):\n#If Not VIRTUALOS_IMPLEMENTED\n\t#If VIRTUALOS_REAL\n\t\tImport os\n\t#End\n#Else\n\tImport \"native\/os.${LANG}\"\n#End\n\n#If VIRTUALOS_REAL_FILEPATH\n\tImport brl.filepath\n#End\n\n' Imports (Private):\nPrivate\n\n#If VIRTUALOS_IMPLEMENTED\n\tImport regal.stringutil\n\t\n\t#If VIRTUALOS_EXTENSION_DL And VIRTUALOS_EXTENSION_VFILE\n\t\tImport regal.ioutil.stringstream\n\t#End\n\t\n\tImport monkey.map\n\t\n\t#If VIRTUALOS_JS_TARGET\n\t\t'Import dom\n\t#End\n#End\n\nPublic\n\n#If VIRTUALOS_IMPLEMENTED\n\t' Constant variable(s):\n\t\n\t' File-types (Must be the same across borders):\n\tConst FILETYPE_NONE:=\t\t0\n\tConst FILETYPE_FILE:=\t\t1\n\tConst FILETYPE_DIR:=\t\t2\n\t\n\tConst FILETIME_UNAVAILABLE:= 0\n\t\n\t' External bindings:\n\tExtern\n\t\n\t' Global variable(s) (External) (Private):\n\tExtern Private\n\t\n\t' If you are supporting these extensions, please provide '__OS_Storage'.\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\t#If VIRTUALOS_JS_TARGET\n\t\t\tGlobal __OS_Storage:StorageHandle=\"__os_storage\"\n\t\t#End\n\t#End\n\t\n\tExtern\n\t\n\t' Classes (External) (Private):\n\tExtern Private\n\t\n\t' API:\n\t' Nothing so far.\n\t\n\t' Extensions:\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\t#If VIRTUALOS_JS_TARGET\n\t\t\tClass StorageHandle = \"Storage\" ' Extends DOMObject\n\t\t\t\t' Methods:\n\t\t\t\t' Nothing so far.\n\t\t\tEnd\n\t\t#Else\n\t\t\t#Error \"Unable to resolve type: 'StorageHandle'\"\n\t\t#End\n\t#End\n\t\n\tExtern\n\t\n\t' Functions (External):\n\t\n\t' API:\n\tFunction HostOS:String()\n\tFunction AppPath:String()\n\tFunction AppArgs:String[]()\n\tFunction RealPath:String(Path:String)\n\tFunction FileType:Int(Path:String)\n\tFunction FileSize:Int(Path:String)\n\t\n\t#If Not VIRTUALOS_MAP_FILETIMES\n\t\tFunction FileTime:Int(Path:String)\n\t\t\n\t\tFunction CopyFile:Bool(Src:String, Dst:String)\n\t\tFunction DeleteFile:Bool(Path:String)\n\t#Else\n\t\tFunction _CopyFile:Bool(Src:String, Dst:String)=\"CopyFile\"\n\t\tFunction _DeleteFile:Bool(Path:String)=\"DeleteFile\"\n\t#End\n\t\n\tFunction LoadString:String(Path:String)\n\tFunction SaveString:Int(Str:String, Path:String)\n\tFunction LoadDir:String[](Path:String)\n\tFunction CreateDir:Bool(Path:String)\n\tFunction DeleteDir:Bool(Path:String)\n\tFunction ChangeDir:Int(Path:String)\n\tFunction CurrentDir:String()\n\t\n\t#If Not VIRTUALOS_MAP_ENV\n\t\tFunction SetEnv:Int(Name:String, Value:String)\n\t\tFunction GetEnv:String(Name:String)\n\t#End\n\t\n\tFunction Execute:Int(CMD:String)\n\t\n\t#If Not VIRTUALOS_DEBUG\n\t\tFunction ExitApp:Int(RetCode:Int)\n\t#Else\n\t\tFunction _ExitApp:Int(RetCode:Int)=\"ExitApp\"\n\t#End\n\t\n\t' Extensions:\n\t#If VIRTUALOS_EXTENSION_REMOTEPATH\n\t\tFunction __OS_ToRemotePath:String(RealPath:String)=\"__os_toRemotePath\"\n\t#End\n\t\n\t#If VIRTUALOS_EXTENSION_DL\n\t\tFunction __OS_Download:String(URL:String)=\"__os_download\"\n\t\t\n\t\t' Virtual file-system (JavaScript) extensions:\n\t\t#If VIRTUALOS_EXTENSION_VFILE ' VIRTUALOS_JS_TARGET\n\t\t\tFunction __OS_DownloadFileUsingRep:String(Storage:StorageHandle, URL:String, Rep:String)=\"__os_downloadFileUsingRep\"\n\t\t\tFunction __OS_DownloadFile:String(Storage:StorageHandle, RealPath:String)=\"__os_downloadFile\"\n\t\t#End\n\t#End\n\t\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\tFunction __OS_StorageSupported:Bool()=\"__os_storageSupported\"\n\t\tFunction __OS_CreateFileLink:Void(Rep:String)=\"__os_createFileLink\"\n\t#End\n\t\n\tPublic\n\t\n\t' Global variable(s) (Private):\n\tPrivate\n\t\n\t#If VIRTUALOS_MAP_ENV\n\t\tGlobal __OS_Env:= New StringMap()\n\t#End\n\t\n\t#If VIRTUALOS_MAP_FILETIMES\n\t\tGlobal __OS_FileTimes:= New StringMap()\n\t#End\n\t\n\tPublic\n\t\n\t' Functions (Monkey):\n\t\n\t' API:\n\t#If VIRTUALOS_MAP_ENV\n\t\tFunction SetEnv:Void(name:String, value:String)\n\t\t\t__OS_Env.Set(name, value)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction GetEnv:String(name:String)\n\t\t\tReturn __OS_Env.Get(name)\n\t\tEnd\n\t#End\n\t\n\t#If VIRTUALOS_MAP_FILETIMES\n\t\tFunction FileTime:Int(Path:String)\n\t\t\tReturn __OS_FileTimes.Get(RealPath(Path)) ' FILETIME_UNAVAILABLE\n\t\tEnd\n\t\t\n\t\tFunction CopyFile:Bool(Src:String, Dst:String)\n\t\t\tLocal Result:= _CopyFile(Src, Dst)\n\t\t\t\n\t\t\tIf (Result) Then\n\t\t\t\t__OS_SetFileTime(RealPath(Dst), FileTime(Src)) ' ; Return True\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Result ' False\n\t\tEnd\n\t\t\n\t\tFunction DeleteFile:Bool(Path:String)\n\t\t\tLocal Result:= _DeleteFile(Path)\n\t\t\t\n\t\t\tIf (Result) Then\n\t\t\t\t__OS_RemoveFileTime(RealPath(Path))\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Result\n\t\tEnd\n\t#End\n\t\n\tFunction LoadDir:String[](Path:String, Recursive:Bool, Hidden:Bool=False)\n\t\tLocal Dirs:= New StringDeque()\n\t\tLocal Files:= New StringDeque()\n\t\t\n\t\t' Add an initial value for safety.\n\t\tDirs.PushFirst(\"\")\n\t\t\n\t\tWhile (Not Dirs.IsEmpty)\n\t\t\tLocal Dir:= Dirs.PopFirst()\n\t\t\t\n\t\t\tFor Local F:= Eachin LoadDir(Path + \"\/\" + Dir)\n\t\t\t\tIf ((Not Hidden) And F.StartsWith(\".\")) Then\n\t\t\t\t\tContinue\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tIf (Dir.Length > 0) Then\n\t\t\t\t\tF = Dir + \"\/\" + F\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tSelect (FileType(Path + \"\/\" + F))\n\t\t\t\t\tCase FILETYPE_FILE\n\t\t\t\t\t\tFiles.PushLast(F)\n\t\t\t\t\tCase FILETYPE_DIR\n\t\t\t\t\t\tIf (Recursive) Then\n\t\t\t\t\t\t\tDirs.PushLast(F)\n\t\t\t\t\t\tElse\n\t\t\t\t\t\t\tFiles.PushLast(F)\n\t\t\t\t\t\tEndif\n\t\t\t\tEnd Select\n\t\t\tNext\n\t\tWend\n\t\n\t\tReturn Files.ToArray()\n\tEnd\n\t\n\tFunction CopyDir:Bool(SourcePath:String, DestinationPath:String, Recursive:Bool=True, Hidden:Bool=False)\n\t\tIf (FileType(SourcePath) <> FILETYPE_DIR) Then\n\t\t\tReturn False\n\t\tEndif\n\t\t\n\t\tLocal Files:= LoadDir(SourcePath)\n\t\t\n\t\tSelect (FileType(DestinationPath))\n\t\t\tCase FILETYPE_NONE\n\t\t\t\tIf (Not CreateDir(DestinationPath)) Then\n\t\t\t\t\tReturn False\n\t\t\t\tEndif\n\t\t\tCase FILETYPE_FILE\n\t\t\t\tReturn False\n\t\tEnd Select\n\t\t\n\t\tFor Local F:= Eachin Files\n\t\t\tIf ((Not Hidden) And F.StartsWith(\".\")) Then\n\t\t\t\tContinue\n\t\t\tEndif\n\t\t\t\n\t\t\tLocal SrcP:= (SourcePath + \"\/\" + F)\n\t\t\tLocal DstP$= (DestinationPath + \"\/\" + F)\n\t\t\t\n\t\t\tSelect (FileType(SrcP))\n\t\t\t\tCase FILETYPE_FILE\n\t\t\t\t\tIf (Not CopyFile(SrcP, DstP)) Then\n\t\t\t\t\t\tReturn False\n\t\t\t\t\tEndif\n\t\t\t\tCase FILETYPE_DIR\n\t\t\t\t\tIf (Recursive And (Not CopyDir(SrcP, DstP, Recursive, Hidden))) Then\n\t\t\t\t\t\tReturn False\n\t\t\t\t\tEndif\n\t\t\tEnd Select\n\t\tNext\n\t\t\n\t\t' Return the default response.\n\t\tReturn True\n\tEnd\n\t\n\tFunction DeleteDir:Bool(Path$, Recursive:Bool)\n\t\tIf (Not Recursive) Then\n\t\t\tReturn DeleteDir(Path)\n\t\tEndif\n\t\t\n\t\tSelect (FileType(Path))\n\t\t\tCase FILETYPE_NONE\n\t\t\t\tReturn True\n\t\t\tCase FILETYPE_FILE\n\t\t\t\tReturn False\n\t\tEnd Select\n\t\t\n\t\tFor Local F:= Eachin LoadDir(Path)\n\t\t\tIf (F = \".\" Or F = \"..\") Then\n\t\t\t\tContinue\n\t\t\tEndif\n\t\t\t\n\t\t\tLocal FPath:= (Path + \"\/\" + F)\n\t\n\t\t\tIf (FileType(FPath) = FILETYPE_DIR) Then\n\t\t\t\tIf (Not DeleteDir(FPath, True)) Then\n\t\t\t\t\tReturn False\n\t\t\t\tEndif\n\t\t\tElse\n\t\t\t\tIf (Not DeleteFile(FPath)) Then\n\t\t\t\t\tReturn False\n\t\t\t\tEndif\n\t\t\tEndif\n\t\tNext\n\t\n\t\tReturn DeleteDir(Path)\n\tEnd\n\t\n\t#If Not VIRTUALOS_REAL_FILEPATH\n\t\tFunction StripDir:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\"\/\")\n\t\t\t\n\t\t\tIf (I = STRING_INVALID_LOCATION) Then\n\t\t\t\tI = Path.FindLast( \"\\\" )\n\t\t\tEndif\n\t\t\t\n\t\t\tIf (I <> STRING_INVALID_LOCATION) Then\n\t\t\t\tReturn Path[I+1..]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Path\n\t\tEnd\n\t\t\n\t\tFunction ExtractDir:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\"\/\")\n\t\t\t\n\t\t\tIf (I = STRING_INVALID_LOCATION) Then\n\t\t\t\tI = Path.FindLast(\"\\\")\n\t\t\tEndif\n\t\t\t\n\t\t\tIf (I <> STRING_INVALID_LOCATION) Then\n\t\t\t\tReturn Path[..I]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn \"\"\n\t\tEnd\n\t\t\n\t\tFunction StripExt:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\".\")\n\t\t\tLocal SecondarySearchPos:= (I+1)\n\t\t\t\n\t\t\tIf ((I <> STRING_INVALID_LOCATION) And (Path.Find(\"\/\", SecondarySearchPos) = STRING_INVALID_LOCATION) And (Path.Find(\"\\\", SecondarySearchPos)= STRING_INVALID_LOCATION)) Then\n\t\t\t\tReturn Path[..I]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn Path\n\t\tEnd\n\t\t\n\t\tFunction ExtractExt:String(Path:String)\n\t\t\tLocal I:= Path.FindLast(\".\")\n\t\t\tLocal SecondarySearchPos:= (I+1)\n\t\t\t\n\t\t\tIf ((I <> STRING_INVALID_LOCATION) And (Path.Find(\"\/\", SecondarySearchPos) = STRING_INVALID_LOCATION) And (Path.Find(\"\\\", SecondarySearchPos)= STRING_INVALID_LOCATION)) Then\n\t\t\t\tReturn Path[SecondarySearchPos..]\n\t\t\tEndif\n\t\t\t\n\t\t\tReturn \"\"\n\t\tEnd\n\t\t\n\t\tFunction StripAll:String(Path:String)\n\t\t\tReturn StripDir(StripExt(Path))\n\t\tEnd\n\t#End\n\t\n\t' Debugging related:\n\t#If VIRTUALOS_DEBUG\n\t\tFunction ExitApp:Int(RetCode:Int)\n\t\t\tDebugStop()\n\t\t\t\n\t\t\t_ExitApp(RetCode)\n\t\t\t\n\t\t\tReturn 0\n\t\tEnd\n\t#End\n\t\n\t' Extensions:\n\t#If VIRTUALOS_MAP_FILETIMES\n\t\tFunction __OS_SetFileTime:Void(RealPath:String, Time:Int)\n\t\t\t__OS_FileTimes.Set(RealPath, Time)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction __OS_RemoveFileTime:Void(RealPath:String)\n\t\t\t__OS_FileTimes.Remove(RealPath)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t#End\n\t\n\t#If VIRTUALOS_EXTENSION_VFILE\n\t\t#If VIRTUALOS_EXTENSION_DL\n\t\t\tFunction __OS_AddFileSystem:Void(URL:String)\n\t\t\t\tLocal FileData:= __OS_Download(URL)\n\t\t\t\t\n\t\t\t\tLocal SS:= New StringStream(FileData, ,,,, True)\n\t\t\t\t\n\t\t\t\t__OS_ParseFileSystem(SS)\n\t\t\t\t\n\t\t\t\tReturn\n\t\t\tEnd\n\t\t#End\n\t\t\n\t\tFunction __OS_ParseFileSystem:Void(S:Stream) ' StringStream\n\t\t\t__OS_ParseFileSystem(S, New StringStack())\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction __OS_ParseFileSystem_Update_ContextRep:String(Context:Stack)\n\t\t\tLocal Rep:String\n\t\t\t\n\t\t\tFor Local Folder:= Eachin Context\n\t\t\t\tRep += (Folder + \"\/\")\n\t\t\tNext\n\t\t\t\n\t\t\tReturn Rep\n\t\tEnd\n\t\t\n\t\t' A simple parser that takes each line of a 'Stream', and decodes a folder structure from the input.\n\t\t' The 'OpenPrefix' argument is used to toggle adding an extra slash before generated paths.\n\t\tFunction __OS_ParseFileSystem:Void(S:Stream, Context:Stack, OpenPrefix:Bool=True) ' StringStream\n\t\t\t' Constant variable(s):\n\t\t\tConst DIVIDER:= ASCII_CHARACTER_SPACE\n\t\t\t\n\t\t\t' Local variable(s):\n\t\t\tLocal LastMasterPath:String\n\t\t\t\n\t\t\tLocal Cache_Context:String\n\t\t\t\n\t\t\tWhile (Not S.Eof) ' Eof()\n\t\t\t\tLocal Origin:= S.Position\n\t\t\t\tLocal IsFileDescriptor:Bool\n\t\t\t\t\n\t\t\t\t' Not the best of methods:\n\t\t\t\tLocal FirstChar:= S.ReadString(1) ' S.ReadByte() ' S.ReadChar()\n\t\t\t\t\n\t\t\t\tSelect FirstChar\n\t\t\t\t\tCase \"~n\", \"~r\", \"~t\", \" \" ' 10, 13, 9, 32\n\t\t\t\t\t\tContinue\n\t\t\t\t\tCase \"!\" ' 33\n\t\t\t\t\t\tIsFileDescriptor = True\n\t\t\t\t\tCase \"{\" ' 123\n\t\t\t\t\t\tContext.Push(LastMasterPath)\n\t\t\t\t\t\t\n\t\t\t\t\t\t' Update the current context-cache.\n\t\t\t\t\t\tCache_Context = __OS_ParseFileSystem_Update_ContextRep(Context)\n\t\t\t\t\t\t\n\t\t\t\t\t\tContinue\n\t\t\t\t\tCase \"}\" ' 125\n\t\t\t\t\t\tIf (Not Context.IsEmpty) Then\n\t\t\t\t\t\t\tContext.Pop()\n\t\t\t\t\t\tEndif\n\t\t\t\t\t\t\n\t\t\t\t\t\tCache_Context = __OS_ParseFileSystem_Update_ContextRep(Context)\n\t\t\t\t\t\t\n\t\t\t\t\t\tContinue\n\t\t\t\t\tDefault\n\t\t\t\t\t\tIsFileDescriptor = False\n\t\t\t\t\t\t\n\t\t\t\t\t\tS.Seek(Origin)\n\t\t\t\tEnd Select\n\t\t\t\t\n\t\t\t\tLocal Line:= S.ReadLine() ' Line.Replace(\"~t\", \"\")\n\t\t\t\t\n\t\t\t\tLocal Entries:String[] = Line.Split(\",\")\n\t\t\t\t\n\t\t\t\tIf (Not IsFileDescriptor) Then\n\t\t\t\t\tLastMasterPath = Entries[Entries.Length-1]\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\t' Not using 'EachIn' for performance reasons:\n\t\t\t\tFor Local I:= 0 Until Entries.Length\n\t\t\t\t\tLocal E:= Entries[I]\n\t\t\t\t\tLocal E_Length:= E.Length\n\t\t\t\t\t\n\t\t\t\t\tE = Cache_Context + SmartClip(E, DIVIDER, E_Length)\n\t\t\t\t\t\n\t\t\t\t\t' Extensions:\n\t\t\t\t\tLocal Time_First:= E.Find(\"[\")\n\t\t\t\t\t\n\t\t\t\t\tIf (Time_First <> STRING_INVALID_LOCATION) Then\n\t\t\t\t\t\tLocal Processed_E:= E[..Time_First]\n\t\t\t\t\t\t\n\t\t\t\t\t\t#If VIRTUALOS_MAP_FILETIMES\n\t\t\t\t\t\t\tLocal Time_Second:= E.Find(\"]\")\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tIf (Time_Second <> STRING_INVALID_LOCATION) Then\n\t\t\t\t\t\t\t\tLocal FTime:= Int(E[Time_First+1..Time_Second])\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tIf (FTime <> FILETIME_UNAVAILABLE) Then\n\t\t\t\t\t\t\t\t\t__OS_SetFileTime(RealPath(Processed_E), FTime)\n\t\t\t\t\t\t\t\tEndif\n\t\t\t\t\t\t\tEndif\n\t\t\t\t\t\t#End\n\t\t\t\t\t\t\n\t\t\t\t\t\tE = Processed_E\n\t\t\t\t\tEndif\n\t\t\t\t\t\n\t\t\t\t\tIf (IsFileDescriptor) Then\n\t\t\t\t\t\t__OS_CreateFileLink(RealPath(E)) ' __OS_DownloadFile(__OS_Storage, RealPath(E))\n\t\t\t\t\tElse\n\t\t\t\t\t\tCreateDir(E)\n\t\t\t\t\tEndif\n\t\t\t\tNext\n\t\t\tWend\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t#Else\n\t\tFunction __OS_StorageSupported:Bool()\n\t\t\tReturn False\n\t\tEnd\n\t#End\n#End","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"8d3be8293fec6e90dd5583b7ffbf3dcda04f30ee","subject":"Added FlxG.SwitchState function","message":"Added FlxG.SwitchState function\n","repos":"devolonter\/flixel-monkey,devolonter\/flixel-monkey,devolonter\/flixel-monkey,devolonter\/flixel-monkey","old_file":"flxg.monkey","new_file":"flxg.monkey","new_contents":"Strict\n\nImport flxgame\nImport flxcamera\nImport flxu\n\nImport plugin.timermanager\n\nClass FlxG\t\n\n\tConst LIBRARY_NAME:String = \"Monkey flixel\"\n\t\n\tConst LIBRARY_MAJOR_VERSION:Int = 1\n\t\n\tConst LIBRARY_MINOR_VERSION:Int = 0\n\t\n\tConst DATA_PREFIX:String = \"flx_\"\n\t\n\tConst RED:Int = $FFFF0012\n\t\n\tConst GREEN:Int = $FF00F225\n\t\n\tConst BLUE:Int = $FF0090E9\n\t\n\tConst PINK:Int = $FFF01EFF\n\t\n\tConst WHITE:Int = $FFFFFFFF\n\t\n\tConst BLACK:Int = $FF000000\n\t\n\tGlobal deviceWidth:Int\n\t\n\tGlobal deviceHeight:Int\n\t\n\tGlobal width:Int\n\t\n\tGlobal height:Int\n\t\t\t\n\tGlobal cameras:Stack\n\t\n\tGlobal camera:FlxCamera\n\t\n\tGlobal plugins:Stack\n\t\n\tGlobal elapsed:Float\n\t\n\tGlobal timeScale:Float\n\t\n\tGlobal visualDebug:Bool\n\t\n\tGlobal globalSeed:Int\n\t\n\tGlobal framerate:Int\n\t\n\tGlobal _deviceScaleFactorX:Float = 1\t\n\t\n\tGlobal _deviceScaleFactorY:Float = 1\n\t\n\tGlobal _bgColor:FlxColor = FlxColor.ARGB(FlxG.BLACK)\t\t\n\t\n\tGlobal _game:FlxGame\n\t\n\tGlobal _lastDrawingColor:Int\n\t\n\tGlobal _lastDrawingBlend:Int\t\n\nPublic\t\n\tFunction Random:Float()\n\t\tFlxG.globalSeed = (FlxG.globalSeed * 1664525 + 1013904223)|0\n\t\tReturn FlxU.Srand(FlxG.globalSeed)\n\tEnd Function\n\t\n\tFunction GetRandom:FlxBasic(objects:FlxBasic[], startIndex:Int = 0, length:Int = 0)\n\t\tIf (objects <> Null) Then\n\t\t\tLocal l:Int = length\n\t\t\t\n\t\t\tIf (l = 0 Or l > objects.Length() - startIndex) Then\n\t\t\t\tl = objects.Length() - startIndex\n\t\t\tEnd if\n\t\t\t\n\t\t\tIf (l > 0) Return objects[startIndex + int(FlxG.Random()*l)]\t\n\t\tEnd If\n\t\t\n\t\tReturn Null\n\tEnd Function\n\t\n\t#Rem\n\tFunction GetRandom:Object(objects:Object[], startIndex:Int = 0, length:Int = 0)\n\t\tGetRandom is not currently supported in Monkey. Use FlxArray.GetSafeRandom method\n\tEnd Function\n\t#End\n\t\n\tFunction SwitchState:Void(state:FlxState)\n\t\tFlxG._game._requestedState = state\n\tEnd Function\n\t\n\tFunction AddCamera:FlxCamera(newCamera:FlxCamera)\n\t\tFlxG.cameras.Push(newCamera)\n\t\tReturn newCamera\n\tEnd Function\n\t\n\tFunction RemoveCamera:Void(camera:FlxCamera, destroy:Bool = True)\n\t\tFlxG.cameras.RemoveEach(camera)\n\t\tIf (destroy) camera.Destroy()\n\tEnd Function\n\t\n\tFunction ResetCameras:Void(newCamera:FlxCamera = Null)\n\t\tLocal cam:FlxCamera\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = FlxG.cameras.Get(i)\n\t\t\tcam.Destroy()\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG.cameras.Clear()\n\t\tIf (newCamera = Null) newCamera = New FlxCamera(0, 0, FlxG.width, FlxG.height)\n\t\t\n\t\tFlxG.camera = FlxG.AddCamera(newCamera)\t\n\tEnd Function\n\t\n\tFunction Flash:Void(color:Int = FlxG.WHITE, duration:Float = 1, onComplete:FlxFunction = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).Flash(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Fade:Void(color:Int = FlxG.BLACK, duration:Float = 1, onComplete:FlxFunction = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).Fade(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Shake:Void(intensity:Float = 0.05, duration:Float = 0.5, onComplete:FlxFunction = Null, force:Bool = True, direction:Int = FlxCamera.SHAKE_BOTH_AXES)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).Shake(intensity, duration, onComplete, force, direction)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\t\t\n\t\n\tFunction BgColor:Int()\n\t\tIf (FlxG.camera = Null Or Not FlxG.camera.alive) Return FlxG._bgColor.argb\t\n\t\tReturn FlxG.camera.BgColor\n\tEnd Function\n\t\n\tFunction BgColor:Void(color:Int)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).BgColor = color\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG._bgColor.SetARGB(color)\n\tEnd Function\n\t\n\tFunction AddPlugin:FlxBasic(plugin:FlxBasic)\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tIf (pluginList.Get(i).ToString() = plugin.ToString()) Then\n\t\t\t\tReturn plugin\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tpluginList.Push(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction GetPlugin:FlxBasic(creator:FlxClass)\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal plugin:FlxBasic\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (creator.InstanceOf(plugin)) Return plugin\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tReturn Null\t\n\tEnd Function\n\t\n\tFunction RemovePlugin:FlxBasic(plugin:FlxBasic)\n\t\tplugins.RemoveEach(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction RemovePluginType:Bool(creator:FlxClass)\n\t\tLocal results:Bool = False\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = pluginList.Length() - 1\t\n\t\t\n\t\tWhile(i >= 0)\n\t\t\tIf (creator.InstanceOf(pluginList.Get(i))) Then\n\t\t\t\tpluginList.Remove(i)\n\t\t\t\tresults = True\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti-=1\n\t\tWend\n\t\n\t\tReturn results\n\tEnd Function\n\t\n\tFunction Init:Void(game:FlxGame, width:Int, height:Int, zoom:Float)\n\t\tFlxG._game = game\n\t\tFlxG.width = width\n\t\tFlxG.height = height\n\t\t\n\t\tFlxCamera.defaultZoom = zoom\n\t\tFlxG.cameras = New Stack()\t\t\n\t\t\n\t\tplugins = New Stack\n\t\tAddPlugin(New TimerManager())\t\n\tEnd Function\n\t\n\tFunction Reset:Void()\t\t\n\t\tFlxG.timeScale = 1\n\t\tFlxG.elapsed = 0 \n\t\tFlxG.globalSeed = Rnd(1, 10000000)\n\tEnd Function\n\t\n\tFunction UpdateCameras:Void()\n\t\tLocal cam:FlxCamera\n\t\tLocal cams:Stack = FlxG.cameras\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = cams.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = cams.Get(i)\n\t\t\tIf (cam <> Null And cam.exists And cam.active) cam.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction UpdatePlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.active) plugin.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction DrawPlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.visible) plugin.Draw()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\nEnd Class\n","old_contents":"Strict\n\nImport flxgame\nImport flxcamera\nImport flxu\n\nImport plugin.timermanager\n\nClass FlxG\t\n\n\tConst LIBRARY_NAME:String = \"Monkey flixel\"\n\t\n\tConst LIBRARY_MAJOR_VERSION:Int = 1\n\t\n\tConst LIBRARY_MINOR_VERSION:Int = 0\n\t\n\tConst DATA_PREFIX:String = \"flx_\"\n\t\n\tConst RED:Int = $FFFF0012\n\t\n\tConst GREEN:Int = $FF00F225\n\t\n\tConst BLUE:Int = $FF0090E9\n\t\n\tConst PINK:Int = $FFF01EFF\n\t\n\tConst WHITE:Int = $FFFFFFFF\n\t\n\tConst BLACK:Int = $FF000000\n\t\n\tGlobal deviceWidth:Int\n\t\n\tGlobal deviceHeight:Int\n\t\n\tGlobal width:Int\n\t\n\tGlobal height:Int\n\t\t\t\n\tGlobal cameras:Stack\n\t\n\tGlobal camera:FlxCamera\n\t\n\tGlobal plugins:Stack\n\t\n\tGlobal elapsed:Float\n\t\n\tGlobal timeScale:Float\n\t\n\tGlobal visualDebug:Bool\n\t\n\tGlobal globalSeed:Int\n\t\n\tGlobal framerate:Int\n\t\n\tGlobal _deviceScaleFactorX:Float = 1\t\n\t\n\tGlobal _deviceScaleFactorY:Float = 1\n\t\n\tGlobal _bgColor:FlxColor = FlxColor.ARGB(FlxG.BLACK)\t\t\n\t\n\tGlobal _game:FlxGame\n\t\n\tGlobal _lastDrawingColor:Int\n\t\n\tGlobal _lastDrawingBlend:Int\t\n\nPublic\t\n\tFunction Random:Float()\n\t\tFlxG.globalSeed = (FlxG.globalSeed * 1664525 + 1013904223)|0\n\t\tReturn FlxU.Srand(FlxG.globalSeed)\n\tEnd Function\n\t\n\tFunction GetRandom:FlxBasic(objects:FlxBasic[], startIndex:Int = 0, length:Int = 0)\n\t\tIf (objects <> Null) Then\n\t\t\tLocal l:Int = length\n\t\t\t\n\t\t\tIf (l = 0 Or l > objects.Length() - startIndex) Then\n\t\t\t\tl = objects.Length() - startIndex\n\t\t\tEnd if\n\t\t\t\n\t\t\tIf (l > 0) Return objects[startIndex + int(FlxG.Random()*l)]\t\n\t\tEnd If\n\t\t\n\t\tReturn Null\n\tEnd Function\n\t\n\t#Rem\n\tFunction GetRandom:Object(objects:Object[], startIndex:Int = 0, length:Int = 0)\n\t\tGetRandom is not currently supported in Monkey. Use FlxArray.GetSafeRandom method\n\tEnd Function\n\t#End\n\t\n\tFunction AddCamera:FlxCamera(newCamera:FlxCamera)\n\t\tFlxG.cameras.Push(newCamera)\n\t\tReturn newCamera\n\tEnd Function\n\t\n\tFunction RemoveCamera:Void(camera:FlxCamera, destroy:Bool = True)\n\t\tFlxG.cameras.RemoveEach(camera)\n\t\tIf (destroy) camera.Destroy()\n\tEnd Function\n\t\n\tFunction ResetCameras:Void(newCamera:FlxCamera = Null)\n\t\tLocal cam:FlxCamera\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = FlxG.cameras.Get(i)\n\t\t\tcam.Destroy()\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG.cameras.Clear()\n\t\tIf (newCamera = Null) newCamera = New FlxCamera(0, 0, FlxG.width, FlxG.height)\n\t\t\n\t\tFlxG.camera = FlxG.AddCamera(newCamera)\t\n\tEnd Function\n\t\n\tFunction Flash:Void(color:Int = FlxG.WHITE, duration:Float = 1, onComplete:FlxFunction = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).Flash(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Fade:Void(color:Int = FlxG.BLACK, duration:Float = 1, onComplete:FlxFunction = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).Fade(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Shake:Void(intensity:Float = 0.05, duration:Float = 0.5, onComplete:FlxFunction = Null, force:Bool = True, direction:Int = FlxCamera.SHAKE_BOTH_AXES)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).Shake(intensity, duration, onComplete, force, direction)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\t\t\n\t\n\tFunction BgColor:Int()\n\t\tIf (FlxG.camera = Null Or Not FlxG.camera.alive) Return FlxG._bgColor.argb\t\n\t\tReturn FlxG.camera.BgColor\n\tEnd Function\n\t\n\tFunction BgColor:Void(color:Int)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.cameras.Get(i).BgColor = color\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG._bgColor.SetARGB(color)\n\tEnd Function\n\t\n\tFunction AddPlugin:FlxBasic(plugin:FlxBasic)\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tIf (pluginList.Get(i).ToString() = plugin.ToString()) Then\n\t\t\t\tReturn plugin\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tpluginList.Push(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction GetPlugin:FlxBasic(creator:FlxClass)\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal plugin:FlxBasic\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (creator.InstanceOf(plugin)) Return plugin\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tReturn Null\t\n\tEnd Function\n\t\n\tFunction RemovePlugin:FlxBasic(plugin:FlxBasic)\n\t\tplugins.RemoveEach(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction RemovePluginType:Bool(creator:FlxClass)\n\t\tLocal results:Bool = False\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = pluginList.Length() - 1\t\n\t\t\n\t\tWhile(i >= 0)\n\t\t\tIf (creator.InstanceOf(pluginList.Get(i))) Then\n\t\t\t\tpluginList.Remove(i)\n\t\t\t\tresults = True\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti-=1\n\t\tWend\n\t\n\t\tReturn results\n\tEnd Function\n\t\n\tFunction Init:Void(game:FlxGame, width:Int, height:Int, zoom:Float)\n\t\tFlxG._game = game\n\t\tFlxG.width = width\n\t\tFlxG.height = height\n\t\t\n\t\tFlxCamera.defaultZoom = zoom\n\t\tFlxG.cameras = New Stack()\t\t\n\t\t\n\t\tplugins = New Stack\n\t\tAddPlugin(New TimerManager())\t\n\tEnd Function\n\t\n\tFunction Reset:Void()\t\t\n\t\tFlxG.timeScale = 1\n\t\tFlxG.elapsed = 0 \n\t\tFlxG.globalSeed = Rnd(1, 10000000)\n\tEnd Function\n\t\n\tFunction UpdateCameras:Void()\n\t\tLocal cam:FlxCamera\n\t\tLocal cams:Stack = FlxG.cameras\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = cams.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = cams.Get(i)\n\t\t\tIf (cam <> Null And cam.exists And cam.active) cam.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction UpdatePlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.active) plugin.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction DrawPlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.visible) plugin.Draw()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\nEnd Class\n","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"28be5beee2642007b25f41f4ea1009babcf33b83","subject":"Broken transitions fixed","message":"Broken transitions fixed\n","repos":"michaelcontento\/bono,michaelcontento\/bono,michaelcontento\/bono","old_file":"bono\/transition.monkey","new_file":"bono\/transition.monkey","new_contents":"Strict\n\n' All transitions where ported from the Kivy project\n' See: https:\/\/github.com\/kivy\/kivy\/blob\/master\/kivy\/animation.py#L366\n\nInterface Transition\n Method Calculate:Float(progress:Float)\nEnd\n\nClass TransitionLinear Implements Transition\n Method Calculate:Float(progress:Float)\n Return progress\n End\nEnd\n\nClass TransitionInQuad Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 2)\n End\nEnd\n\nClass TransitionOutQuad Implements Transition\n Method Calculate:Float(progress:Float)\n Return -1 * progress * (progress - 2)\n End\nEnd\n\nClass TransitionInOutQuad Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(progress, 2)\n\n progress -= 1\n Return -0.5 * (progress * (progress - 2) - 1)\n End\nEnd\n\nClass TransitionInCubic Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 3)\n End\nEnd\n\nClass TransitionOutCubic Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return Pow(progress, 3) + 1\n End\nEnd\n\nClass TransitionInOutCubic Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(progress, 3)\n\n progress -= 2\n Return 0.5 * (Pow(progress, 3) + 2)\n End\nEnd\n\nClass TransitionInQuart Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 4)\n End\nEnd\n\nClass TransitionOutQuart Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return -1 * (Pow(progress, 4) - 1)\n End\nEnd\n\nClass TransitionInOutQuart Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(progress, 4)\n\n progress -= 2\n Return -0.5 * (Pow(progress, 4) - 2)\n End\nEnd\n\nClass TransitionInSine Implements Transition\n Method Calculate:Float(progress:Float)\n Return -1 * Cosr(progress * HALFPI) + 1\n End\nEnd\n\nClass TransitionOutSine Implements Transition\n Method Calculate:Float(progress:Float)\n Return Sinr(progress * HALFPI)\n End\nEnd\n\nClass TransitionInOutSine Implements Transition\n Method Calculate:Float(progress:Float)\n Return -0.5 * (Cosr(progress * PI) - 1.0)\n End\nEnd\n\nClass TransitionInExpo Implements Transition\n Method Calculate:Float(progress:Float)\n If progress = 0 Then Return 0\n Return Pow(2, 10 * (progress - 1.0))\n End\nEnd\n\nClass TransitionOutExpo Implements Transition\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n Return -Pow(2, -10 * progress) + 1\n End\nEnd\n\nClass TransitionInOutExpo Implements Transition\n Method Calculate:Float(progress:Float)\n If progress = 0 Then Return 0\n If progress = 1 Then Return 1\n\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(2, 10 * (progress - 1.0))\n\n progress -= 1\n Return 0.5 * (-Pow(2, -10 * progress) + 2)\n End\nEnd\n\nClass TransitionInCirc Implements Transition\n Method Calculate:Float(progress:Float)\n Return -1 * (Sqrt(1 - Pow(progress, 2)) - 1)\n End\nEnd\n\nClass TransitionOutCirc Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return Sqrt(1 - Pow(progress, 2))\n End\nEnd\n\nClass TransitionInOutCirc Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return -0.5 * (Sqrt(1 - Pow(progress, 2)) - 1)\n\n progress -= 2\n Return 0.5 * (Sqrt(1 - Pow(progress, 2)) + 1)\n End\nEnd\n\nClass TransitionInElastic Implements Transition\n Private\n\n Const P:Float = 0.3\n Const S:Float = P \/ 4\n\n Public\n\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n progress -= 1\n\n Return -(Pow(2, 10 * progress) * Sinr((progress - S) * TWOPI \/ P))\n End\nEnd\n\nClass TransitionOutElastic Implements Transition\n Private\n\n Const P:Float = 0.3\n Const S:Float = P \/ 4\n\n Public\n\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n Return Pow(2, -10 * progress) * Sinr((progress - S) * TWOPI \/ P) + 1\n End\nEnd\n\nClass TransitionInOutElastic Implements Transition\n Private\n\n Const P:Float = 0.45\n Const S:Float = P \/ 4\n\n Public\n\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress = 2 Then Return 1\n\n If progress < 1 Then\n progress -= 1\n Return -0.5 * (Pow(2, 10 * progress) * Sinr((progress - S) * TWOPI \/ P))\n Else\n progress -= 1\n Return Pow(2, -10 * progress) * Sinr((progress - S) * TWOPI \/ P) * 0.5 + 1\n End\n End\nEnd\n\nClass TransitionInBack Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 2) * (2.70158 * progress - 1.70158)\n End\nEnd\n\nClass TransitionOutBack Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return Pow(progress, 2) * (2.70158 * progress + 1.70158) + 1\n End\nEnd\n\nClass TransitionInOutBack Implements Transition\n Private\n\n Const S:Float = 1.70158 * 1.525\n\n Public\n\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress - S))\n\n progress -= 2\n Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress + S) + 2)\n End\nEnd\n\nFunction OutBounce:Float(progress:Float)\n If progress < (1 \/ 2.75) Return 7.5625 * Pow(progress, 2)\n\n If progress < (2 \/ 2.75)\n progress -= 1.5 \/ 2.75\n Return 7.5625 * Pow(progress, 2) + 0.75\n End\n\n If progress < (2.5 \/ 2.75)\n progress -= 2.25 \/ 2.75\n Return 7.5625 * Pow(progress, 2) + 0.9375\n End\n\n progress -= 2.625 \/ 2.75\n Return 7.5625 * Pow(progress, 2) + 0.984375\nEnd\n\nFunction InBounce:Float(progress:Float)\n Return 1 - OutBounce(1 - progress)\nEnd\n\nClass TransitionInBounce Implements Transition\n Method Calculate:Float(progress:Float)\n Return InBounce(progress)\n End\nEnd\n\nClass TransitionOutBounce Implements Transition\n Method Calculate:Float(progress:Float)\n Return OutBounce(progress)\n End\nEnd\n\nClass TransitionInOutBounce Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return InBounce(progress) * 0.5\n\n Return OutBounce(progress - 1) * 0.5 + 0.5\n End\nEnd\n","old_contents":"Strict\n\n' All transitions where ported from the Kivy project\n' See: https:\/\/github.com\/kivy\/kivy\/blob\/master\/kivy\/animation.py#L366\n\nInterface Transition\n Method Calculate:Float(progress:Float)\nEnd\n\nClass TransitionLinear Implements Transition\n Method Calculate:Float(progress:Float)\n Return progress\n End\nEnd\n\nClass TransitionInQuad Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 2)\n End\nEnd\n\nClass TransitionOutQuad Implements Transition\n Method Calculate:Float(progress:Float)\n Return -1 * progress * (progress - 2)\n End\nEnd\n\nClass TransitionInOutQuad Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(progress, 2)\n\n progress -= 1\n Return -0.5 * (progress * (progress - 2) - 1)\n End\nEnd\n\nClass TransitionInCubic Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 3)\n End\nEnd\n\nClass TransitionOutCubic Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return Pow(progress, 3) + 1\n End\nEnd\n\nClass TransitionInOutCubic Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(progress, 3)\n\n progress -= 2\n Return 0.5 * (Pow(progress, 3) + 2)\n End\nEnd\n\nClass TransitionInQuart Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 4)\n End\nEnd\n\nClass TransitionOutQuart Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return -1 * (Pow(progress, 4) - 1)\n End\nEnd\n\nClass TransitionInOutQuart Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(progress, 4)\n\n progress -= 2\n Return -0.5 * (Pow(progress, 4) - 2)\n End\nEnd\n\nClass TransitionInSine Implements Transition\n Method Calculate:Float(progress:Float)\n Return -1 * Cos(progress * HALFPI) + 1.0\n End\nEnd\n\nClass TransitionOutSine Implements Transition\n Method Calculate:Float(progress:Float)\n Return Sin(progress * HALFPI)\n End\nEnd\n\nClass TransitionInOutSine Implements Transition\n Method Calculate:Float(progress:Float)\n Return -0.5 * (Cos(progress * PI) - 1.0)\n End\nEnd\n\nClass TransitionInExpo Implements Transition\n Method Calculate:Float(progress:Float)\n If progress = 0 Then Return 0\n Return Pow(2, 10 * (progress - 1.0))\n End\nEnd\n\nClass TransitionOutExpo Implements Transition\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n Return -Pow(2, -10 * progress) + 1\n End\nEnd\n\nClass TransitionInOutExpo Implements Transition\n Method Calculate:Float(progress:Float)\n If progress = 0 Then Return 0\n If progress = 1 Then Return 1\n\n progress *= 2\n If progress < 1 Then Return 0.5 * Pow(2, 10 * (progress - 1.0))\n\n progress -= 1\n Return 0.5 * (-Pow(2, -10 * progress) + 2)\n End\nEnd\n\nClass TransitionInCirc Implements Transition\n Method Calculate:Float(progress:Float)\n Return -1 * (Sqrt(1 - Pow(progress, 2)) - 1)\n End\nEnd\n\nClass TransitionOutCirc Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return Sqrt(1 - Pow(progress, 2))\n End\nEnd\n\nClass TransitionInOutCirc Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return -0.5 * (Sqrt(1 - Pow(progress, 2)) - 1)\n\n progress -= 2\n Return 0.5 * (Sqrt(1 - Pow(progress, 2)) + 1)\n End\nEnd\n\nClass TransitionInElastic Implements Transition\n Private\n\n Const P:Float = 0.3\n Const S:Float = P \/ 4\n\n Public\n\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n progress -= 1\n\n Return -(Pow(2, 10 * progress) * Sin((progress - S) * TWOPI \/ P))\n End\nEnd\n\nClass TransitionOutElastic Implements Transition\n Private\n\n Const P:Float = 0.3\n Const S:Float = P \/ 4\n\n Public\n\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n progress -= 1\n\n Return Pow(2, -10 * progress) * Sin((progress - S) * TWOPI \/ P) + 1\n End\nEnd\n\nClass TransitionInOutElastic Implements Transition\n Private\n\n Const P:Float = 0.45\n Const S:Float = P \/ 4\n\n Public\n\n Method Calculate:Float(progress:Float)\n If progress = 1 Then Return 1\n\n progress = progress * 2 - 1\n If progress < 1 Then\n Return -0.5 * (Pow(2, 10 * progress) * Sin((progress - S) * TWOPI \/ P))\n End\n\n Return Pow(2, -10 * progress) * Sin((progress - S) * TWOPI \/ P) * 0.5 + 1\n End\nEnd\n\nClass TransitionInBack Implements Transition\n Method Calculate:Float(progress:Float)\n Return Pow(progress, 2) * (2.70158 * progress - 1.70158)\n End\nEnd\n\nClass TransitionOutBack Implements Transition\n Method Calculate:Float(progress:Float)\n progress -= 1\n Return Pow(progress, 2) * (2.70158 * progress + 1.70158) + 1\n End\nEnd\n\nClass TransitionInOutBack Implements Transition\n Private\n\n Const S:Float = 1.70158 * 1.525\n\n Public\n\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress - S))\n\n progress -= 2\n Return 0.5 * (Pow(progress, 2) * ((S + 1) * progress + S) + 2)\n End\nEnd\n\nFunction OutBounce:Float(progress:Float)\n If progress < (1 \/ 2.75) Return 7.5625 * Pow(progress, 2)\n\n If progress < (2 \/ 2.75)\n progress -= 1.5 \/ 2.75\n Return 7.5625 * Pow(progress, 2) + 0.75\n End\n\n If progress < (2.5 \/ 2.75)\n progress -= 2.25 \/ 2.75\n Return 7.5625 * Pow(progress, 2) + 0.9375\n End\n\n progress -= 2.625 \/ 2.75\n Return 7.5625 * Pow(progress, 2) + 0.984375\nEnd\n\nFunction InBounce:Float(progress:Float)\n Return 1 - OutBounce(1 - progress)\nEnd\n\nClass TransitionInBounce Implements Transition\n Method Calculate:Float(progress:Float)\n Return InBounce(progress)\n End\nEnd\n\nClass TransitionOutBounce Implements Transition\n Method Calculate:Float(progress:Float)\n Return OutBounce(progress)\n End\nEnd\n\nClass TransitionInOutBounce Implements Transition\n Method Calculate:Float(progress:Float)\n progress *= 2\n If progress < 1 Then Return InBounce(progress) * 0.5\n\n Return OutBounce(progress - 1) * 0.5 + 0.5\n End\nEnd\n","returncode":0,"stderr":"","license":"apache-2.0","lang":"Monkey"} {"commit":"52196bee86e4d9621ed6de6ac0ae41cb3e5bde1d","subject":"Added comparison-codes.","message":"Added comparison-codes.\n","repos":"Regal-Internet-Brothers\/util,Regal-Internet-Brothers\/util","old_file":"util.monkey","new_file":"util.monkey","new_contents":"Strict\n\nPublic\n\n' Preprocessor related:\n#Rem\n#If TARGET = \"glfw\" Or TARGET = \"sexy\"\n\t#GLFW_TARGET = True\n#End\n#End\n\n#UTIL_IMPLEMENTED = True\n#UTIL_WRAP_BOTH_WAYS = True\n#UTIL_PREPROCESSOR_FIXES = False ' True\n#UTIL_DELEGATE_TYPETOOL = False\n#UTIL_TYPECODE_STRINGS_USE_SHORTHAND = False\n\n#If IOELEMENT_IMPLEMENTED\n\t#UTIL_SUPPORT_IOELEMENTS = True\n#Else\n\t#UTIL_SUPPORT_IOELEMENTS = False\n#End\n\n#If CONFIG = \"debug\"\n\t#DEBUG_PRINT = True\n#Else\n\t#DEBUG_PRINT = False\n#End\n\n#If CONFIG = \"release\"\n\t#DEBUG_PRINT_ON_ERROR = True\n#Else\n\t#DEBUG_PRINT_ON_ERROR = False\n#End\n\n#DEBUG_PRINT_QUOTES = False\n\n#If Not UTIL_PREPROCESSOR_FIXES\n\t' These are the actual default settings for these variables:\n\t#UTIL_READ_LINES_QUICKLY = True\n\t\n\t#If HOST = \"winnt\"\n\t\t#UTIL_WRITELINE_ENDTYPE = \"CRLF\" ' \"LF\"\n\t#Else\n\t\t#UTIL_WRITELINE_ENDTYPE = \"LF\"\n\t#End\n#Else\n\t' The default values of these are purposely separate from the main settings:\n\t#If READ_LINE_QUICKLY\n\t\t#UTIL_READ_LINES_QUICKLY = READ_LINE_QUICKLY\n\t#Else\n\t\t#UTIL_READ_LINES_QUICKLY = True\n\t#End\n\t\n\t#If WRITE_LINE_ENDTYPE\n\t\t#UTIL_WRITELINE_ENDTYPE = WRITE_LINE_ENDTYPE\n\t#Else\n\t\t#If HOST = \"winnt\"\n\t\t\t#UTIL_WRITELINE_ENDTYPE = \"CRLF\"\n\t\t#Else\n\t\t\t#UTIL_WRITELINE_ENDTYPE = \"LF\"\n\t\t#End\n\t#End\n#End\n\n' Imports (Public):\nImport autostream\n\nImport byteorder\nImport imagedimensions\nImport retrostrings\nImport stringutil\nImport boxutil\nImport vector\n\n#If CONSOLE_IMPLEMENTED\n\tImport console\n#End\n\nImport sizeof\nImport time\n\n#If Not BRL_GAMETARGET_IMPLEMENTED\n\tImport mojoemulator\n#End\n\n' Imports (Private):\nPrivate\n\n' Unofficial:\n#If UTIL_SUPPORT_IOELEMENTS\n\tImport ioelement\n#End\n\n' Official:\n\n' BRL:\nImport brl.databuffer\nImport brl.stream\nImport brl.filepath\n\n' Mojo:\n#If BRL_GAMETARGET_IMPLEMENTED And Not MILLISECS_IMPLEMENTED\n\tImport mojo.app\n#End\n\nPublic\n\n' Imports (Other):\n#If Not UTIL_DELEGATE_TYPETOOL\n\tPrivate\n#End\n\nImport typetool\n\n#If Not UTIL_DELEGATE_TYPETOOL\n\tPublic\n#End\n\n' Aliases:\nAlias TypeCode = Int ' Byte\n\n' Constant variable(s):\n\n' Type codes (Mainly used for generic classes):\nConst TYPE_OBJECT:TypeCode\t\t\t= 0\nConst TYPE_INT:TypeCode\t\t\t\t= 1\nConst TYPE_BOOL:TypeCode\t\t\t= 2\nConst TYPE_FLOAT:TypeCode\t\t\t= 3\nConst TYPE_STRING:TypeCode\t\t\t= 4\n\n' Type strings (Mainly used by 'TypeToString'):\nConst TYPE_UNKNOWN_STR:String\t\t\t= \"Unknown\"\nConst TYPE_OBJECT_STR:String\t\t\t= \"Object\"\n\n#If Not UTIL_TYPECODE_STRINGS_USE_SHORTHAND\n\tConst TYPE_INT_STR:String\t\t\t= \"Int\"\n\tConst TYPE_BOOL_STR:String\t\t\t= \"Bool\"\n\tConst TYPE_FLOAT_STR:String\t\t\t= \"Float\"\n\tConst TYPE_STRING_STR:String\t\t= \"String\"\n#Else\n\tConst TYPE_INT_STR:String\t\t\t= \"%\"\n\tConst TYPE_BOOL_STR:String\t\t\t= \"?\"\n\tConst TYPE_FLOAT_STR:String\t\t\t= \"#\"\n\tConst TYPE_STRING_STR:String\t\t= \"$\"\n#End\n\n' Comparison response-codes:\nConst COMPARE_UNKNOWN:Int = 0\nConst COMPARE_RIGHT:Int = 1\nConst COMPARE_LEFT:Int = -1\n\n' Ascii codes:\nConst ASCII_CARRIAGE_RETURN:Byte = 13\nConst ASCII_LINE_FEED:Byte = 10\n\n' Used mainly for external code where '-9999...' isn't ever going to be valid.\n' You should stick to 'Null' in most cases; try not to use this.\nConst NOVAR:= -999999\n\n' This acts as a general \"automatic-value\".\n' Basically, you can check against this for things like manually defined array-lengths.\nConst UTIL_AUTO:Long = -1\n\n' This is for situations where the length of something can be optional.\nConst AUTOMATIC_LENGTH:Long = -1\n\nConst ErrorTemplate:String = \"[ERROR] {Debug}: \" ' + Space\nConst LogTemplate:String = \"[Info] {Debug}: \" ' + Space\n\n' Global variable(s) (Public):\n#If CONSOLE_IMPLEMENTED\n\tGlobal DebugConsole:Console = Null\n#End\n\n' A global stack logging randomization seeds.\n' This is commonly accessed by the 'PushSeed' and 'PopSeed' functions.\nGlobal SeedStack:Stack = Null\n\n' Global variable(s) (Private):\nPrivate\n\n' Nothing so far.\n\nPublic\n\n' Functions (Public):\nFunction FLAG:ULong(ID:ULong)\n\tReturn Pow(2, ID)\nEnd\n\n' This command is little-endian only:\nFunction AsByte:UInt(I:UInt)\n\tReturn ((I Shl 24) Shr 24)\nEnd\n\n' This command treats data as 8-bit (Turns something like $F7, into $FFFFFFF7)\n' This is only applied on little-endian systems,\n' please use this command for hex values (Monkey converts hex on compile-time).\nFunction PaddedHex:UInt(I:UInt)\n\tIf (Not BigEndian()) Then\n\t\tReturn AsByte(I)\n\tEndif\n\t\n\tReturn I\nEnd\n\nFunction Transfer:Bool(InputStream:Stream, OutputStream:Stream, DataSize:ULong)\n\t' Check for errors:\n\t#If Not MONKEYLANG_EXTENSION_TYPE_UNISGNED_INT\n\t\tIf (DataSize <= 0) Then Return False\n\t#End\n\t\n\tIf (InputStream = Null Or InputStream.Eof()) Then Return False\n\tIf (OutputStream = Null) Then Return False\n\t\n\t' Local variable(s):\n\t#If FLAG_TEMP_BUFFERS\n\t\tLocal Data:DataBuffer = New DataBuffer(DataSize)\n\t\tLocal DataLength:= DataSize ' Data.Length()\n\t\t\n\t\t' Read from the input-stream, then write to the output-stream:\n\t\tInputStream.Read(Data, 0, DataLength)\n\t\tOutputStream.Write(Data, 0, DataLength)\n\t\t\n\t\tData.Discard()\n\t#Else\n\t\t'Local Data:Int[DataSize]\n\t\t'Local Data:Byte[DataSize]\n\t\t\n\t\tFor Local I:= 1 To DataSize ' Data.Length()\n\t\t\tOutputStream.WriteByte(InputStream.ReadByte())\n\t\tNext\n\t#End\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\nFunction Sq:Double(Input:Double)\n\tReturn Pow(Input, 2.0) ' Input * Input\nEnd\n\nFunction Sq:Long(Input:Long)\n\tReturn Pow(Input, 2) ' Input * Input\nEnd\n\n#If Not MONKEYLANG_EXPLICIT_BOXES\n\tFunction Sq:Long(IO:IntObject)\n\t\tReturn Sq(IO.ToInt())\n\tEnd\n\t\n\tFunction Sq:Double(FO:FloatObject)\n\t\tReturn Sq(FO.ToFloat())\n\tEnd\n#End\n\n' Ideally, the 'Denom' argument should be positive:\nFunction SMod:Long(Input:Long, Denom:Long)\n\tReturn GenericUtilities.SMod(Input, Denom)\nEnd\n\nFunction SMod:Double(Input:Double, Denom:Double)\n\tReturn GenericUtilities.SMod(Input, Denom)\nEnd\n\n#If Not MONKEYLANG_EXPLICIT_BOXES\n\tFunction SMod:Long(IO:IntObject, Denom:IntObject)\n\t\tReturn SMod(IO.ToInt(), Denom.ToInt())\n\tEnd\n\t\n\tFunction SMod:Double(FO:FloatObject, Denom:FloatObject)\n\t\tReturn SMod(FO.ToFloat(), Denom.ToFloat())\n\tEnd\n#End\n\nFunction WrapAngle:Double(A:Double)\n\t#If UTIL_WRAP_BOTH_WAYS\n\t\tReturn SMod(A, 360.0)\n\t#Else\n\t\tReturn A Mod 360.0\n\t#End\nEnd\n\nFunction WrapColor:Float(C:Double)\n\t#Rem\n\tWhile (C < 0.0)\n\t\tC += 255.0\n\tWend\n\t\n\tWhile (C > 255.0)\n\t\tC -= 255.0\n\tWend\n\t#End\n\t\n\t#If UTIL_WRAP_BOTH_WAYS\n\t\tReturn SMod(C, 256.0)\n\t#Else\n\t\tReturn (C Mod 256.0)\n\t#End\nEnd\n\n' Comparison commands:\n\n' To normal Monkey users, these do the same thing:\nFunction CompareInts:Int(X:Int, Y:Int)\n\tReturn X-Y\nEnd\n\nFunction CompareLongs:Long(X:Long, Y:Long)\n\tReturn X-Y\nEnd\n\nFunction CompareShorts:Short(X:Short, Y:Short)\n\tReturn X-Y\nEnd\n\nFunction CompateSBytes:SByte(X:SByte, Y:SByte)\n\tReturn X-Y\nEnd\n\n' This just for the sake of keeping names consistent:\nFunction CompareBytes:Byte(X:Byte, Y:Byte)\n\tReturn X-Y\nEnd\n\n' The standard return type for non-integral comparison is currently 'Int':\nFunction CompareFloats:Int(X:Float, Y:Float)\n\tIf (X < Y) Then\n\t\tReturn COMPARE_LEFT\n\tEndif\n\t\n\tReturn Int(X > Y)\nEnd\n\nFunction CompareDoubles:Int(X:Double, Y:Double)\n\tIf (X < Y) Then\n\t\tReturn COMPARE_LEFT\n\tEndif\n\t\n\tReturn Int(X > Y)\nEnd\n\nFunction CompareStrings:Int(X:String, Y:String)\n\tReturn X.Compare(Y)\nEnd\n\n' Comparison wrappers:\nFunction Compare:Int(X:Int, Y:Int)\n\tReturn CompareInts(X, Y)\nEnd\n\nFunction Compare:Int(X:Float, Y:Float)\n\tReturn CompareFloats(X, Y)\nEnd\n\nFunction Compare:Int(X:String, Y:String)\n\tReturn CompareStrings(X, Y)\nEnd\n\n' Extension-based wrappers:\n#If MONKEYLANG_EXTENSION_TYPE_LONG\n\tFunction Compare:Long(X:Long, Y:Long)\n\t\tReturn CompareLongs(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_SHORT\n\tFunction Compare:Short(X:Short, Y:Short)\n\t\tReturn CompareShorts(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_SBYTE\n\tFunction Compare:SByte(X:SByte, Y:SByte)\n\t\tReturn CompareSBytes(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_BYTE\n\tFunction Compare:Byte(X:Byte, Y:Byte)\n\t\tReturn CompareBytes(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_DOUBLE\n\tFunction Compare:Int(X:Double, Y:Double)\n\t\tReturn CompareDoubles(X, Y)\n\tEnd\n#End\n\n' This command is a helper function for the inverse position of a byte inside of an integer.\nFunction ProcessColorLocation:UInt(Point:Byte)\n\t#If Not MONKEYLANG_EXTENSION_TYPE_BYTE\n\t\t' Check for errors:\n\t\tIf (Point < 0) Then\n\t\t\tReturn 0\n\t\tEndif\n\t#End\n\t\n\tReturn (SizeOf_Integer_InBits-(SizeOf_Octet_InBits*(Point+1))) ' ((SizeOf_Integer_InBits-SizeOf_Octet_InBits)-(SizeOf_Octet_InBits*Point))\nEnd\n\n' NOTE: This command will produce incorrect color values without all characters present in the encode-string.\nFunction ColorToString:String(Pixel:UInt, Encoding:String=\"ARGB\")\n\t' Ensure the encoding is always described as uppercase.\n\tEncoding = Encoding.ToUpper()\n\t\n\t' Return the encoded color-string:\n\tReturn (\"R: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"R\"))) & $000000FF) +\n\t\t\t\", G: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"G\"))) & $000000FF) +\n\t\t\t\", B: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"B\"))) & $000000FF) +\n\t\t\t\", A: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"A\"))) & $000000FF))\nEnd\n\nFunction PrintColor:Void(Pixel:UInt, Encoding:String=\"ARGB\")\n\tPrint(ColorToString(Pixel, Encoding))\n\t\n\tReturn\nEnd\n\n' This is just a wrapper for the main implementation:\nFunction PushSeed:Bool()\n\tReturn PushSeed(Seed)\nEnd\n\n' The return value of this function specifies if the seed-stack already existed.\nFunction PushSeed:Bool(Seed:Int)\n\t' Local variable(s):\n\tLocal Response:Bool = (SeedStack <> Null)\n\t\n\tIf (Not Response) Then\n\t\tSeedStack = New IntStack()\n\tEndif\n\t\n\tSeedStack.Push(Seed)\n\t\n\t' Return the calculated response.\n\tReturn Response\nEnd\n\n' This command retrieves a seed from the seed-stack,\n' if no seed exists, the current randomization seed is returned.\nFunction PopSeed:Int()\n\tIf (SeedStack <> Null) Then\n\t\tIf (Not SeedStack.IsEmpty()) Then\n\t\t\tReturn SeedStack.Pop()\n\t\tEndif\n\tEndif\n\t\n\t' Return the default response.\n\tReturn Seed\nEnd\n\n' This command sets the randomization seed to the current up-time of the system (In milliseconds).\nFunction SetSeedToUptime:Void()\n\tSeed = Millisecs()\n\t\n\tReturn\nEnd\n\n' These commands are basic wrappers for the 'Rnd' command, which allow the user to generate\n' a one-off random number (Without changing the seed after execution).\nFunction RandomNumber:Double()\n\t' Push the current seed onto the seed-stack.\n\tPushSeed()\n\t\n\t' Set the seed to the up-time of the system (In milliseconds).\n\tSetSeedToUptime()\n\t\n\t' Local variable(s):\n\t\n\t' Randomize a number for the user.\n\tLocal Number:= Rnd()\n\t\n\t' Pop the last saved seed off of the seed-stack.\n\tPopSeed()\n\t\n\t' Return the randomized number.\n\tReturn Number\nEnd\n\nFunction RandomNumber:Double(Range:Double)\n\t' Push the current seed onto the seed-stack.\n\tPushSeed()\n\t\n\t' Set the seed to the up-time of the system (In milliseconds).\n\tSetSeedToUptime()\n\t\n\t' Local variable(s):\n\t\n\t' Randomize a number for the user.\n\tLocal Number:= Rnd(Range)\n\t\n\t' Pop the last saved seed off of the seed-stack.\n\tPopSeed()\n\t\n\t' Return the randomized number.\n\tReturn Number\nEnd\n\nFunction RandomNumber:Double(Low:Double, High:Double)\n\t' Push the current seed onto the seed-stack.\n\tPushSeed()\n\t\n\t' Set the seed to the up-time of the system (In milliseconds).\n\tSetSeedToUptime()\n\t\n\t' Local variable(s):\n\t\n\t' Randomize a number for the user.\n\tLocal Number:= Rnd(Low, High)\n\t\n\t' Pop the last saved seed off of the seed-stack.\n\tPopSeed()\n\t\n\t' Return the randomized number.\n\tReturn Number\nEnd\n\n' This command writes a standard line to a 'Stream'.\n' This supports both 'LF', and 'CRLF' line endings currently, and this can be configured with 'UTIL_WRITELINE_ENDTYPE'.\n' Though character encoding is supported with this, only ASCII is supported by 'ReadLine'.\nFunction WriteLine:Bool(S:Stream, Line:String, CharacterEncoding:String=\"ascii\")\n\t' Check for errors:\n\tIf (S = Null) Then\n\t\tReturn False\n\tEndif\n\t\n\tS.WriteString(Line, CharacterEncoding)\n\t\n\t#If UTIL_WRITELINE_ENDTYPE = \"CRLF\"\n\t\tS.WriteByte(ASCII_CARRIAGE_RETURN)\n\t#End\n\t\n\tS.WriteByte(ASCII_LINE_FEED)\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\n' This command reads a standard line from a 'Stream'. (This supports both 'LF', and 'CRLF' line endings currently)\n' In addition, only 'ASCII' is currently supported.\nFunction ReadLine:String(S:Stream)\n\t' Local variable(s):\n\tLocal Position:= S.Position()\n\tLocal Padding:ULong = 0 ' * SizeOf_Char\n\t\n\tLocal Str:String\n\t\n\t#If Not UTIL_READ_LINES_QUICKLY\n\t\tLocal Size:ULong = 0\n\t#End\n\t\n\tWhile (Not S.Eof())\n\t\tLocal Char:= S.ReadByte()\n\t\t\n\t\tIf (Char <> ASCII_LINE_FEED) Then\n\t\t\tIf (Char <> ASCII_CARRIAGE_RETURN) Then\n\t\t\t\t#If UTIL_READ_LINES_QUICKLY\n\t\t\t\t\tStr += String.FromChar(Char)\n\t\t\t\t#Else\n\t\t\t\t\tSize += 1\n\t\t\t\t#End\n\t\t\tElse\n\t\t\t\tPadding = 2*SizeOf_Char\n\t\t\tEndif\n\t\tElse\n\t\t\t#Rem\n\t\t\t\tIf (Padding = 0) Then\n\t\t\t\t\tPadding = 1\n\t\t\t\tEndif\n\t\t\t#End\n\t\t\t\n\t\t\tPadding = Max(Padding, 1*SizeOf_Char)\n\t\t\t\n\t\t\tExit\n\t\tEndif\n\tWend\n\t\n\t#If Not UTIL_READ_LINES_QUICKLY\n\t\tS.Seek(Position)\n\t\t\n\t\tStr = S.ReadString(Size, \"ascii\")\n\t\t\n\t\tS.Seek(S.Position()+Padding)\n\t#End\n\t\n\t' Return the string we read from the stream.\n\tReturn Str\nEnd\n\nFunction ResizeBuffer:DataBuffer(Buffer:DataBuffer, Size:Long=AUTOMATIC_LENGTH, CopyData:Bool=True, DiscardOldBuffer:Bool=False, OnlyWhenDifferentSizes:Bool=False)\n\tLocal BufferAvailable:Bool = (Buffer <> Null)\n\t\n\tIf (BufferAvailable And OnlyWhenDifferentSizes) Then\n\t\tIf (Size <> AUTOMATIC_LENGTH And Buffer.Length() = Size) Then\n\t\t\tReturn Buffer\n\t\tEndif\n\tEndif\n\t\n\tIf (Size = AUTOMATIC_LENGTH) Then\n\t\tSize = Buffer.Length()\n\tEndif\n\t\n\t' Allocate a new data-buffer.\n\tLocal B:= New DataBuffer(Size)\n\t\n\t' Copy the buffer's bytes over to 'B'.\n\tIf (BufferAvailable) Then\n\t\tIf (CopyData) Then\n\t\t\t' Copy the contents of 'Buffer' to the newly generated buffer-object.\n\t\t\tBuffer.CopyBytes(0, B, 0, Buffer.Length())\n\t\tEndif\n\t\t\n\t\tIf (DiscardOldBuffer) Then\n\t\t\t' Discard the old buffer.\n\t\t\tBuffer.Discard()\n\t\tEndif\n\tEndif\n\t\n\t' Return the newly generated buffer.\n\tReturn B\nEnd\n\n#If CONSOLE_IMPLEMENTED\n\tFunction DebugBind:Bool(C:Console)\n\t\tIf (C = Null) Then Return False\n\t\t\n\t\tDebugConsole = C\n\t\t\n\t\t' Return the default response.\n\t\tReturn True\n\tEnd\n#End\n\nFunction DebugError:Void(E:Throwable, StopExecution:Bool=True)\n\t#If CONFIG = \"debug\"\n\t\tDebugStop()\n\t#Else\n\t\tDebugPrint(\"Unknown exception has been thrown; continuing anyway.\")\n\t#End\n\t\n\tReturn\nEnd\n\nFunction DebugError:Void(Msg:String, StopExecution:Bool=True)\n\t#If DEBUG_PRINT\n\t\t' Local variable(s):\n\t\tLocal TempMsg:String\n\t\t\n\t\tIf (StopExecution) Then\n\t\t\tTempMsg = ErrorTemplate\n\t\tElse\n\t\t\tTempMsg = LogTemplate\n\t\tEndif\n\t\t\n\t\t' Generate the final message:\n\t\tMsg = TempMsg +\n\t\t\n\t\t#If DEBUG_PRINT_QUOTES\n\t\t\tQuote + Msg + Quote\n\t\t#Else\n\t\t\tMsg\n\t\t#End\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\tDebugConsole.WriteLine(Msg, True)\n\t\t\tElse\n\t\t#End\n\t\t\n\t\tPrint(Msg)\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tEndif\n\t\t#End\n\t#Else\n\t\t' This may change later:\n\t\tIf (StopExecution) Then\n\t\t\tMsg = ErrorTemplate + Msg\n\t\tEndif\n\t#End\n\n\tIf (StopExecution) Then\n\t\t#If CONFIG = \"debug\"\n\t\t\t#If DEBUG_PRINT_ON_ERROR\n\t\t\t\tDebugStop()\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#Else\n\t\t\t#If DEBUG_PRINT\n\t\t\t\tLocal FinalStr:String = (ErrorTemplate + Quote + \"Attempt to stop execution failed. (Reason: Release-mode)\" + Quote)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\t\t\tDebugConsole.WriteLine(FinalStr, True)\n\t\t\t\t\tElse\n\t\t\t\t#End\n\t\t\t\t\n\t\t\t\tPrint(FinalStr)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tEndif\n\t\t\t\t#End\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#End\n\tEndif\n\t\n\tReturn\nEnd\n\nFunction DebugPrint:Void(Str:String, StopExecution:Bool=False)\n\tDebugError(Str, StopExecution)\n\t\n\tReturn\nEnd\n\n' This command is useful for dealing with arrays:\nFunction OutOfBounds:Bool(Position:ULong, Length:ULong)\n\tReturn (Position >= Length)\nEnd\n\n' The following functions are designed to be used with generic classes:\nFunction TypeIsObject:Bool(O:Object)\n\tReturn True\nEnd\n\nFunction TypeIsObject:Bool(IO:IntObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(BO:BoolObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(FO:FloatObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(SO:StringObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(I:Int)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(B:Bool)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(F:Float)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(S:String)\n\tReturn False\nEnd\n\nFunction TypeOf:TypeCode(O:Object)\n\tReturn TYPE_OBJECT\nEnd\n\n' Normally, I'd have these surrounded by a preprocessor check for an extension, but this is purposeful.\nFunction TypeOf:TypeCode(IO:IntObject)\n\tReturn TYPE_INT\nEnd\n\nFunction TypeOf:TypeCode(BO:BoolObject)\n\tReturn TYPE_BOOL\nEnd\n\nFunction TypeOf:TypeCode(FO:FloatObject)\n\tReturn TYPE_FLOAT\nEnd\n\nFunction TypeOf:TypeCode(SO:StringObject)\n\tReturn TYPE_STRING\nEnd\n\nFunction TypeOf:TypeCode(I:Int)\n\tReturn TYPE_INT\nEnd\n\nFunction TypeOf:TypeCode(B:Bool)\n\tReturn TYPE_BOOL\nEnd\n\nFunction TypeOf:TypeCode(F:Float)\n\tReturn TYPE_FLOAT\nEnd\n\nFunction TypeOf:TypeCode(S:String)\n\tReturn TYPE_STRING\nEnd\n\nFunction TypeAsString:String(O:Object)\n\tReturn TypeAsString(TYPE_OBJECT) ' TypeToString(TypeOf(O))\nEnd\n\nFunction TypeAsString:String(IO:IntObject)\n\tReturn TypeAsString(TYPE_INT) ' TypeToString(TypeOf(IO))\nEnd\n\nFunction TypeAsString:String(BO:BoolObject)\n\tReturn TypeAsString(TYPE_BOOL) ' TypeToString(TypeOf(BO))\nEnd\n\nFunction TypeAsString:String(FO:FloatObject)\n\tReturn TypeAsString(TYPE_FLOAT) ' TypeToString(TypeOf(FO))\nEnd\n\nFunction TypeAsString:String(SO:StringObject)\n\tReturn TypeAsString(TYPE_STRING) ' TypeToString(TypeOf(SO))\nEnd\n\nFunction TypeAsString:String(I:Int)\n\tReturn TypeToString(TYPE_INT) ' TypeToString(TypeOf(I))\nEnd\n\nFunction TypeAsString:String(B:Bool)\n\tReturn TypeToString(TYPE_BOOL) ' TypeToString(TypeOf(B))\nEnd\n\nFunction TypeAsString:String(F:Float)\n\tReturn TypeToString(TYPE_FLOAT) ' TypeToString(TypeOf(F))\nEnd\n\nFunction TypeAsString:String(S:String)\n\tReturn TypeToString(TYPE_STRING) ' TypeToString(TypeOf(S))\nEnd\n\nFunction TypeToString:String(Code:TypeCode)\n\t' Check if the input-code is known:\n\tSelect Code\n\t\tCase TYPE_OBJECT\n\t\t\tReturn TYPE_OBJECT_STR\n\t\tCase TYPE_INT\n\t\t\tReturn TYPE_INT_STR\n\t\tCase TYPE_BOOL\n\t\t\tReturn TYPE_BOOL_STR\n\t\tCase TYPE_FLOAT\n\t\t\tReturn TYPE_FLOAT_STR\n\t\tCase TYPE_STRING\n\t\t\tReturn TYPE_STRING_STR\n\tEnd Select\n\t\n\t' If nothing else, return the \"unknown type\" 'String'.\n\tReturn TYPE_UNKNOWN_STR\nEnd\n\n' Functions (Private):\nPrivate\n\n' The following commands were created to solve auto-conversion conflicts with the standard \"box\" classes:\nFunction Sgn:Long(I:Long)\n\tReturn math.Sgn(I)\nEnd\n\nFunction Sgn:Double(F:Double)\n\tReturn math.Sgn(F)\nEnd\n\n#If Not MONKEYLANG_EXPLICIT_BOXES\n\tFunction Sgn:Long(IO:IntObject)\n\t\tReturn Sgn(IO.ToInt())\n\t\t'Return math.Sgn(IO.ToInt())\n\tEnd\n\t\n\tFunction Sgn:Double(FO:FloatObject)\n\t\tReturn Sgn(FO.ToFloat())\n\t\t'Return math.Sgn(FO.ToFloat())\n\tEnd\n#End\n\nPublic\n\n' Classes:\nClass GenericUtilities\n\t' Constant variable(s):\n\t\n\t' Comparison response codes (Positive numbers are for error-reporting):\n\tConst COMPARE_RESPONSE_IDENTICAL:Int\t\t\t= -1\n\tConst COMPARE_RESPONSE_WRONG_LENGTH:Int\t\t\t= -2\n\t\n\t' Other:\n\tConst AUTO:= UTIL_AUTO\n\t\n\t' Global variable(s):\n\t\n\t' For internal and extern use. That being said, please do not modify this value.\n\tGlobal NIL:T\n\t\n\t' Functions:\n\t\n\t' This command gives the user the type-code of 'T'.\n\tFunction Type:TypeCode()\n\t\t' Return the type code of 'NIL'.\n\t\tReturn TypeOf(NIL)\n\tEnd\n\t\n\t' This command specifies if 'T' is an object.\n\tFunction IsObject:Bool()\n\t\tReturn TypeIsObject(NIL)\n\tEnd\n\t\n\t' This command wraps the standard 'BoolToString' conversion command.\n\tFunction AsString:String(Input:Bool)\n\t\tReturn BoolToString(Input)\n\tEnd\n\t\n\t' This command reads a string from a standard 'Stream' object.\n\tFunction AsString:String(S:Stream, Length:Long=AUTO, Encoding:String=\"utf8\")\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = S.Length()\n\t\tEndif\n\t\t\n\t\tReturn S.ReadString(Length, Encoding)\n\tEnd\n\t\n\t' By default, this command will add the 'Offset' argument to the processed version of the 'Length' argument.\n\t' To disable this, set 'ApplyOffsetToLength' to 'False'.\n\tFunction AsString:String(Input:T[], Offset:ULong=0, Length:Long=AUTO, AddSpaces:Bool=True, ApplyOffsetToLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal Output:String = LeftBracket\n\t\t\n\t\t' If no length was specified, use the array's length:\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Input.Length()\n\t\tEndif\n\t\t\n\t\tLocal VirtualLength:ULong\n\t\t\n\t\tIf (ApplyOffsetToLength) Then\n\t\t\tVirtualLength = Length+Offset\n\t\tElse\n\t\t\tVirtualLength = Length\n\t\tEndif\n\t\t\n\t\tFor Local Index:= Offset Until VirtualLength\n\t\t\tOutput += String(Input[Index])\n\t\t\t\n\t\t\tIf (Index+1 < VirtualLength) Then\n\t\t\t\tIf (AddSpaces) Then\n\t\t\t\t\tOutput += (Comma + Space) ' \", \"\n\t\t\t\tElse\n\t\t\t\t\tOutput += Comma\n\t\t\t\tEndif\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\tReturn Output + RightBracket\n\tEnd\n\t\n\tFunction CopyStringToArray:T[](Input:String, Output:T[], Offset:ULong=0, Length:Long=AUTO)\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Min(Input.Length(), Output.Length())\n\t\tEndif\n\t\t\n\t\tFor Local I:= Offset Until Length\n\t\t\tOutput[I] = Input[I]\n\t\tNext\n\t\t\n\t\t' Just for the sake of convenience, return the 'Output' array.\n\t\tReturn Output\n\tEnd\n\t\n\tFunction IndexOfList:T(L:List, Index:ULong=0)\n\t\t' Local variable(s):\n\t\tLocal Data:list.Node = L.FirstNode()\n\t\t\t\t\n\t\tFor Local I:= 0 Until Index\n\t\t\tData = Data.NextNode()\n\t\t\t\n\t\t\t' Not my favorite method, but it works:\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn NIL\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the value of the assessed node.\n\t\tReturn Data.Value()\n\tEnd\n\t\n\tFunction Zero:T[](Input:T[])\n\t\tReturn Nil(Input)\n\tEnd\n\t\n\tFunction Nil:T[](Input:T[])\n\t\tFor Local Index:= 0 Until Input.Length()\n\t\t\tInput[Index] = NIL\n\t\tNext\n\t\t\n\t\tReturn Input\n\tEnd\n\t\n\tFunction SMod:T(Input:T, Denom:T)\n\t\tReturn (Input Mod (Denom*Sgn(Input)))\n\tEnd\n\t\n\tFunction PrintArray:Void(Input:T[])\n\t\tPrint(AsString(Input))\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction OutputArray:Void(Input:T[])\n\t\tPrintArray(Input)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction OutputArray:Void(Input:T[], S:Stream, WriteLength:Bool=False)\n\t\tWrite(S, Input, WriteLength)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod ReadArray:Void(Input:T[], S:Stream, Size:Long=AUTO)\n\t\tRead(S, Input, Size)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\t\tNOTES:\n\t\t\t* In the event of an error, an empty array will be produced.\n\t\t\t\n\t\t\t* The 'CopyArray' command's 'FitSource' argument should only be enabled with the\n\t\t\tknowledge that the original destination may have been discarded.\n\t\t\t\n\t\t\tYour code must reflect this by disregarding the original array,\n\t\t\tand simply assigning the old array to the retrun value.\n\t\t\t\n\t\t\tEXAMPLE:\n\t\t\t\t' Local variable(s):\n\t\t\t\tLocal A:T[10], A2:T[3]\n\t\t\t\t\n\t\t\t\t' This will likely produce a new 'T' array, based on the area-delta.\n\t\t\t\tA2 = CopyArray(A, A2, True)\n\t#End\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], FitSource:Bool)\n\t\tReturn CopyArray(Source, Destination, 0, 0, AUTO, AUTO, FitSource)\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], Source_Offset:ULong=0, Destination_Offset:ULong=0, Source_Length:Long=AUTO, Destination_Length:Long=AUTO, FitSource:Bool=False)\n\t\tIf (Source_Length = AUTO) Then\n\t\t\tSource_Length = Source.Length()\n\t\tEndif\n\t\t\n\t\tIf (Destination_Length = AUTO) Then\n\t\t\tDestination_Length = Destination.Length()\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\t\n\t\t' These two are used as caches for the real lengths of the arrays:\n\t\tLocal Destination_RealLength:= Destination.Length()\n\t\tLocal Source_RealLength:= Source.Length()\n\t\t\n\t\t' Calculate the source and destination areas:\n\t\tLocal Source_Area:Long = (Source_Length-Source_Offset)\n\t\t\n\t\t' Make sure we have a source to work with:\n\t\tIf (Source_Area <= 0) Then\n\t\t\t' The source-area is too small for use, return an empty array.\n\t\t\tReturn []\n\t\tEndif\n\t\t\n\t\tLocal Destination_Area:Long = (Destination_Length-Destination_Offset)\n\t\t\n\t\t' If we're not going to fit the source, check if the destination-area is big enough:\n\t\tIf (Not FitSource) Then\n\t\t\tIf (Destination_Area <= 0) Then\n\t\t\t\t' The destination-area is too small for use, return an empty array.\n\t\t\t\tReturn []\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tLocal Operation_Area:Long\n\t\t\n\t\tIf (FitSource And Destination_Area < Source_Area) Then\n\t\t\tLocal AreaDelta:Long = (Source_Area-Destination_Area)\n\t\t\tLocal NewArea:Long = (Destination_RealLength+AreaDelta)\n\t\t\t\n\t\t\tIf (NewArea > Destination_RealLength) Then\n\t\t\t\tDestination = Destination.Resize(NewArea)\n\t\t\tElse\n\t\t\t\tDestination = Destination.Resize(Destination_Length+AreaDelta)\n\t\t\tEndif\n\t\t\t\n\t\t\tDestination_Area = Source_Area\n\t\t\tOperation_Area = Destination_Area\n\t\tElse\n\t\t\tOperation_Area = Min(Source_Area, Destination_Area)\n\t\tEndif\n\t\t\n\t\t' Copy the contents of the source-array into the destination-array:\n\t\tFor Local Index:= 0 Until Operation_Area\n\t\t\tDestination[Index+Destination_Offset] = Source[Index+Source_Offset]\n\t\tNext\n\t\t\n\t\t' Return the destination-array.\n\t\tReturn Destination\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[])\n\t\tReturn CloneArray(Source)\n\tEnd\n\t\n\tFunction CloneArray:T[](Source:T[])\n\t\tReturn CopyArray(Source, New T[Source.Length()])\n\tEnd\n\t\n\t' This command returns a positive number upon an error,\n\t' otherwise a 'response code' will be given (See the \"Contant variable(s)\" section for details).\n\tFunction Compare:Int(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal A1_Length:= A1.Length\n\t\tLocal A2_Length:= A2.Length\n\t\t\n\t\t' Check for errors:\n\t\tIf (CheckLength) Then\n\t\t\t' Make sure they're both the same length.\n\t\t\tIf (A1_Length <> A2_Length) Then\n\t\t\t\tReturn COMPARE_RESPONSE_WRONG_LENGTH\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tFor Local I:= 0 Until Min(A1_Length, A2_Length)\n\t\t\tIf (A1[I] <> A2[I]) Then\n\t\t\t\t' Not the best of escape methods, but it works.\n\t\t\t\tReturn I\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the default response.\n\t\tReturn COMPARE_RESPONSE_IDENTICAL\n\tEnd\n\t\n\t' This function returns positive if both arrays are identical.\n\tFunction SimpleCompare:Bool(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\tReturn (Compare(A1, A2, CheckLength) = COMPARE_RESPONSE_IDENTICAL)\n\tEnd\n\t\n\tFunction Read:T(S:Stream)\n\t\tReturn Read(S, NIL)\n\tEnd\n\t\n\tFunction Read:T[](S:Stream, DataArray:T[], Size:Long=AUTO)\n\t\tIf (Size = AUTO) Then\n\t\t\tSize = S.ReadInt() ' S.ReadLong()\n\t\tEndif\n\t\t\n\t\tIf (Size > 0) Then\n\t\t\tIf (DataArray.Length() = 0) Then\n\t\t\t\tDataArray = New T[Size]\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\tLocal DLength:= Min(DataArray.Length(), Size)\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tDataArray[Index] = Read(S, NIL)\n\t\tNext\n\t\t\n\t\tReturn DataArray\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, DataArray:T[], WriteLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal DLength:= DataArray.Length()\n\t\t\n\t\tIf (WriteLength) Then\n\t\t\tS.WriteInt(DLength) ' S.WriteLong(DLength)\n\t\tEndif\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tWrite(S, DataArray[Index])\n\t\tNext\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:Long(S:Stream, Identifier:Long, Size:Byte=4)\n\t\t\tIf (Size > 1) Then\n\t\t\t\tIf (Size < 4) Then\n\t\t\t\t\tReturn S.ReadShort()\n\t\t\t\tElse\n\t\t\t\t\t' Good enough for now:\n\t\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\t\tS.ReadInt()\n\t\t\t\t\tEndif\n\t\t\t\t\t\n\t\t\t\t\tReturn S.ReadInt()\n\t\t\t\t\t'Return S.ReadLong()\n\t\t\t\tEndif\n\t\t#If MONKEYLANG_EXTENSION_TYPE_BYTE\n\t\t\tElse\n\t\t#Else\n\t\t\tElseif (Size > 0) Then\n\t\t#End\n\t\t\t\tReturn S.ReadByte()\n\t\t\tEndif\n\t\t\n\t\t' Return the default response.\n\t\tReturn 0\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:Long, Size:Byte=4)\n\t\tSize = Byte(IntSize(Size)) ' ApplyByteBounds(IntSize(Size))\n\t\t\n\t\t\tIf (Size > 1) Then\n\t\t\t\tIf (Size < 4) Then\n\t\t\t\t\tS.WriteShort(Data)\n\t\t\t\tElse\n\t\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\t\tS.WriteInt(0)\n\t\t\t\t\tEndif\n\t\t\t\t\t\n\t\t\t\t\tS.WriteInt(Data)\n\t\t\t\t\t'S.WriteLong(Data)\n\t\t\t\tEndif\n\t\t#If MONKEYLANG_EXTENSION_TYPE_BYTE\n\t\t\tElse\n\t\t#Else\n\t\t\tElseif (Size > 0) Then\n\t\t#End\n\t\t\t\tS.WriteByte(Data)\n\t\t\tEndif\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\tFunction Read:Bool(S:Stream, Identifier:Bool)\n\t\tReturn Read(S, Long(Identifier), 1)\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, B:Bool)\n\t\tWrite(S, Long(B), 1)\n\t\t\n\t\tReturn\n\tEnd\n\t#End\n\t\n\t'Function Read:Double(S:Stream, Identifier:Double)\n\tFunction Read:Float(S:Stream, Identifier:Float)\n\t\tReturn S.ReadFloat() ' S.ReadDouble()\n\tEnd\n\t\n\t'Function Write:Void(S:Stream, Data:Double)\n\tFunction Write:Void(S:Stream, Data:Float)\n\t\tS.WriteFloat(Data) ' S.ReadDouble(Data)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:String(S:Stream, Data:String, Encoding:String=\"utf8\", Size:Long=AUTO)\n\t\t' Check if the size was manually specified:\n\t\tIf (Size = AUTO) Then\n\t\t\t' Read the string's length from the input-stream.\n\t\t\tSize = S.ReadInt() ' S.ReadLong()\n\t\tEndif\n\t\t\n\t\t' Read the desired string from the input-stream, then return it.\n\t\tReturn S.ReadString(Size, Encoding)\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:String, Encoding:String=\"utf8\", WriteSize:Bool=True)\n\t\t' Check if we're writing the size of the input-string.\n\t\tIf (WriteSize) Then\n\t\t\t' Write the length of the input-string to the output-stream.\n\t\t\tS.WriteInt(Data.Length()) ' S.WriteLong(Data.Length())\n\t\tEndif\n\t\t\n\t\t' Write the input-string to the output-stream.\n\t\tS.WriteString(Data, Encoding)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#If UTIL_SUPPORT_IOELEMENTS\n\t\tFunction Read:Void(S:Stream, Data:InputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Load(S)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:OutputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Save(S)\n\t\tEnd\n\t#End\n\t\n\t' The following commands were created to solve auto-conversion conflicts with the standard \"box\" classes:\n\t#If Not MONKEYLANG_EXPLICIT_BOXES\n\t\tFunction Read:Long(S:Stream, Identifier:IntObject, Size:Byte=4)\n\t\t\tReturn Read(S, Identifier.ToInt(), Size)\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:IntObject, Size:Byte=4)\n\t\t\tWrite(S, Data.ToInt(), Size)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\t'Function Read:Double(S:Stream, Identifier:FloatObject)\n\t\tFunction Read:Float(S:Stream, Identifier:FloatObject)\n\t\t\tReturn Read(S, Identifier.ToFloat())\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:FloatObject)\n\t\t\tWrite(S, Data.ToFloat())\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t#End\n\t\n\t' Constructor(s):\n\t\n\t' DO NOT CREATE NEW INSTANCES OF THIS CLASS.\n\tMethod New()\n\t\tDebugError(\"This class should not be used in this was.\")\n\tEnd\nEnd","old_contents":"Strict\n\nPublic\n\n' Preprocessor related:\n#Rem\n#If TARGET = \"glfw\" Or TARGET = \"sexy\"\n\t#GLFW_TARGET = True\n#End\n#End\n\n#UTIL_IMPLEMENTED = True\n#UTIL_WRAP_BOTH_WAYS = True\n#UTIL_PREPROCESSOR_FIXES = False ' True\n#UTIL_DELEGATE_TYPETOOL = False\n#UTIL_TYPECODE_STRINGS_USE_SHORTHAND = False\n\n#If IOELEMENT_IMPLEMENTED\n\t#UTIL_SUPPORT_IOELEMENTS = True\n#Else\n\t#UTIL_SUPPORT_IOELEMENTS = False\n#End\n\n#If CONFIG = \"debug\"\n\t#DEBUG_PRINT = True\n#Else\n\t#DEBUG_PRINT = False\n#End\n\n#If CONFIG = \"release\"\n\t#DEBUG_PRINT_ON_ERROR = True\n#Else\n\t#DEBUG_PRINT_ON_ERROR = False\n#End\n\n#DEBUG_PRINT_QUOTES = False\n\n#If Not UTIL_PREPROCESSOR_FIXES\n\t' These are the actual default settings for these variables:\n\t#UTIL_READ_LINES_QUICKLY = True\n\t\n\t#If HOST = \"winnt\"\n\t\t#UTIL_WRITELINE_ENDTYPE = \"CRLF\" ' \"LF\"\n\t#Else\n\t\t#UTIL_WRITELINE_ENDTYPE = \"LF\"\n\t#End\n#Else\n\t' The default values of these are purposely separate from the main settings:\n\t#If READ_LINE_QUICKLY\n\t\t#UTIL_READ_LINES_QUICKLY = READ_LINE_QUICKLY\n\t#Else\n\t\t#UTIL_READ_LINES_QUICKLY = True\n\t#End\n\t\n\t#If WRITE_LINE_ENDTYPE\n\t\t#UTIL_WRITELINE_ENDTYPE = WRITE_LINE_ENDTYPE\n\t#Else\n\t\t#If HOST = \"winnt\"\n\t\t\t#UTIL_WRITELINE_ENDTYPE = \"CRLF\"\n\t\t#Else\n\t\t\t#UTIL_WRITELINE_ENDTYPE = \"LF\"\n\t\t#End\n\t#End\n#End\n\n' Imports (Public):\nImport autostream\n\nImport byteorder\nImport imagedimensions\nImport retrostrings\nImport stringutil\nImport boxutil\nImport vector\n\n#If CONSOLE_IMPLEMENTED\n\tImport console\n#End\n\nImport sizeof\nImport time\n\n#If Not BRL_GAMETARGET_IMPLEMENTED\n\tImport mojoemulator\n#End\n\n' Imports (Private):\nPrivate\n\n' Unofficial:\n#If UTIL_SUPPORT_IOELEMENTS\n\tImport ioelement\n#End\n\n' Official:\n\n' BRL:\nImport brl.databuffer\nImport brl.stream\nImport brl.filepath\n\n' Mojo:\n#If BRL_GAMETARGET_IMPLEMENTED And Not MILLISECS_IMPLEMENTED\n\tImport mojo.app\n#End\n\nPublic\n\n' Imports (Other):\n#If Not UTIL_DELEGATE_TYPETOOL\n\tPrivate\n#End\n\nImport typetool\n\n#If Not UTIL_DELEGATE_TYPETOOL\n\tPublic\n#End\n\n' Aliases:\nAlias TypeCode = Int ' Byte\n\n' Constant variable(s):\n\n' Type codes (Mainly used for generic classes):\nConst TYPE_OBJECT:TypeCode\t\t\t= 0\nConst TYPE_INT:TypeCode\t\t\t\t= 1\nConst TYPE_BOOL:TypeCode\t\t\t= 2\nConst TYPE_FLOAT:TypeCode\t\t\t= 3\nConst TYPE_STRING:TypeCode\t\t\t= 4\n\n' Type strings (Mainly used by 'TypeToString'):\nConst TYPE_UNKNOWN_STR:String\t\t\t= \"Unknown\"\nConst TYPE_OBJECT_STR:String\t\t\t= \"Object\"\n\n#If Not UTIL_TYPECODE_STRINGS_USE_SHORTHAND\n\tConst TYPE_INT_STR:String\t\t\t= \"Int\"\n\tConst TYPE_BOOL_STR:String\t\t\t= \"Bool\"\n\tConst TYPE_FLOAT_STR:String\t\t\t= \"Float\"\n\tConst TYPE_STRING_STR:String\t\t= \"String\"\n#Else\n\tConst TYPE_INT_STR:String\t\t\t= \"%\"\n\tConst TYPE_BOOL_STR:String\t\t\t= \"?\"\n\tConst TYPE_FLOAT_STR:String\t\t\t= \"#\"\n\tConst TYPE_STRING_STR:String\t\t= \"$\"\n#End\n\n' Ascii codes:\nConst ASCII_CARRIAGE_RETURN:Byte = 13\nConst ASCII_LINE_FEED:Byte = 10\n\n' Used mainly for external code where '-9999...' isn't ever going to be valid.\n' You should stick to 'Null' in most cases; try not to use this.\nConst NOVAR:= -999999\n\n' This acts as a general \"automatic-value\".\n' Basically, you can check against this for things like manually defined array-lengths.\nConst UTIL_AUTO:Long = -1\n\n' This is for situations where the length of something can be optional.\nConst AUTOMATIC_LENGTH:Long = -1\n\nConst ErrorTemplate:String = \"[ERROR] {Debug}: \" ' + Space\nConst LogTemplate:String = \"[Info] {Debug}: \" ' + Space\n\n' Global variable(s) (Public):\n#If CONSOLE_IMPLEMENTED\n\tGlobal DebugConsole:Console = Null\n#End\n\n' A global stack logging randomization seeds.\n' This is commonly accessed by the 'PushSeed' and 'PopSeed' functions.\nGlobal SeedStack:Stack = Null\n\n' Global variable(s) (Private):\nPrivate\n\n' Nothing so far.\n\nPublic\n\n' Functions (Public):\nFunction FLAG:ULong(ID:ULong)\n\tReturn Pow(2, ID)\nEnd\n\n' This command is little-endian only:\nFunction AsByte:UInt(I:UInt)\n\tReturn ((I Shl 24) Shr 24)\nEnd\n\n' This command treats data as 8-bit (Turns something like $F7, into $FFFFFFF7)\n' This is only applied on little-endian systems,\n' please use this command for hex values (Monkey converts hex on compile-time).\nFunction PaddedHex:UInt(I:UInt)\n\tIf (Not BigEndian()) Then\n\t\tReturn AsByte(I)\n\tEndif\n\t\n\tReturn I\nEnd\n\nFunction Transfer:Bool(InputStream:Stream, OutputStream:Stream, DataSize:ULong)\n\t' Check for errors:\n\t#If Not MONKEYLANG_EXTENSION_TYPE_UNISGNED_INT\n\t\tIf (DataSize <= 0) Then Return False\n\t#End\n\t\n\tIf (InputStream = Null Or InputStream.Eof()) Then Return False\n\tIf (OutputStream = Null) Then Return False\n\t\n\t' Local variable(s):\n\t#If FLAG_TEMP_BUFFERS\n\t\tLocal Data:DataBuffer = New DataBuffer(DataSize)\n\t\tLocal DataLength:= DataSize ' Data.Length()\n\t\t\n\t\t' Read from the input-stream, then write to the output-stream:\n\t\tInputStream.Read(Data, 0, DataLength)\n\t\tOutputStream.Write(Data, 0, DataLength)\n\t\t\n\t\tData.Discard()\n\t#Else\n\t\t'Local Data:Int[DataSize]\n\t\t'Local Data:Byte[DataSize]\n\t\t\n\t\tFor Local I:= 1 To DataSize ' Data.Length()\n\t\t\tOutputStream.WriteByte(InputStream.ReadByte())\n\t\tNext\n\t#End\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\nFunction Sq:Double(Input:Double)\n\tReturn Pow(Input, 2.0) ' Input * Input\nEnd\n\nFunction Sq:Long(Input:Long)\n\tReturn Pow(Input, 2) ' Input * Input\nEnd\n\n#If Not MONKEYLANG_EXPLICIT_BOXES\n\tFunction Sq:Long(IO:IntObject)\n\t\tReturn Sq(IO.ToInt())\n\tEnd\n\t\n\tFunction Sq:Double(FO:FloatObject)\n\t\tReturn Sq(FO.ToFloat())\n\tEnd\n#End\n\n' Ideally, the 'Denom' argument should be positive:\nFunction SMod:Long(Input:Long, Denom:Long)\n\tReturn GenericUtilities.SMod(Input, Denom)\nEnd\n\nFunction SMod:Double(Input:Double, Denom:Double)\n\tReturn GenericUtilities.SMod(Input, Denom)\nEnd\n\n#If Not MONKEYLANG_EXPLICIT_BOXES\n\tFunction SMod:Long(IO:IntObject, Denom:IntObject)\n\t\tReturn SMod(IO.ToInt(), Denom.ToInt())\n\tEnd\n\t\n\tFunction SMod:Double(FO:FloatObject, Denom:FloatObject)\n\t\tReturn SMod(FO.ToFloat(), Denom.ToFloat())\n\tEnd\n#End\n\nFunction WrapAngle:Double(A:Double)\n\t#If UTIL_WRAP_BOTH_WAYS\n\t\tReturn SMod(A, 360.0)\n\t#Else\n\t\tReturn A Mod 360.0\n\t#End\nEnd\n\nFunction WrapColor:Float(C:Double)\n\t#Rem\n\tWhile (C < 0.0)\n\t\tC += 255.0\n\tWend\n\t\n\tWhile (C > 255.0)\n\t\tC -= 255.0\n\tWend\n\t#End\n\t\n\t#If UTIL_WRAP_BOTH_WAYS\n\t\tReturn SMod(C, 256.0)\n\t#Else\n\t\tReturn (C Mod 256.0)\n\t#End\nEnd\n\n' Comparison commands:\n\n' To normal Monkey users, these do the same thing:\nFunction CompareInts:Int(X:Int, Y:Int)\n\tReturn X-Y\nEnd\n\nFunction CompareLongs:Long(X:Long, Y:Long)\n\tReturn X-Y\nEnd\n\nFunction CompareShorts:Short(X:Short, Y:Short)\n\tReturn X-Y\nEnd\n\nFunction CompateSBytes:SByte(X:SByte, Y:SByte)\n\tReturn X-Y\nEnd\n\n' This just for the sake of keeping names consistent:\nFunction CompareBytes:Byte(X:Byte, Y:Byte)\n\tReturn X-Y\nEnd\n\n' The standard return type for non-integral comparison is currently 'Int':\nFunction CompareFloats:Int(X:Float, Y:Float)\n\tIf (X < Y) Then\n\t\tReturn -1\n\tEndif\n\t\n\tReturn Int(X > Y)\nEnd\n\nFunction CompareDoubles:Int(X:Double, Y:Double)\n\tIf (X < Y) Then\n\t\tReturn -1\n\tEndif\n\t\n\tReturn Int(X > Y)\nEnd\n\nFunction CompareStrings:Int(X:String, Y:String)\n\tReturn X.Compare(Y)\nEnd\n\n' Comparison wrappers:\nFunction Compare:Int(X:Int, Y:Int)\n\tReturn CompareInts(X, Y)\nEnd\n\nFunction Compare:Int(X:Float, Y:Float)\n\tReturn CompareFloats(X, Y)\nEnd\n\nFunction Compare:Int(X:String, Y:String)\n\tReturn CompareStrings(X, Y)\nEnd\n\n' Extension-based wrappers:\n#If MONKEYLANG_EXTENSION_TYPE_LONG\n\tFunction Compare:Long(X:Long, Y:Long)\n\t\tReturn CompareLongs(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_SHORT\n\tFunction Compare:Short(X:Short, Y:Short)\n\t\tReturn CompareShorts(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_SBYTE\n\tFunction Compare:SByte(X:SByte, Y:SByte)\n\t\tReturn CompareSBytes(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_BYTE\n\tFunction Compare:Byte(X:Byte, Y:Byte)\n\t\tReturn CompareBytes(X, Y)\n\tEnd\n#End\n\n#If MONKEYLANG_EXTENSION_TYPE_DOUBLE\n\tFunction Compare:Int(X:Double, Y:Double)\n\t\tReturn CompareDoubles(X, Y)\n\tEnd\n#End\n\n' This command is a helper function for the inverse position of a byte inside of an integer.\nFunction ProcessColorLocation:UInt(Point:Byte) ' Byte\n\t#If Not MONKEYLANG_EXTENSION_TYPE_BYTE\n\t\t' Check for errors:\n\t\tIf (Point < 0) Then\n\t\t\tReturn 0\n\t\tEndif\n\t#End\n\t\n\tReturn (SizeOf_Integer_InBits-(SizeOf_Octet_InBits*(Point+1))) ' ((SizeOf_Integer_InBits-SizeOf_Octet_InBits)-(SizeOf_Octet_InBits*Point))\nEnd\n\n' NOTE: This command will produce incorrect color values without all characters present in the encode-string.\nFunction ColorToString:String(Pixel:UInt, Encoding:String=\"ARGB\")\n\t' Ensure the encoding is always described as uppercase.\n\tEncoding = Encoding.ToUpper()\n\t\n\t' Return the encoded color-string:\n\tReturn (\"R: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"R\"))) & $000000FF) +\n\t\t\t\", G: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"G\"))) & $000000FF) +\n\t\t\t\", B: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"B\"))) & $000000FF) +\n\t\t\t\", A: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"A\"))) & $000000FF))\nEnd\n\nFunction PrintColor:Void(Pixel:UInt, Encoding:String=\"ARGB\")\n\tPrint(ColorToString(Pixel, Encoding))\n\t\n\tReturn\nEnd\n\n' This is just a wrapper for the main implementation:\nFunction PushSeed:Bool()\n\tReturn PushSeed(Seed)\nEnd\n\n' The return value of this function specifies if the seed-stack already existed.\nFunction PushSeed:Bool(Seed:Int)\n\t' Local variable(s):\n\tLocal Response:Bool = (SeedStack <> Null)\n\t\n\tIf (Not Response) Then\n\t\tSeedStack = New IntStack()\n\tEndif\n\t\n\tSeedStack.Push(Seed)\n\t\n\t' Return the calculated response.\n\tReturn Response\nEnd\n\n' This command retrieves a seed from the seed-stack,\n' if no seed exists, the current randomization seed is returned.\nFunction PopSeed:Int()\n\tIf (SeedStack <> Null) Then\n\t\tIf (Not SeedStack.IsEmpty()) Then\n\t\t\tReturn SeedStack.Pop()\n\t\tEndif\n\tEndif\n\t\n\t' Return the default response.\n\tReturn Seed\nEnd\n\n' This command sets the randomization seed to the current up-time of the system (In milliseconds).\nFunction SetSeedToUptime:Void()\n\tSeed = Millisecs()\n\t\n\tReturn\nEnd\n\n' These commands are basic wrappers for the 'Rnd' command, which allow the user to generate\n' a one-off random number (Without changing the seed after execution).\nFunction RandomNumber:Double()\n\t' Push the current seed onto the seed-stack.\n\tPushSeed()\n\t\n\t' Set the seed to the up-time of the system (In milliseconds).\n\tSetSeedToUptime()\n\t\n\t' Local variable(s):\n\t\n\t' Randomize a number for the user.\n\tLocal Number:= Rnd()\n\t\n\t' Pop the last saved seed off of the seed-stack.\n\tPopSeed()\n\t\n\t' Return the randomized number.\n\tReturn Number\nEnd\n\nFunction RandomNumber:Double(Range:Double)\n\t' Push the current seed onto the seed-stack.\n\tPushSeed()\n\t\n\t' Set the seed to the up-time of the system (In milliseconds).\n\tSetSeedToUptime()\n\t\n\t' Local variable(s):\n\t\n\t' Randomize a number for the user.\n\tLocal Number:= Rnd(Range)\n\t\n\t' Pop the last saved seed off of the seed-stack.\n\tPopSeed()\n\t\n\t' Return the randomized number.\n\tReturn Number\nEnd\n\nFunction RandomNumber:Double(Low:Double, High:Double)\n\t' Push the current seed onto the seed-stack.\n\tPushSeed()\n\t\n\t' Set the seed to the up-time of the system (In milliseconds).\n\tSetSeedToUptime()\n\t\n\t' Local variable(s):\n\t\n\t' Randomize a number for the user.\n\tLocal Number:= Rnd(Low, High)\n\t\n\t' Pop the last saved seed off of the seed-stack.\n\tPopSeed()\n\t\n\t' Return the randomized number.\n\tReturn Number\nEnd\n\n' This command writes a standard line to a 'Stream'.\n' This supports both 'LF', and 'CRLF' line endings currently, and this can be configured with 'UTIL_WRITELINE_ENDTYPE'.\n' Though character encoding is supported with this, only ASCII is supported by 'ReadLine'.\nFunction WriteLine:Bool(S:Stream, Line:String, CharacterEncoding:String=\"ascii\")\n\t' Check for errors:\n\tIf (S = Null) Then\n\t\tReturn False\n\tEndif\n\t\n\tS.WriteString(Line, CharacterEncoding)\n\t\n\t#If UTIL_WRITELINE_ENDTYPE = \"CRLF\"\n\t\tS.WriteByte(ASCII_CARRIAGE_RETURN)\n\t#End\n\t\n\tS.WriteByte(ASCII_LINE_FEED)\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\n' This command reads a standard line from a 'Stream'. (This supports both 'LF', and 'CRLF' line endings currently)\n' In addition, only 'ASCII' is currently supported.\nFunction ReadLine:String(S:Stream)\n\t' Local variable(s):\n\tLocal Position:= S.Position()\n\tLocal Padding:ULong = 0 ' * SizeOf_Char\n\t\n\tLocal Str:String\n\t\n\t#If Not UTIL_READ_LINES_QUICKLY\n\t\tLocal Size:ULong = 0\n\t#End\n\t\n\tWhile (Not S.Eof())\n\t\tLocal Char:= S.ReadByte()\n\t\t\n\t\tIf (Char <> ASCII_LINE_FEED) Then\n\t\t\tIf (Char <> ASCII_CARRIAGE_RETURN) Then\n\t\t\t\t#If UTIL_READ_LINES_QUICKLY\n\t\t\t\t\tStr += String.FromChar(Char)\n\t\t\t\t#Else\n\t\t\t\t\tSize += 1\n\t\t\t\t#End\n\t\t\tElse\n\t\t\t\tPadding = 2*SizeOf_Char\n\t\t\tEndif\n\t\tElse\n\t\t\t#Rem\n\t\t\t\tIf (Padding = 0) Then\n\t\t\t\t\tPadding = 1\n\t\t\t\tEndif\n\t\t\t#End\n\t\t\t\n\t\t\tPadding = Max(Padding, 1*SizeOf_Char)\n\t\t\t\n\t\t\tExit\n\t\tEndif\n\tWend\n\t\n\t#If Not UTIL_READ_LINES_QUICKLY\n\t\tS.Seek(Position)\n\t\t\n\t\tStr = S.ReadString(Size, \"ascii\")\n\t\t\n\t\tS.Seek(S.Position()+Padding)\n\t#End\n\t\n\t' Return the string we read from the stream.\n\tReturn Str\nEnd\n\nFunction ResizeBuffer:DataBuffer(Buffer:DataBuffer, Size:Long=AUTOMATIC_LENGTH, CopyData:Bool=True, DiscardOldBuffer:Bool=False, OnlyWhenDifferentSizes:Bool=False)\n\tLocal BufferAvailable:Bool = (Buffer <> Null)\n\t\n\tIf (BufferAvailable And OnlyWhenDifferentSizes) Then\n\t\tIf (Size <> AUTOMATIC_LENGTH And Buffer.Length() = Size) Then\n\t\t\tReturn Buffer\n\t\tEndif\n\tEndif\n\t\n\tIf (Size = AUTOMATIC_LENGTH) Then\n\t\tSize = Buffer.Length()\n\tEndif\n\t\n\t' Allocate a new data-buffer.\n\tLocal B:= New DataBuffer(Size)\n\t\n\t' Copy the buffer's bytes over to 'B'.\n\tIf (BufferAvailable) Then\n\t\tIf (CopyData) Then\n\t\t\t' Copy the contents of 'Buffer' to the newly generated buffer-object.\n\t\t\tBuffer.CopyBytes(0, B, 0, Buffer.Length())\n\t\tEndif\n\t\t\n\t\tIf (DiscardOldBuffer) Then\n\t\t\t' Discard the old buffer.\n\t\t\tBuffer.Discard()\n\t\tEndif\n\tEndif\n\t\n\t' Return the newly generated buffer.\n\tReturn B\nEnd\n\n#If CONSOLE_IMPLEMENTED\n\tFunction DebugBind:Bool(C:Console)\n\t\tIf (C = Null) Then Return False\n\t\t\n\t\tDebugConsole = C\n\t\t\n\t\t' Return the default response.\n\t\tReturn True\n\tEnd\n#End\n\nFunction DebugError:Void(E:Throwable, StopExecution:Bool=True)\n\t#If CONFIG = \"debug\"\n\t\tDebugStop()\n\t#Else\n\t\tDebugPrint(\"Unknown exception has been thrown; continuing anyway.\")\n\t#End\n\t\n\tReturn\nEnd\n\nFunction DebugError:Void(Msg:String, StopExecution:Bool=True)\n\t#If DEBUG_PRINT\n\t\t' Local variable(s):\n\t\tLocal TempMsg:String\n\t\t\n\t\tIf (StopExecution) Then\n\t\t\tTempMsg = ErrorTemplate\n\t\tElse\n\t\t\tTempMsg = LogTemplate\n\t\tEndif\n\t\t\n\t\t' Generate the final message:\n\t\tMsg = TempMsg +\n\t\t\n\t\t#If DEBUG_PRINT_QUOTES\n\t\t\tQuote + Msg + Quote\n\t\t#Else\n\t\t\tMsg\n\t\t#End\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\tDebugConsole.WriteLine(Msg, True)\n\t\t\tElse\n\t\t#End\n\t\t\n\t\tPrint(Msg)\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tEndif\n\t\t#End\n\t#Else\n\t\t' This may change later:\n\t\tIf (StopExecution) Then\n\t\t\tMsg = ErrorTemplate + Msg\n\t\tEndif\n\t#End\n\n\tIf (StopExecution) Then\n\t\t#If CONFIG = \"debug\"\n\t\t\t#If DEBUG_PRINT_ON_ERROR\n\t\t\t\tDebugStop()\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#Else\n\t\t\t#If DEBUG_PRINT\n\t\t\t\tLocal FinalStr:String = (ErrorTemplate + Quote + \"Attempt to stop execution failed. (Reason: Release-mode)\" + Quote)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\t\t\tDebugConsole.WriteLine(FinalStr, True)\n\t\t\t\t\tElse\n\t\t\t\t#End\n\t\t\t\t\n\t\t\t\tPrint(FinalStr)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tEndif\n\t\t\t\t#End\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#End\n\tEndif\n\t\n\tReturn\nEnd\n\nFunction DebugPrint:Void(Str:String, StopExecution:Bool=False)\n\tDebugError(Str, StopExecution)\n\t\n\tReturn\nEnd\n\n' This command is useful for dealing with arrays:\nFunction OutOfBounds:Bool(Position:ULong, Length:ULong)\n\tReturn (Position >= Length)\nEnd\n\n' The following functions are designed to be used with generic classes:\nFunction TypeIsObject:Bool(O:Object)\n\tReturn True\nEnd\n\nFunction TypeIsObject:Bool(IO:IntObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(BO:BoolObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(FO:FloatObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(SO:StringObject)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(I:Int)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(B:Bool)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(F:Float)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(S:String)\n\tReturn False\nEnd\n\nFunction TypeOf:TypeCode(O:Object)\n\tReturn TYPE_OBJECT\nEnd\n\n' Normally, I'd have these surrounded by a preprocessor check for an extension, but this is purposeful.\nFunction TypeOf:TypeCode(IO:IntObject)\n\tReturn TYPE_INT\nEnd\n\nFunction TypeOf:TypeCode(BO:BoolObject)\n\tReturn TYPE_BOOL\nEnd\n\nFunction TypeOf:TypeCode(FO:FloatObject)\n\tReturn TYPE_FLOAT\nEnd\n\nFunction TypeOf:TypeCode(SO:StringObject)\n\tReturn TYPE_STRING\nEnd\n\nFunction TypeOf:TypeCode(I:Int)\n\tReturn TYPE_INT\nEnd\n\nFunction TypeOf:TypeCode(B:Bool)\n\tReturn TYPE_BOOL\nEnd\n\nFunction TypeOf:TypeCode(F:Float)\n\tReturn TYPE_FLOAT\nEnd\n\nFunction TypeOf:TypeCode(S:String)\n\tReturn TYPE_STRING\nEnd\n\nFunction TypeAsString:String(O:Object)\n\tReturn TypeAsString(TYPE_OBJECT) ' TypeToString(TypeOf(O))\nEnd\n\nFunction TypeAsString:String(IO:IntObject)\n\tReturn TypeAsString(TYPE_INT) ' TypeToString(TypeOf(IO))\nEnd\n\nFunction TypeAsString:String(BO:BoolObject)\n\tReturn TypeAsString(TYPE_BOOL) ' TypeToString(TypeOf(BO))\nEnd\n\nFunction TypeAsString:String(FO:FloatObject)\n\tReturn TypeAsString(TYPE_FLOAT) ' TypeToString(TypeOf(FO))\nEnd\n\nFunction TypeAsString:String(SO:StringObject)\n\tReturn TypeAsString(TYPE_STRING) ' TypeToString(TypeOf(SO))\nEnd\n\nFunction TypeAsString:String(I:Int)\n\tReturn TypeToString(TYPE_INT) ' TypeToString(TypeOf(I))\nEnd\n\nFunction TypeAsString:String(B:Bool)\n\tReturn TypeToString(TYPE_BOOL) ' TypeToString(TypeOf(B))\nEnd\n\nFunction TypeAsString:String(F:Float)\n\tReturn TypeToString(TYPE_FLOAT) ' TypeToString(TypeOf(F))\nEnd\n\nFunction TypeAsString:String(S:String)\n\tReturn TypeToString(TYPE_STRING) ' TypeToString(TypeOf(S))\nEnd\n\nFunction TypeToString:String(Code:TypeCode)\n\t' Check if the input-code is known:\n\tSelect Code\n\t\tCase TYPE_OBJECT\n\t\t\tReturn TYPE_OBJECT_STR\n\t\tCase TYPE_INT\n\t\t\tReturn TYPE_INT_STR\n\t\tCase TYPE_BOOL\n\t\t\tReturn TYPE_BOOL_STR\n\t\tCase TYPE_FLOAT\n\t\t\tReturn TYPE_FLOAT_STR\n\t\tCase TYPE_STRING\n\t\t\tReturn TYPE_STRING_STR\n\tEnd Select\n\t\n\t' If nothing else, return the \"unknown type\" 'String'.\n\tReturn TYPE_UNKNOWN_STR\nEnd\n\n' Functions (Private):\nPrivate\n\n' The following commands were created to solve auto-conversion conflicts with the standard \"box\" classes:\nFunction Sgn:Long(I:Long)\n\tReturn math.Sgn(I)\nEnd\n\nFunction Sgn:Double(F:Double)\n\tReturn math.Sgn(F)\nEnd\n\n#If Not MONKEYLANG_EXPLICIT_BOXES\n\tFunction Sgn:Long(IO:IntObject)\n\t\tReturn Sgn(IO.ToInt())\n\t\t'Return math.Sgn(IO.ToInt())\n\tEnd\n\t\n\tFunction Sgn:Double(FO:FloatObject)\n\t\tReturn Sgn(FO.ToFloat())\n\t\t'Return math.Sgn(FO.ToFloat())\n\tEnd\n#End\n\nPublic\n\n' Classes:\nClass GenericUtilities\n\t' Constant variable(s):\n\t\n\t' Comparison response codes (Positive numbers are for error-reporting):\n\tConst COMPARE_RESPONSE_IDENTICAL:Int\t\t\t= -1\n\tConst COMPARE_RESPONSE_WRONG_LENGTH:Int\t\t\t= -2\n\t\n\t' Other:\n\tConst AUTO:= UTIL_AUTO\n\t\n\t' Global variable(s):\n\t\n\t' For internal and extern use. That being said, please do not modify this value.\n\tGlobal NIL:T\n\t\n\t' Functions:\n\t\n\t' This command gives the user the type-code of 'T'.\n\tFunction Type:TypeCode()\n\t\t' Return the type code of 'NIL'.\n\t\tReturn TypeOf(NIL)\n\tEnd\n\t\n\t' This command specifies if 'T' is an object.\n\tFunction IsObject:Bool()\n\t\tReturn TypeIsObject(NIL)\n\tEnd\n\t\n\t' This command wraps the standard 'BoolToString' conversion command.\n\tFunction AsString:String(Input:Bool)\n\t\tReturn BoolToString(Input)\n\tEnd\n\t\n\t' This command reads a string from a standard 'Stream' object.\n\tFunction AsString:String(S:Stream, Length:Long=AUTO, Encoding:String=\"utf8\")\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = S.Length()\n\t\tEndif\n\t\t\n\t\tReturn S.ReadString(Length, Encoding)\n\tEnd\n\t\n\t' By default, this command will add the 'Offset' argument to the processed version of the 'Length' argument.\n\t' To disable this, set 'ApplyOffsetToLength' to 'False'.\n\tFunction AsString:String(Input:T[], Offset:ULong=0, Length:Long=AUTO, AddSpaces:Bool=True, ApplyOffsetToLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal Output:String = LeftBracket\n\t\t\n\t\t' If no length was specified, use the array's length:\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Input.Length()\n\t\tEndif\n\t\t\n\t\tLocal VirtualLength:ULong\n\t\t\n\t\tIf (ApplyOffsetToLength) Then\n\t\t\tVirtualLength = Length+Offset\n\t\tElse\n\t\t\tVirtualLength = Length\n\t\tEndif\n\t\t\n\t\tFor Local Index:= Offset Until VirtualLength\n\t\t\tOutput += String(Input[Index])\n\t\t\t\n\t\t\tIf (Index+1 < VirtualLength) Then\n\t\t\t\tIf (AddSpaces) Then\n\t\t\t\t\tOutput += (Comma + Space) ' \", \"\n\t\t\t\tElse\n\t\t\t\t\tOutput += Comma\n\t\t\t\tEndif\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\tReturn Output + RightBracket\n\tEnd\n\t\n\tFunction CopyStringToArray:T[](Input:String, Output:T[], Offset:ULong=0, Length:Long=AUTO)\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Min(Input.Length(), Output.Length())\n\t\tEndif\n\t\t\n\t\tFor Local I:= Offset Until Length\n\t\t\tOutput[I] = Input[I]\n\t\tNext\n\t\t\n\t\t' Just for the sake of convenience, return the 'Output' array.\n\t\tReturn Output\n\tEnd\n\t\n\tFunction IndexOfList:T(L:List, Index:ULong=0)\n\t\t' Local variable(s):\n\t\tLocal Data:list.Node = L.FirstNode()\n\t\t\t\t\n\t\tFor Local I:= 0 Until Index\n\t\t\tData = Data.NextNode()\n\t\t\t\n\t\t\t' Not my favorite method, but it works:\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn NIL\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the value of the assessed node.\n\t\tReturn Data.Value()\n\tEnd\n\t\n\tFunction Zero:T[](Input:T[])\n\t\tReturn Nil(Input)\n\tEnd\n\t\n\tFunction Nil:T[](Input:T[])\n\t\tFor Local Index:= 0 Until Input.Length()\n\t\t\tInput[Index] = NIL\n\t\tNext\n\t\t\n\t\tReturn Input\n\tEnd\n\t\n\tFunction SMod:T(Input:T, Denom:T)\n\t\tReturn (Input Mod (Denom*Sgn(Input)))\n\tEnd\n\t\n\tFunction PrintArray:Void(Input:T[])\n\t\tPrint(AsString(Input))\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction OutputArray:Void(Input:T[])\n\t\tPrintArray(Input)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction OutputArray:Void(Input:T[], S:Stream, WriteLength:Bool=False)\n\t\tWrite(S, Input, WriteLength)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod ReadArray:Void(Input:T[], S:Stream, Size:Long=AUTO)\n\t\tRead(S, Input, Size)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\t\tNOTES:\n\t\t\t* In the event of an error, an empty array will be produced.\n\t\t\t\n\t\t\t* The 'CopyArray' command's 'FitSource' argument should only be enabled with the\n\t\t\tknowledge that the original destination may have been discarded.\n\t\t\t\n\t\t\tYour code must reflect this by disregarding the original array,\n\t\t\tand simply assigning the old array to the retrun value.\n\t\t\t\n\t\t\tEXAMPLE:\n\t\t\t\t' Local variable(s):\n\t\t\t\tLocal A:T[10], A2:T[3]\n\t\t\t\t\n\t\t\t\t' This will likely produce a new 'T' array, based on the area-delta.\n\t\t\t\tA2 = CopyArray(A, A2, True)\n\t#End\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], FitSource:Bool)\n\t\tReturn CopyArray(Source, Destination, 0, 0, AUTO, AUTO, FitSource)\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], Source_Offset:ULong=0, Destination_Offset:ULong=0, Source_Length:Long=AUTO, Destination_Length:Long=AUTO, FitSource:Bool=False)\n\t\tIf (Source_Length = AUTO) Then\n\t\t\tSource_Length = Source.Length()\n\t\tEndif\n\t\t\n\t\tIf (Destination_Length = AUTO) Then\n\t\t\tDestination_Length = Destination.Length()\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\t\n\t\t' These two are used as caches for the real lengths of the arrays:\n\t\tLocal Destination_RealLength:= Destination.Length()\n\t\tLocal Source_RealLength:= Source.Length()\n\t\t\n\t\t' Calculate the source and destination areas:\n\t\tLocal Source_Area:Long = (Source_Length-Source_Offset)\n\t\t\n\t\t' Make sure we have a source to work with:\n\t\tIf (Source_Area <= 0) Then\n\t\t\t' The source-area is too small for use, return an empty array.\n\t\t\tReturn []\n\t\tEndif\n\t\t\n\t\tLocal Destination_Area:Long = (Destination_Length-Destination_Offset)\n\t\t\n\t\t' If we're not going to fit the source, check if the destination-area is big enough:\n\t\tIf (Not FitSource) Then\n\t\t\tIf (Destination_Area <= 0) Then\n\t\t\t\t' The destination-area is too small for use, return an empty array.\n\t\t\t\tReturn []\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tLocal Operation_Area:Long\n\t\t\n\t\tIf (FitSource And Destination_Area < Source_Area) Then\n\t\t\tLocal AreaDelta:Long = (Source_Area-Destination_Area)\n\t\t\tLocal NewArea:Long = (Destination_RealLength+AreaDelta)\n\t\t\t\n\t\t\tIf (NewArea > Destination_RealLength) Then\n\t\t\t\tDestination = Destination.Resize(NewArea)\n\t\t\tElse\n\t\t\t\tDestination = Destination.Resize(Destination_Length+AreaDelta)\n\t\t\tEndif\n\t\t\t\n\t\t\tDestination_Area = Source_Area\n\t\t\tOperation_Area = Destination_Area\n\t\tElse\n\t\t\tOperation_Area = Min(Source_Area, Destination_Area)\n\t\tEndif\n\t\t\n\t\t' Copy the contents of the source-array into the destination-array:\n\t\tFor Local Index:= 0 Until Operation_Area\n\t\t\tDestination[Index+Destination_Offset] = Source[Index+Source_Offset]\n\t\tNext\n\t\t\n\t\t' Return the destination-array.\n\t\tReturn Destination\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[])\n\t\tReturn CloneArray(Source)\n\tEnd\n\t\n\tFunction CloneArray:T[](Source:T[])\n\t\tReturn CopyArray(Source, New T[Source.Length()])\n\tEnd\n\t\n\t' This command returns a positive number upon an error,\n\t' otherwise a 'response code' will be given (See the \"Contant variable(s)\" section for details).\n\tFunction Compare:Int(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal A1_Length:= A1.Length\n\t\tLocal A2_Length:= A2.Length\n\t\t\n\t\t' Check for errors:\n\t\tIf (CheckLength) Then\n\t\t\t' Make sure they're both the same length.\n\t\t\tIf (A1_Length <> A2_Length) Then\n\t\t\t\tReturn COMPARE_RESPONSE_WRONG_LENGTH\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tFor Local I:= 0 Until Min(A1_Length, A2_Length)\n\t\t\tIf (A1[I] <> A2[I]) Then\n\t\t\t\t' Not the best of escape methods, but it works.\n\t\t\t\tReturn I\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the default response.\n\t\tReturn COMPARE_RESPONSE_IDENTICAL\n\tEnd\n\t\n\t' This function returns positive if both arrays are identical.\n\tFunction SimpleCompare:Bool(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\tReturn (Compare(A1, A2, CheckLength) = COMPARE_RESPONSE_IDENTICAL)\n\tEnd\n\t\n\tFunction Read:T(S:Stream)\n\t\tReturn Read(S, NIL)\n\tEnd\n\t\n\tFunction Read:T[](S:Stream, DataArray:T[], Size:Long=AUTO)\n\t\tIf (Size = AUTO) Then\n\t\t\tSize = S.ReadInt() ' S.ReadLong()\n\t\tEndif\n\t\t\n\t\tIf (Size > 0) Then\n\t\t\tIf (DataArray.Length() = 0) Then\n\t\t\t\tDataArray = New T[Size]\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\tLocal DLength:= Min(DataArray.Length(), Size)\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tDataArray[Index] = Read(S, NIL)\n\t\tNext\n\t\t\n\t\tReturn DataArray\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, DataArray:T[], WriteLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal DLength:= DataArray.Length()\n\t\t\n\t\tIf (WriteLength) Then\n\t\t\tS.WriteInt(DLength) ' S.WriteLong(DLength)\n\t\tEndif\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tWrite(S, DataArray[Index])\n\t\tNext\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:Long(S:Stream, Identifier:Long, Size:Byte=4)\n\t\t\tIf (Size > 1) Then\n\t\t\t\tIf (Size < 4) Then\n\t\t\t\t\tReturn S.ReadShort()\n\t\t\t\tElse\n\t\t\t\t\t' Good enough for now:\n\t\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\t\tS.ReadInt()\n\t\t\t\t\tEndif\n\t\t\t\t\t\n\t\t\t\t\tReturn S.ReadInt()\n\t\t\t\t\t'Return S.ReadLong()\n\t\t\t\tEndif\n\t\t#If MONKEYLANG_EXTENSION_TYPE_BYTE\n\t\t\tElse\n\t\t#Else\n\t\t\tElseif (Size > 0) Then\n\t\t#End\n\t\t\t\tReturn S.ReadByte()\n\t\t\tEndif\n\t\t\n\t\t' Return the default response.\n\t\tReturn 0\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:Long, Size:Byte=4)\n\t\tSize = Byte(IntSize(Size)) ' ApplyByteBounds(IntSize(Size))\n\t\t\n\t\t\tIf (Size > 1) Then\n\t\t\t\tIf (Size < 4) Then\n\t\t\t\t\tS.WriteShort(Data)\n\t\t\t\tElse\n\t\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\t\tS.WriteInt(0)\n\t\t\t\t\tEndif\n\t\t\t\t\t\n\t\t\t\t\tS.WriteInt(Data)\n\t\t\t\t\t'S.WriteLong(Data)\n\t\t\t\tEndif\n\t\t#If MONKEYLANG_EXTENSION_TYPE_BYTE\n\t\t\tElse\n\t\t#Else\n\t\t\tElseif (Size > 0) Then\n\t\t#End\n\t\t\t\tS.WriteByte(Data)\n\t\t\tEndif\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\tFunction Read:Bool(S:Stream, Identifier:Bool)\n\t\tReturn Read(S, Long(Identifier), 1)\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, B:Bool)\n\t\tWrite(S, Long(B), 1)\n\t\t\n\t\tReturn\n\tEnd\n\t#End\n\t\n\t'Function Read:Double(S:Stream, Identifier:Double)\n\tFunction Read:Float(S:Stream, Identifier:Float)\n\t\tReturn S.ReadFloat() ' S.ReadDouble()\n\tEnd\n\t\n\t'Function Write:Void(S:Stream, Data:Double)\n\tFunction Write:Void(S:Stream, Data:Float)\n\t\tS.WriteFloat(Data) ' S.ReadDouble(Data)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:String(S:Stream, Data:String, Encoding:String=\"utf8\", Size:Long=AUTO)\n\t\t' Check if the size was manually specified:\n\t\tIf (Size = AUTO) Then\n\t\t\t' Read the string's length from the input-stream.\n\t\t\tSize = S.ReadInt() ' S.ReadLong()\n\t\tEndif\n\t\t\n\t\t' Read the desired string from the input-stream, then return it.\n\t\tReturn S.ReadString(Size, Encoding)\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:String, Encoding:String=\"utf8\", WriteSize:Bool=True)\n\t\t' Check if we're writing the size of the input-string.\n\t\tIf (WriteSize) Then\n\t\t\t' Write the length of the input-string to the output-stream.\n\t\t\tS.WriteInt(Data.Length()) ' S.WriteLong(Data.Length())\n\t\tEndif\n\t\t\n\t\t' Write the input-string to the output-stream.\n\t\tS.WriteString(Data, Encoding)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#If UTIL_SUPPORT_IOELEMENTS\n\t\tFunction Read:Void(S:Stream, Data:InputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Load(S)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:OutputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Save(S)\n\t\tEnd\n\t#End\n\t\n\t' The following commands were created to solve auto-conversion conflicts with the standard \"box\" classes:\n\t#If Not MONKEYLANG_EXPLICIT_BOXES\n\t\tFunction Read:Long(S:Stream, Identifier:IntObject, Size:Byte=4)\n\t\t\tReturn Read(S, Identifier.ToInt(), Size)\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:IntObject, Size:Byte=4)\n\t\t\tWrite(S, Data.ToInt(), Size)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\t'Function Read:Double(S:Stream, Identifier:FloatObject)\n\t\tFunction Read:Float(S:Stream, Identifier:FloatObject)\n\t\t\tReturn Read(S, Identifier.ToFloat())\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:FloatObject)\n\t\t\tWrite(S, Data.ToFloat())\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t#End\n\t\n\t' Constructor(s):\n\t\n\t' DO NOT CREATE NEW INSTANCES OF THIS CLASS.\n\tMethod New()\n\t\tDebugError(\"This class should not be used in this was.\")\n\tEnd\nEnd","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"4b04a367aa10e44db658b16054db22c3863a6bcb","subject":"optimized some Vector2D instantiation away","message":"optimized some Vector2D instantiation away\n","repos":"michaelcontento\/bono,michaelcontento\/bono,michaelcontento\/bono","old_file":"src\/fx\/actions\/actionmoveto.monkey","new_file":"src\/fx\/actions\/actionmoveto.monkey","new_contents":"Strict\n\nPrivate\n\nImport bono\n\nPublic\n\nClass ActionMoveTo Extends BaseAction\n Private\n\n Field obj:Positionable\n Field endPos:Vector2D\n Field startPos := New Vector2D()\n Field distance := New Vector2D()\n Field currentPos := New Vector2D()\n\n Public\n\n Method New()\n Throw New InvalidConstructorException(\"use New(Positionable, Vector2D)\")\n End\n\n Method New(obj:Positionable, pos:Vector2D)\n Self.obj = obj\n Self.endPos = pos\n End\n\n Method OnActionStart:Void()\n Super.OnActionStart()\n\n startPos.Set(obj.GetPosition())\n distance.Set(endPos).Sub(startPos)\n End\n\n Method OnActionUpdate:Void(progress:Float)\n currentPos.Set(distance).Mul(progress).Add(startPos)\n obj.GetPosition().Set(currentPos)\n End\nEnd\n","old_contents":"Strict\n\nPrivate\n\nImport bono\n\nPublic\n\nClass ActionMoveTo Extends BaseAction\n Private\n\n Field endPos:Vector2D\n Field startPos:Vector2D\n Field distance:Vector2D\n Field obj:Positionable\n\n Public\n\n Method New()\n Throw New InvalidConstructorException(\"use New(Positionable, Vector2D)\")\n End\n\n Method New(obj:Positionable, pos:Vector2D)\n Self.obj = obj\n Self.endPos = pos\n End\n\n Method OnActionStart:Void()\n Super.OnActionStart()\n\n startPos = obj.GetPosition().Copy()\n distance = endPos.Copy().Sub(startPos)\n End\n\n Method OnActionUpdate:Void(progress:Float)\n obj.GetPosition().Set(startPos.Copy().Add(distance.Copy().Mul(progress)))\n End\nEnd\n","returncode":0,"stderr":"","license":"apache-2.0","lang":"Monkey"} {"commit":"2f55ca37548979dd7a098a288b25816a5159359a","subject":"Fixes after refactoring","message":"Fixes after refactoring\n","repos":"devolonter\/flixel-monkey,devolonter\/flixel-monkey,devolonter\/flixel-monkey,devolonter\/flixel-monkey","old_file":"flxg.monkey","new_file":"flxg.monkey","new_contents":"Strict\n\nImport mojo\n\nImport flxextern\nImport flxbasic\nImport flxgame\nImport flxcamera\nImport flxobject\nImport flxsound\nImport flxmusic\nImport flxu\n\nImport system.input.accel\nImport system.input.joystick\nImport system.input.keyboard\nImport system.input.mouse\nImport system.input.touch\nImport system.flxresourcesmanager\nImport system.flxquadtree\nImport system.flxreplay\n\nImport plugin.timermanager\nImport plugin.debugpathdisplay\n\nAlias AccelInput = accel.Accel\nAlias MouseInput = mouse.Mouse\nAlias TouchInput = touch.Touch\nAlias JoystickInput = joystick.Joystick\n\nClass FlxG\n\n\tConst LIBRARY_NAME:String = \"Monkey Flixel\"\n\t\n\tConst LIBRARY_MAJOR_VERSION:Int = 1\n\t\n\tConst LIBRARY_MINOR_VERSION:Int = 0\n\t\n\tConst DATA_PREFIX:String = \"flx_\"\n\t\n\tConst RED:Int = $FFFF0012\n\t\n\tConst GREEN:Int = $FF00F225\n\t\n\tConst BLUE:Int = $FF0090E9\n\t\n\tConst PINK:Int = $FFF01EFF\n\t\n\tConst WHITE:Int = $FFFFFFFF\n\t\n\tConst BLACK:Int = $FF000000\n\t\n\tGlobal DeviceWidth:Int\n\t\n\tGlobal DeviceHeight:Int\n\t\n\tGlobal Width:Int\n\t\n\tGlobal Height:Int\n\t\n\tGlobal WorldBounds:FlxRect\n\t\n\tGlobal WorldDivisions:Int\n\t\t\t\n\tGlobal Cameras:Stack\n\t\n\tGlobal Camera:FlxCamera\n\t\n\tGlobal Plugins:Stack\n\t\n\tGlobal VolumeHandler:FlxVolumeChangeListener\n\t\n\tGlobal Elapsed:Float\n\t\n\tGlobal TimeScale:Float\n\t\n\tGlobal VisualDebug:Bool\n\n\tGlobal Mobile:Bool\n\t\n\tGlobal GlobalSeed:Int\n\t\n\tGlobal Scores:Stack\t\n\t\n\tGlobal Score:Int\n\t\n\tGlobal Accel:AccelInput\t\n\t\n\tGlobal Keys:Keyboard\n\t\n\tGlobal Mouse:MouseInput\n\t\n\tGlobal Music:FlxMusic\n\t\n\tGlobal Sounds:FlxGroup\n\t\n\tGlobal Mute:Bool\n\t\t\n\tGlobal Framerate:Int\t\n\t\n\tGlobal _DeviceScaleFactorX:Float = 1\t\n\t\n\tGlobal _DeviceScaleFactorY:Float = 1\n\t\n\tGlobal _BgColor:FlxColor = FlxColor.ARGB(FlxG.BLACK)\t\t\n\t\n\tGlobal _Game:FlxGame\n\t\n\tGlobal _Volume:Float\n\t\n\tGlobal _Cache:FlxResourcesManager\n\t\n\tGlobal _LastDrawingColor:Int\n\t\n\tGlobal _LastDrawingAlpha:Float\n\t\n\tGlobal _LastDrawingBlend:Int\n\t\n\tGlobal _CurrentCamera:FlxCamera\n\t\n\tGlobal _CurrentCameraID:Int\n\nPrivate\n\tConst _JOY_UNITS_COUNT:Int = 4\n\t\n\tConst _TOUCH_COUNT:Int = 32\n\t\n\tGlobal _Joystick:JoystickInput[_JOY_UNITS_COUNT]\n\t\n\tGlobal _Touch:TouchInput[_TOUCH_COUNT]\n\t\n\tGlobal _CollideListener:FlxCollideProcessListener = New FlxCollideProcessListener()\n\t\n\nPublic\n\tFunction GetLibraryName:String()\n\t\tReturn FlxG.LIBRARY_NAME + \" v\" + FlxG.LIBRARY_MAJOR_VERSION + \".\" + FlxG.LIBRARY_MINOR_VERSION\n\tEnd Function\n\t\n\tFunction Log:Void(data:String)\n\t\tPrint data\n\t\t'TODO\n\tEnd Function\n\t\n\tFunction Random:Float()\n\t\tFlxG.GlobalSeed = (FlxG.GlobalSeed * 1664525 + 1013904223)|0\n\t\tReturn FlxU.Srand(FlxG.GlobalSeed)\n\tEnd Function\n\t\n\tFunction GetRandom:FlxBasic(objects:FlxBasic[], startIndex:Int = 0, length:Int = 0)\n\t\tIf (objects.Length() > 0) Then\n\t\t\tLocal l:Int = length\n\t\t\t\n\t\t\tIf (l = 0 Or l > objects.Length() - startIndex) Then\n\t\t\t\tl = objects.Length() - startIndex\n\t\t\tEnd if\n\t\t\t\n\t\t\tIf (l > 0) Return objects[startIndex + int(FlxG.Random()*l)]\t\n\t\tEnd If\n\t\t\n\t\tReturn Null\n\tEnd Function\n\t\n\t#Rem\n\tFunction GetRandom:Object(objects:Object[], startIndex:Int = 0, length:Int = 0)\n\t\tGetRandom is not currently supported in Monkey. Use FlxArray.GetSafeRandom method\n\tEnd Function\n\t#End\n\t\n\tFunction LoadReplay:Void(data:String, state:FlxState = Null, cancelKeys:Int[] = [], timeout:Float = 0, callback:FlxReplayListener = Null)\n\t\t_Game._replay.Load(data)\n\t\tIf (state = Null) Then\n\t\t\tFlxG.ResetGame()\n\t\tElse\n\t\t\tFlxG.SwitchState(state)\n\t\tEnd If\n\t\t\n\t\t_Game._replayCancelKeys = cancelKeys\n\t\t_Game._replayTimer = timeout * 1000\n\t\t_Game._replayCallback = callback\n\t\t_Game._replayRequested = True\n\tEnd Function\n\t\n\tFunction ReloadReplay:Void(standardMode:Bool = True)\n\t\tIf (standardMode) Then\n\t\t\tFlxG.ResetGame()\n\t\tElse\n\t\t\tFlxG.ResetState()\n\t\tEnd If\n\t\t\n\t\tIf (_Game._replay.frameCount > 0) _Game._replayRequested = True\n\tEnd Function\t\n\t\n\tFunction StopReplay:Void()\n\t\t_Game._replaying = False\n\t\t\n\t\tIf (_Game._debugger <> Null) Then\n\t\t\t'TODO\n\t\tEnd If\n\t\t\n\t\tResetInput()\n\tEnd Function\n\t\n\tFunction RecordReplay:Void(standardMode:Bool = True)\n\t\tIf (standardMode) Then\n\t\t\tFlxG.ResetGame()\n\t\tElse\n\t\t\tFlxG.ResetState()\n\t\tEnd If\n\t\t\n\t\t_Game._recordingRequested = True\n\tEnd Function\n\t\n\tFunction StopRecording:String()\n\t\t_Game._recording = False\n\t\t\n\t\tIf (_Game._debugger <> Null) Then\n\t\t\t'TODO\n\t\tEnd if\n\t\t\n\t\tReturn _Game._replay.Save()\n\tEnd Function\n\t\n\tFunction ResetState:Void()\n\t\t_Game._requestedState = FlxState(_Game._state.GetClass().CreateInstance())\n\tEnd Function\n\t\n\tFunction ResetGame:Void()\n\t\t_Game._requestedReset = True\n\tEnd Function\n\t\n\tFunction ResetInput:Void()\n\t\t#If TARGET = \"html5\" Or TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tAccel.Reset()\n\t\t#End\t\t\t\t\n\t\t\n\t\t#If TARGET = \"xna\" Or TARGET = \"glfw\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tFor Local i:Int = 0 Until _JOY_UNITS_COUNT\n\t\t\t\t\t_Joystick[i].Reset()\n\t\t\t\tNext\n\t\t\tEnd If\n\t\t#End\n\t\t\n\t\t#If TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t_Touch[i].Reset()\n\t\t\tNext\n\t\t\t\n\t\t#ElseIf TARGET = \"html5\" Or TARGET = \"flash\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Reset()\n\t\t\tEnd If\n\t\t\t\t\n\t\t\t_Touch[0].Reset()\n\t\t\n\t\t#ElseIf TARGET = \"xna\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Reset()\n\t\t\t\t_Touch[0].Reset()\n\t\t\tElse\n\t\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t\t_Touch[i].Reset()\n\t\t\t\tNext\n\t\t\tEnd If\t\t\t\n\t\t\t\n\t\t#Else\n\t\t\tKeys.Reset()\n\t\t\t_Touch[0].Reset()\t\t\t\n\t\t#End\n\t\t\n\t\t#If TARGET = \"android\"\n\t\t\tKeys.Reset()\n\t\t#End\n\t\t\n\t\tMouse.Reset()\n\tEnd Function\n\t\n\tFunction PlayMusic:Void(music:String, volume:Float = 1.0)\n\t\tIf (FlxG.Music = Null) Then\n\t\t\tFlxG.Music = New FlxMusic()\n\t\t\t\n\t\tElseIf (FlxG.Music.active) Then\n\t\t\tFlxG.Music.Stop()\n\t\tEnd If\n\t\t\n\t\tFlxG.Music.Load(music, True)\n\t\tFlxG.Music.Volume = volume\n\t\tFlxG.Music.survive = True\n\t\t\n\t\tFlxG.Music.Play()\n\tEnd Function\n\t\n\tFunction LoadSound:FlxSound(sound:String, volume:Float = 1.0, looped:Bool = False, autoDestroy:Bool = False, autoPlay:Bool = False)\n\t\tLocal s:FlxSound = FlxSound(Sounds.Recycle(FlxSound.ClassObject))\n\t\t\n\t\ts.Load(sound, looped, autoDestroy)\n\t\ts.Volume = volume\t\t\n\t\tIf (autoPlay) s.Play()\n\t\t\t\t\n\t\tReturn s\n\tEnd Function\n\t\n\tFunction Play:FlxSound(sound:String, volume:Float = 1.0, looped:Bool = False, autoDestroy:Bool = True)\n\t\tReturn FlxG.LoadSound(sound, volume, looped, autoDestroy, True)\n\tEnd Function\n\t\n\tFunction Volume:Float()\n\t\tReturn _Volume\n\tEnd Function\n\t\n\tFunction Volume:Void(volume:Float)\n\t\t_Volume = volume\n\t\t\n\t\tIf (_Volume < 0) Then\n\t\t\t_Volume = 0\n\t\tElseIf (_Volume > 1) Then\n\t\t\t_Volume = 1\n\t\tEnd If\n\t\t\n\t\tIf (VolumeHandler <> Null) Then\n\t\t\tIf (FlxG.Mute) Then\n\t\t\t\tVolumeHandler.OnVolumeChange(0)\n\t\t\tElse\n\t\t\t\tVolumeHandler.OnVolumeChange(_Volume)\n\t\t\tEnd If\n\t\tEnd If\n\tEnd Function\n\t\n\tFunction DestroySounds:Void(forceDestroy:Bool = False)\n\t\tIf (Music <> Null And (forceDestroy Or Not Music.survive)) Then\n\t\t\tMusic.Destroy()\n\t\t\tMusic = Null\n\t\tEnd If\n\t\t\n\t\tLocal sound:FlxSound\n\t\t\n\t\tFor Local basic:FlxBasic = EachIn Sounds\n\t\t\tsound = FlxSound(basic)\n\t\t\t\n\t\t\tIf (sound <> Null And (forceDestroy Or Not sound.survive)) Then\n\t\t\t\tsound.Destroy()\n\t\t\tEnd If\n\t\tNext\n\tEnd Function\n\t\n\tFunction UpdateSounds:Void()\n\t\tIf (Music <> Null And Music.active) Then\n\t\t\tMusic.Update()\n\t\tEnd If\n\t\t\n\t\tIf (Sounds <> Null And Sounds.active) Then\n\t\t\tSounds.Update()\n\t\tEnd If\n\tEnd Function\n\t\n\tFunction PauseSounds:Void()\n\t\tIf (Music <> Null And Music.exists And Music.active) Then\n\t\t\tMusic.Pause()\n\t\tEnd If\n\t\t\n\t\tLocal sound:FlxSound\n\t\t\n\t\tFor Local basic:FlxBasic = EachIn Sounds\n\t\t\tsound = FlxSound(basic)\n\t\t\t\n\t\t\tIf (sound <> Null And sound.exists And sound.active) Then\n\t\t\t\tsound.Pause()\n\t\t\tEnd If\n\t\tNext\n\tEnd Function\n\t\n\tFunction ResumeSounds:Void()\n\t\tIf (Music <> Null And Music.exists) Then\n\t\t\tMusic.Play()\n\t\tEnd If\n\t\t\n\t\tLocal sound:FlxSound\n\t\t\n\t\tFor Local basic:FlxBasic = EachIn Sounds\n\t\t\tsound = FlxSound(basic)\n\t\t\t\n\t\t\tIf (sound <> Null And sound.exists) Then\n\t\t\t\tsound.Resume()\n\t\t\tEnd If\n\t\tNext\n\tEnd Function\n\t\n\tFunction CheckBitmapCache:Bool(key:String)\n\t\tReturn _Cache.CheckResource(key)\n\tEnd Function\n\t\n\tFunction AddBitmap:Image(graphic:String, graphicLoader:FlxResourceLoader, unique:Bool = False, key:String = \"\")\n\t\tIf (key.Length() = 0) Then\n\t\t\tkey = graphic\n\t\t\t\n\t\t\tIf (unique And CheckBitmapCache(key)) Then\n\t\t\t\tLocal inc:Int = 0\n\t\t\t\tLocal ukey:String\n\t\t\t\t\n\t\t\t\tRepeat\n\t\t\t\t\tukey = key + inc\n\t\t\t\t\tinc += 1\n\t\t\t\tUntil(CheckBitmapCache(ukey))\n\t\t\t\t\n\t\t\t\tkey = ukey\n\t\t\tEnd If\n\t\tEnd If\n\t\t\n\t\tReturn _Cache.GetResource(key, graphicLoader)\n\tEnd Function\n\t\n\tFunction ClearBitmapCache:Void()\n\t\tIf (_Cache = Null) _Cache = New FlxResourcesManager()\n\t\t\n\t\tFor Local image:Image = EachIn _Cache.Resources.Values()\n\t\t\tIf (image <> Null) image.Discard()\n\t\tNext\n\t\t\n\t\t_Cache.Clear()\n\tEnd Function\n\t\n\tFunction State:FlxState()\n\t\tReturn _Game._state\n\tEnd Function\n\t\n\tFunction SwitchState:Void(state:FlxState)\n\t\tFlxG._Game._requestedState = state\n\tEnd Function\n\t\n\tFunction AddCamera:FlxCamera(newCamera:FlxCamera)\n\t\tFlxG.Cameras.Push(newCamera)\n\t\tReturn newCamera\n\tEnd Function\n\t\n\tFunction RemoveCamera:Void(camera:FlxCamera, destroy:Bool = True)\n\t\tFlxG.Cameras.RemoveEach(camera)\n\t\tIf (destroy) camera.Destroy()\n\tEnd Function\n\t\n\tFunction ResetCameras:Void(newCamera:FlxCamera = Null)\t\n\t\tLocal cam:FlxCamera\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = FlxG.Cameras.Get(i)\n\t\t\tcam.Destroy()\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG.Cameras.Clear()\n\t\tFlxG.Camera = Null\n\t\t\n\t\tIf (newCamera = Null) newCamera = New FlxCamera(0, 0, FlxG.Width, FlxG.Height)\n\t\t\n\t\tFlxG.Camera = FlxG.AddCamera(newCamera)\t\n\tEnd Function\n\t\n\tFunction Flash:Void(color:Int = FlxG.WHITE, duration:Float = 1, onComplete:FlxCameraFlashListener = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).Flash(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Fade:Void(color:Int = FlxG.BLACK, duration:Float = 1, onComplete:FlxCameraFadeListener = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).Fade(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Shake:Void(intensity:Float = 0.05, duration:Float = 0.5, onComplete:FlxCameraShakeListener = Null, force:Bool = True, direction:Int = FlxCamera.SHAKE_BOTH_AXES)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).Shake(intensity, duration, onComplete, force, direction)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\t\t\n\t\n\tFunction BgColor:Int()\n\t\tIf (FlxG.Camera = Null Or Not FlxG.Camera.alive) Return FlxG._BgColor.argb\t\n\t\tReturn FlxG.Camera.BgColor\n\tEnd Function\n\t\n\tFunction BgColor:Void(color:Int)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).BgColor = color\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG._BgColor.SetARGB(color)\n\tEnd Function\n\t\n\tFunction Overlap:Bool(objectOrGroup1:FlxBasic = Null, objectOrGroup2:FlxBasic, notifyCallback:FlxOverlapNotifyListener = Null, processCallback:FlxOverlapProcessListener = Null)\n\t\tIf (objectOrGroup1 = Null) objectOrGroup1 = FlxG.State()\n\t\tIf (objectOrGroup2 = objectOrGroup1) objectOrGroup2 = Null\n\t\t\n\t\tFlxQuadTree.Divisions = FlxG.WorldDivisions\n\t\t\n\t\tLocal quadTree:FlxQuadTree = New FlxQuadTree(FlxG.WorldBounds.x, FlxG.WorldBounds.y, FlxG.WorldBounds.width, FlxG.WorldBounds.height)\n\t\tquadTree.Load(objectOrGroup1, objectOrGroup2, notifyCallback, processCallback)\n\t\t\n\t\tLocal result:Bool = quadTree.Execute()\n\t\tquadTree.Destroy()\n\t\t\n\t\tReturn result\n\tEnd Function\n\t\n\tFunction Collide:Bool(objectOrGroup1:FlxBasic = Null, objectOrGroup2:FlxBasic = Null, notifyCallback:FlxOverlapNotifyListener = Null)\n\t\tReturn\tOverlap(objectOrGroup1, objectOrGroup2, notifyCallback, _CollideListener)\n\tEnd Function\n\t\n\tFunction AddPlugin:FlxBasic(plugin:FlxBasic)\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tIf (pluginList.Get(i).ToString() = plugin.ToString()) Then\n\t\t\t\tReturn plugin\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tpluginList.Push(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction GetPlugin:FlxBasic(creator:FlxClass)\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal plugin:FlxBasic\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (creator.InstanceOf(plugin)) Return plugin\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tReturn Null\t\n\tEnd Function\n\t\n\tFunction RemovePlugin:FlxBasic(plugin:FlxBasic)\n\t\tPlugins.RemoveEach(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction RemovePluginType:Bool(creator:FlxClass)\n\t\tLocal results:Bool = False\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = pluginList.Length() - 1\t\n\t\t\n\t\tWhile(i >= 0)\n\t\t\tIf (creator.InstanceOf(pluginList.Get(i))) Then\n\t\t\t\tpluginList.Remove(i)\n\t\t\t\tresults = True\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti-=1\n\t\tWend\n\t\n\t\tReturn results\n\tEnd Function\n\t\n\tFunction Init:Void(game:FlxGame, width:Int, height:Int, zoom:Float)\n\t\tFlxG._Game = game\n\t\tFlxG.Width = width\n\t\tFlxG.Height = height\n\t\t\n\t\tFlxG.Mute = False\n\t\tFlxG._Volume = .5\n\t\tFlxG.Sounds = New FlxGroup()\n\t\tFlxG.VolumeHandler = Null\n\t\t\n\t\tFlxG.ClearBitmapCache()\t\t\n\t\t\n\t\tFlxCamera.DefaultZoom = zoom\n\t\tFlxG.Cameras = New Stack()\t\t\n\t\t\n\t\tPlugins = New Stack\n\t\tAddPlugin(New DebugPathDisplay())\n\t\tAddPlugin(New TimerManager())\n\t\t\n\t\tFlxG.Accel = New AccelInput()\n\t\tFlxG.Keys = New Keyboard()\n\t\tFlxG.Mouse = New MouseInput()\n\t\t\n\t\tFor Local i:Int = 0 Until _JOY_UNITS_COUNT\n\t\t\t_Joystick[i] = New JoystickInput(i)\n\t\tNext\n\t\t\n\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t_Touch[i] = New TouchInput(i)\n\t\tNext\n\t\t\n\t\tFlxG.Mobile = IsMobile()\n\t\t\n\t\tFlxG.Scores = New Stack()\t\t\n\tEnd Function\n\t\n\tFunction Reset:Void()\n\t\tFlxG.ClearBitmapCache()\n\t\tFlxG.ResetInput()\n\t\tFlxG.DestroySounds(True)\n\t\tFlxG.Scores.Clear()\n\t\tFlxG.Score = 0\t\n\t\tFlxG.TimeScale = 1\n\t\tFlxG.Elapsed = 0 \n\t\tFlxG.GlobalSeed = Rnd(1, 10000000)\n\t\tFlxG.WorldBounds = New FlxRect(-10, -10, FlxG.Width + 20, FlxG.Height + 20)\n\t\tFlxG.WorldDivisions = 6\n\t\tLocal debugPathDisplay:DebugPathDisplay = DebugPathDisplay(FlxG.GetPlugin(DebugPathDisplay.ClassObject))\n\t\tIf (debugPathDisplay <> Null) debugPathDisplay.Clear()\n\tEnd Function\n\t\n\tFunction UpdateInput:Void()\n\t\t#If TARGET = \"html5\" Or TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tAccel.Update(AccelX(), AccelY(), AccelZ())\n\t\t#End\t\t\n\t\t\n\t\t#If TARGET = \"xna\" Or TARGET = \"glfw\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tFor Local i:Int = 0 Until _JOY_UNITS_COUNT\n\t\t\t\t\t_Joystick[i].Update()\n\t\t\t\tNext\n\t\t\tEnd If\n\t\t#End\n\t\t\n\t\t#If TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t_Touch[i].Update(TouchX(i), TouchY(i))\n\t\t\t\t\n\t\t\t\tIf (i > 0 And Not _Touch[i].Used) Exit\n\t\t\tNext\n\t\t\t\n\t\t#ElseIf TARGET = \"html5\" Or TARGET = \"flash\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Update()\n\t\t\tEnd If\n\t\t\t\n\t\t\t_Touch[0].Update(TouchX(), TouchY())\n\t\t\t\n\t\t#ElseIf TARGET = \"xna\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Update()\n\t\t\t\t_Touch[0].Update(TouchX(), TouchY())\n\t\t\tElse\n\t\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t\t_Touch[i].Update(TouchX(i), TouchY(i))\n\t\t\t\t\t\n\t\t\t\t\tIf (i > 0 And Not _Touch[i].Used) Exit\n\t\t\t\tNext\n\t\t\tEnd If\n\t\t\t\t\t\n\t\t#Else\n\t\t\tKeys.Update()\t\t\t\t\n\t\t\t_Touch[0].Update(TouchX(), TouchY())\n\t\t#End\n\t\t\n\t\t#If TARGET = \"android\"\n\t\t\tKeys.Update()\n\t\t#End\n\t\t\n\t\tIf (Not _Game._debuggerUp Or Not _Game._debugger.hasMouse) Then\n\t\t\tMouse.Update(MouseX(), MouseY())\n\t\tEnd If\n\tEnd Function\n\t\n\tFunction UpdateCameras:Void()\n\t\tLocal cam:FlxCamera\n\t\tLocal cams:Stack = FlxG.Cameras\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = cams.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = cams.Get(i)\n\t\t\tIf (cam <> Null And cam.exists And cam.active) cam.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction UpdatePlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.active) plugin.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction DrawPlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.visible) plugin.Draw()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Joystick:JoystickInput(unit:Int = 0)\n\t\tReturn _Joystick[unit]\n\tEnd Function\n\t\n\tFunction Touch:TouchInput(index:Int = 0)\n\t\tReturn _Touch[index]\n\tEnd Function\n\t\n\tFunction JoystickCount:Int()\n\t\tReturn _JOY_UNITS_COUNT\n\tEnd Function\n\t\n\tFunction TouchCount:Int()\n\t\tReturn _TOUCH_COUNT\n\tEnd Function\n\nEnd Class\n\nPrivate\nClass FlxCollideProcessListener Implements FlxOverlapProcessListener\n\t\n\tMethod OnOverlapProcess:Bool(object1:FlxObject, object2:FlxObject)\n\t\tReturn FlxObject.Separate(object1, object2)\n\tEnd Method\n\nEnd Class","old_contents":"Strict\n\nImport mojo\n\nImport flxextern\nImport flxbasic\nImport flxgame\nImport flxcamera\nImport flxobject\nImport flxsound\nImport flxmusic\nImport flxu\n\nImport system.input.accel\nImport system.input.joystick\nImport system.input.keyboard\nImport system.input.mouse\nImport system.input.touch\nImport system.flxresourcesmanager\nImport system.flxquadtree\nImport system.flxreplay\n\nImport plugin.timermanager\nImport plugin.debugpathdisplay\n\nAlias AccelInput = accel.Accel\nAlias TouchInput = touch.Touch\nAlias JoystickInput = joystick.Joystick\n\nClass FlxG\n\n\tConst LIBRARY_NAME:String = \"Monkey Flixel\"\n\t\n\tConst LIBRARY_MAJOR_VERSION:Int = 1\n\t\n\tConst LIBRARY_MINOR_VERSION:Int = 0\n\t\n\tConst DATA_PREFIX:String = \"flx_\"\n\t\n\tConst RED:Int = $FFFF0012\n\t\n\tConst GREEN:Int = $FF00F225\n\t\n\tConst BLUE:Int = $FF0090E9\n\t\n\tConst PINK:Int = $FFF01EFF\n\t\n\tConst WHITE:Int = $FFFFFFFF\n\t\n\tConst BLACK:Int = $FF000000\n\t\n\tGlobal DeviceWidth:Int\n\t\n\tGlobal DeviceHeight:Int\n\t\n\tGlobal Width:Int\n\t\n\tGlobal Height:Int\n\t\n\tGlobal WorldBounds:FlxRect\n\t\n\tGlobal WorldDivisions:Int\n\t\t\t\n\tGlobal Cameras:Stack\n\t\n\tGlobal Camera:FlxCamera\n\t\n\tGlobal Plugins:Stack\n\t\n\tGlobal VolumeHandler:FlxVolumeChangeListener\n\t\n\tGlobal Elapsed:Float\n\t\n\tGlobal TimeScale:Float\n\t\n\tGlobal VisualDebug:Bool\n\n\tGlobal Mobile:Bool\n\t\n\tGlobal GlobalSeed:Int\n\t\n\tGlobal Scores:Stack\t\n\t\n\tGlobal Score:Int\n\t\n\tGlobal Accel:AccelInput\t\n\t\n\tGlobal Keys:Keyboard\n\t\n\tGlobal Mouse:Mouse\n\t\n\tGlobal Music:FlxMusic\n\t\n\tGlobal Sounds:FlxGroup\n\t\n\tGlobal Mute:Bool\n\t\t\n\tGlobal Framerate:Int\t\n\t\n\tGlobal _DeviceScaleFactorX:Float = 1\t\n\t\n\tGlobal _DeviceScaleFactorY:Float = 1\n\t\n\tGlobal _BgColor:FlxColor = FlxColor.ARGB(FlxG.BLACK)\t\t\n\t\n\tGlobal _Game:FlxGame\n\t\n\tGlobal _Volume:Float\n\t\n\tGlobal _Cache:FlxResourcesManager\n\t\n\tGlobal _LastDrawingColor:Int\n\t\n\tGlobal _LastDrawingAlpha:Float\n\t\n\tGlobal _LastDrawingBlend:Int\n\t\n\tGlobal _CurrentCamera:FlxCamera\n\t\n\tGlobal _CurrentCameraID:Int\n\nPrivate\n\tConst _JOY_UNITS_COUNT:Int = 4\n\t\n\tConst _TOUCH_COUNT:Int = 32\n\t\n\tGlobal _Joystick:JoystickInput[_JOY_UNITS_COUNT]\n\t\n\tGlobal _Touch:TouchInput[_TOUCH_COUNT]\n\t\n\tGlobal _CollideListener:FlxCollideProcessListener = New FlxCollideProcessListener()\n\t\n\nPublic\n\tFunction GetLibraryName:String()\n\t\tReturn FlxG.LIBRARY_NAME + \" v\" + FlxG.LIBRARY_MAJOR_VERSION + \".\" + FlxG.LIBRARY_MINOR_VERSION\n\tEnd Function\n\t\n\tFunction Log:Void(data:String)\n\t\tPrint data\n\t\t'TODO\n\tEnd Function\n\t\n\tFunction Random:Float()\n\t\tFlxG.GlobalSeed = (FlxG.GlobalSeed * 1664525 + 1013904223)|0\n\t\tReturn FlxU.Srand(FlxG.GlobalSeed)\n\tEnd Function\n\t\n\tFunction GetRandom:FlxBasic(objects:FlxBasic[], startIndex:Int = 0, length:Int = 0)\n\t\tIf (objects.Length() > 0) Then\n\t\t\tLocal l:Int = length\n\t\t\t\n\t\t\tIf (l = 0 Or l > objects.Length() - startIndex) Then\n\t\t\t\tl = objects.Length() - startIndex\n\t\t\tEnd if\n\t\t\t\n\t\t\tIf (l > 0) Return objects[startIndex + int(FlxG.Random()*l)]\t\n\t\tEnd If\n\t\t\n\t\tReturn Null\n\tEnd Function\n\t\n\t#Rem\n\tFunction GetRandom:Object(objects:Object[], startIndex:Int = 0, length:Int = 0)\n\t\tGetRandom is not currently supported in Monkey. Use FlxArray.GetSafeRandom method\n\tEnd Function\n\t#End\n\t\n\tFunction LoadReplay:Void(data:String, state:FlxState = Null, cancelKeys:Int[] = [], timeout:Float = 0, callback:FlxReplayListener = Null)\n\t\t_game._replay.Load(data)\n\t\tIf (state = Null) Then\n\t\t\tFlxG.ResetGame()\n\t\tElse\n\t\t\tFlxG.SwitchState(state)\n\t\tEnd If\n\t\t\n\t\t_game._replayCancelKeys = cancelKeys\n\t\t_game._replayTimer = timeout * 1000\n\t\t_game._replayCallback = callback\n\t\t_game._replayRequested = True\n\tEnd Function\n\t\n\tFunction ReloadReplay:Void(standardMode:Bool = True)\n\t\tIf (standardMode) Then\n\t\t\tFlxG.ResetGame()\n\t\tElse\n\t\t\tFlxG.ResetState()\n\t\tEnd If\n\t\t\n\t\tIf (_game._replay.frameCount > 0) _game._replayRequested = True\n\tEnd Function\t\n\t\n\tFunction StopReplay:Void()\n\t\t_Game._replaying = False\n\t\t\n\t\tIf (_Game._debugger <> Null) Then\n\t\t\t'TODO\n\t\tEnd If\n\t\t\n\t\tResetInput()\n\tEnd Function\n\t\n\tFunction RecordReplay:Void(standardMode:Bool = True)\n\t\tIf (standardMode) Then\n\t\t\tFlxG.ResetGame()\n\t\tElse\n\t\t\tFlxG.ResetState()\n\t\tEnd If\n\t\t\n\t\t_game._recordingRequested = True\n\tEnd Function\n\t\n\tFunction StopRecording:String()\n\t\t_game._recording = False\n\t\t\n\t\tIf (_game._debugger <> Null) Then\n\t\t\t'TODO\n\t\tEnd if\n\t\t\n\t\tReturn _game._replay.Save()\n\tEnd Function\n\t\n\tFunction ResetState:Void()\n\t\t_game._requestedState = FlxState(_game._state.GetClass().CreateInstance())\n\tEnd Function\n\t\n\tFunction ResetGame:Void()\n\t\t_game._requestedReset = True\n\tEnd Function\n\t\n\tFunction ResetInput:Void()\n\t\t#If TARGET = \"html5\" Or TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tAccel.Reset()\n\t\t#End\t\t\t\t\n\t\t\n\t\t#If TARGET = \"xna\" Or TARGET = \"glfw\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tFor Local i:Int = 0 Until _JOY_UNITS_COUNT\n\t\t\t\t\t_Joystick[i].Reset()\n\t\t\t\tNext\n\t\t\tEnd If\n\t\t#End\n\t\t\n\t\t#If TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t_Touch[i].Reset()\n\t\t\tNext\n\t\t\t\n\t\t#ElseIf TARGET = \"html5\" Or TARGET = \"flash\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Reset()\n\t\t\tEnd If\n\t\t\t\t\n\t\t\t_Touch[0].Reset()\n\t\t\n\t\t#ElseIf TARGET = \"xna\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Reset()\n\t\t\t\t_Touch[0].Reset()\n\t\t\tElse\n\t\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t\t_Touch[i].Reset()\n\t\t\t\tNext\n\t\t\tEnd If\t\t\t\n\t\t\t\n\t\t#Else\n\t\t\tKeys.Reset()\n\t\t\t_Touch[0].Reset()\t\t\t\n\t\t#End\n\t\t\n\t\t#If TARGET = \"android\"\n\t\t\tKeys.Reset()\n\t\t#End\n\t\t\n\t\tMouse.Reset()\n\tEnd Function\n\t\n\tFunction PlayMusic:Void(music:String, volume:Float = 1.0)\n\t\tIf (FlxG.Music = Null) Then\n\t\t\tFlxG.Music = New FlxMusic()\n\t\t\t\n\t\tElseIf (FlxG.Music.active) Then\n\t\t\tFlxG.Music.Stop()\n\t\tEnd If\n\t\t\n\t\tFlxG.Music.Load(music, True)\n\t\tFlxG.Music.Volume = volume\n\t\tFlxG.Music.survive = True\n\t\t\n\t\tFlxG.Music.Play()\n\tEnd Function\n\t\n\tFunction LoadSound:FlxSound(sound:String, volume:Float = 1.0, looped:Bool = False, autoDestroy:Bool = False, autoPlay:Bool = False)\n\t\tLocal s:FlxSound = FlxSound(Sounds.Recycle(FlxSound.ClassObject))\n\t\t\n\t\ts.Load(sound, looped, autoDestroy)\n\t\ts.Volume = volume\t\t\n\t\tIf (autoPlay) s.Play()\n\t\t\t\t\n\t\tReturn s\n\tEnd Function\n\t\n\tFunction Play:FlxSound(sound:String, volume:Float = 1.0, looped:Bool = False, autoDestroy:Bool = True)\n\t\tReturn FlxG.LoadSound(sound, volume, looped, autoDestroy, True)\n\tEnd Function\n\t\n\tFunction Volume:Float()\n\t\tReturn _Volume\n\tEnd Function\n\t\n\tFunction Volume:Void(volume:Float)\n\t\t_Volume = volume\n\t\t\n\t\tIf (_Volume < 0) Then\n\t\t\t_Volume = 0\n\t\tElseIf (_Volume > 1) Then\n\t\t\t_Volume = 1\n\t\tEnd If\n\t\t\n\t\tIf (VolumeHandler <> Null) Then\n\t\t\tIf (FlxG.Mute) Then\n\t\t\t\tVolumeHandler.OnVolumeChange(0)\n\t\t\tElse\n\t\t\t\tVolumeHandler.OnVolumeChange(_Volume)\n\t\t\tEnd If\n\t\tEnd If\n\tEnd Function\n\t\n\tFunction DestroySounds:Void(forceDestroy:Bool = False)\n\t\tIf (Music <> Null And (forceDestroy Or Not Music.survive)) Then\n\t\t\tMusic.Destroy()\n\t\t\tMusic = Null\n\t\tEnd If\n\t\t\n\t\tLocal sound:FlxSound\n\t\t\n\t\tFor Local basic:FlxBasic = EachIn Sounds\n\t\t\tsound = FlxSound(basic)\n\t\t\t\n\t\t\tIf (sound <> Null And (forceDestroy Or Not sound.survive)) Then\n\t\t\t\tsound.Destroy()\n\t\t\tEnd If\n\t\tNext\n\tEnd Function\n\t\n\tFunction UpdateSounds:Void()\n\t\tIf (Music <> Null And Music.active) Then\n\t\t\tMusic.Update()\n\t\tEnd If\n\t\t\n\t\tIf (Sounds <> Null And Sounds.active) Then\n\t\t\tSounds.Update()\n\t\tEnd If\n\tEnd Function\n\t\n\tFunction PauseSounds:Void()\n\t\tIf (Music <> Null And Music.exists And Music.active) Then\n\t\t\tMusic.Pause()\n\t\tEnd If\n\t\t\n\t\tLocal sound:FlxSound\n\t\t\n\t\tFor Local basic:FlxBasic = EachIn Sounds\n\t\t\tsound = FlxSound(basic)\n\t\t\t\n\t\t\tIf (sound <> Null And sound.exists And sound.active) Then\n\t\t\t\tsound.Pause()\n\t\t\tEnd If\n\t\tNext\n\tEnd Function\n\t\n\tFunction ResumeSounds:Void()\n\t\tIf (Music <> Null And Music.exists) Then\n\t\t\tMusic.Play()\n\t\tEnd If\n\t\t\n\t\tLocal sound:FlxSound\n\t\t\n\t\tFor Local basic:FlxBasic = EachIn Sounds\n\t\t\tsound = FlxSound(basic)\n\t\t\t\n\t\t\tIf (sound <> Null And sound.exists) Then\n\t\t\t\tsound.Resume()\n\t\t\tEnd If\n\t\tNext\n\tEnd Function\n\t\n\tFunction CheckBitmapCache:Bool(key:String)\n\t\tReturn _Cache.CheckResource(key)\n\tEnd Function\n\t\n\tFunction AddBitmap:Image(graphic:String, graphicLoader:FlxResourceLoader, unique:Bool = False, key:String = \"\")\n\t\tIf (key.Length() = 0) Then\n\t\t\tkey = graphic\n\t\t\t\n\t\t\tIf (unique And CheckBitmapCache(key)) Then\n\t\t\t\tLocal inc:Int = 0\n\t\t\t\tLocal ukey:String\n\t\t\t\t\n\t\t\t\tRepeat\n\t\t\t\t\tukey = key + inc\n\t\t\t\t\tinc += 1\n\t\t\t\tUntil(CheckBitmapCache(ukey))\n\t\t\t\t\n\t\t\t\tkey = ukey\n\t\t\tEnd If\n\t\tEnd If\n\t\t\n\t\tReturn _Cache.GetResource(key, graphicLoader)\n\tEnd Function\n\t\n\tFunction ClearBitmapCache:Void()\n\t\tIf (_Cache = Null) _Cache = New FlxResourcesManager()\n\t\t\n\t\tFor Local image:Image = EachIn _Cache.Resources.Values()\n\t\t\tIf (image <> Null) image.Discard()\n\t\tNext\n\t\t\n\t\t_Cache.Clear()\n\tEnd Function\n\t\n\tFunction State:FlxState()\n\t\tReturn _Game._state\n\tEnd Function\n\t\n\tFunction SwitchState:Void(state:FlxState)\n\t\tFlxG._Game._requestedState = state\n\tEnd Function\n\t\n\tFunction AddCamera:FlxCamera(newCamera:FlxCamera)\n\t\tFlxG.Cameras.Push(newCamera)\n\t\tReturn newCamera\n\tEnd Function\n\t\n\tFunction RemoveCamera:Void(camera:FlxCamera, destroy:Bool = True)\n\t\tFlxG.Cameras.RemoveEach(camera)\n\t\tIf (destroy) camera.Destroy()\n\tEnd Function\n\t\n\tFunction ResetCameras:Void(newCamera:FlxCamera = Null)\t\n\t\tLocal cam:FlxCamera\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = FlxG.Cameras.Get(i)\n\t\t\tcam.Destroy()\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG.Cameras.Clear()\n\t\tFlxG.Camera = Null\n\t\t\n\t\tIf (newCamera = Null) newCamera = New FlxCamera(0, 0, FlxG.Width, FlxG.Height)\n\t\t\n\t\tFlxG.Camera = FlxG.AddCamera(newCamera)\t\n\tEnd Function\n\t\n\tFunction Flash:Void(color:Int = FlxG.WHITE, duration:Float = 1, onComplete:FlxCameraFlashListener = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).Flash(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Fade:Void(color:Int = FlxG.BLACK, duration:Float = 1, onComplete:FlxCameraFadeListener = Null, force:Bool = False)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).Fade(color, duration, onComplete, force)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Shake:Void(intensity:Float = 0.05, duration:Float = 0.5, onComplete:FlxCameraShakeListener = Null, force:Bool = True, direction:Int = FlxCamera.SHAKE_BOTH_AXES)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).Shake(intensity, duration, onComplete, force, direction)\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\t\t\n\t\n\tFunction BgColor:Int()\n\t\tIf (FlxG.Camera = Null Or Not FlxG.Camera.alive) Return FlxG._BgColor.argb\t\n\t\tReturn FlxG.Camera.BgColor\n\tEnd Function\n\t\n\tFunction BgColor:Void(color:Int)\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = FlxG.Cameras.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tFlxG.Cameras.Get(i).BgColor = color\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tFlxG._BgColor.SetARGB(color)\n\tEnd Function\n\t\n\tFunction Overlap:Bool(objectOrGroup1:FlxBasic = Null, objectOrGroup2:FlxBasic, notifyCallback:FlxOverlapNotifyListener = Null, processCallback:FlxOverlapProcessListener = Null)\n\t\tIf (objectOrGroup1 = Null) objectOrGroup1 = FlxG.State()\n\t\tIf (objectOrGroup2 = objectOrGroup1) objectOrGroup2 = Null\n\t\t\n\t\tFlxQuadTree.Divisions = FlxG.WorldDivisions\n\t\t\n\t\tLocal quadTree:FlxQuadTree = New FlxQuadTree(FlxG.WorldBounds.x, FlxG.WorldBounds.y, FlxG.WorldBounds.width, FlxG.WorldBounds.height)\n\t\tquadTree.Load(objectOrGroup1, objectOrGroup2, notifyCallback, processCallback)\n\t\t\n\t\tLocal result:Bool = quadTree.Execute()\n\t\tquadTree.Destroy()\n\t\t\n\t\tReturn result\n\tEnd Function\n\t\n\tFunction Collide:Bool(objectOrGroup1:FlxBasic = Null, objectOrGroup2:FlxBasic = Null, notifyCallback:FlxOverlapNotifyListener = Null)\n\t\tReturn\tOverlap(objectOrGroup1, objectOrGroup2, notifyCallback, _CollideListener)\n\tEnd Function\n\t\n\tFunction AddPlugin:FlxBasic(plugin:FlxBasic)\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tIf (pluginList.Get(i).ToString() = plugin.ToString()) Then\n\t\t\t\tReturn plugin\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tpluginList.Push(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction GetPlugin:FlxBasic(creator:FlxClass)\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal plugin:FlxBasic\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (creator.InstanceOf(plugin)) Return plugin\n\t\t\t\n\t\t\ti+=1\n\t\tWend\n\t\t\n\t\tReturn Null\t\n\tEnd Function\n\t\n\tFunction RemovePlugin:FlxBasic(plugin:FlxBasic)\n\t\tplugins.RemoveEach(plugin)\n\t\tReturn plugin\n\tEnd Function\n\t\n\tFunction RemovePluginType:Bool(creator:FlxClass)\n\t\tLocal results:Bool = False\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = pluginList.Length() - 1\t\n\t\t\n\t\tWhile(i >= 0)\n\t\t\tIf (creator.InstanceOf(pluginList.Get(i))) Then\n\t\t\t\tpluginList.Remove(i)\n\t\t\t\tresults = True\t\n\t\t\tEnd If\n\t\t\t\n\t\t\ti-=1\n\t\tWend\n\t\n\t\tReturn results\n\tEnd Function\n\t\n\tFunction Init:Void(game:FlxGame, width:Int, height:Int, zoom:Float)\n\t\tFlxG._Game = game\n\t\tFlxG.Width = width\n\t\tFlxG.Height = height\n\t\t\n\t\tFlxG.Mute = False\n\t\tFlxG._Volume = .5\n\t\tFlxG.Sounds = New FlxGroup()\n\t\tFlxG.VolumeHandler = Null\n\t\t\n\t\tFlxG.ClearBitmapCache()\t\t\n\t\t\n\t\tFlxCamera.DefaultZoom = zoom\n\t\tFlxG.Cameras = New Stack()\t\t\n\t\t\n\t\tPlugins = New Stack\n\t\tAddPlugin(New DebugPathDisplay())\n\t\tAddPlugin(New TimerManager())\n\t\t\n\t\tFlxG.Accel = New AccelInput()\n\t\tFlxG.Keys = New Keyboard()\n\t\tFlxG.Mouse = New Mouse()\n\t\t\n\t\tFor Local i:Int = 0 Until _JOY_UNITS_COUNT\n\t\t\t_Joystick[i] = New JoystickInput(i)\n\t\tNext\n\t\t\n\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t_Touch[i] = New TouchInput(i)\n\t\tNext\n\t\t\n\t\tFlxG.Mobile = IsMobile()\n\t\t\n\t\tFlxG.Scores = New Stack()\t\t\n\tEnd Function\n\t\n\tFunction Reset:Void()\n\t\tFlxG.ClearBitmapCache()\n\t\tFlxG.ResetInput()\n\t\tFlxG.DestroySounds(True)\n\t\tFlxG.Scores.Clear()\n\t\tFlxG.Score = 0\t\n\t\tFlxG.TimeScale = 1\n\t\tFlxG.Elapsed = 0 \n\t\tFlxG.GlobalSeed = Rnd(1, 10000000)\n\t\tFlxG.WorldBounds = New FlxRect(-10, -10, FlxG.Width + 20, FlxG.Height + 20)\n\t\tFlxG.WorldDivisions = 6\n\t\tLocal debugPathDisplay:DebugPathDisplay = DebugPathDisplay(FlxG.GetPlugin(DebugPathDisplay.ClassObject))\n\t\tIf (debugPathDisplay <> Null) debugPathDisplay.Clear()\n\tEnd Function\n\t\n\tFunction UpdateInput:Void()\n\t\t#If TARGET = \"html5\" Or TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tAccel.Update(AccelX(), AccelY(), AccelZ())\n\t\t#End\t\t\n\t\t\n\t\t#If TARGET = \"xna\" Or TARGET = \"glfw\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tFor Local i:Int = 0 Until _JOY_UNITS_COUNT\n\t\t\t\t\t_Joystick[i].Update()\n\t\t\t\tNext\n\t\t\tEnd If\n\t\t#End\n\t\t\n\t\t#If TARGET = \"ios\" Or TARGET = \"android\"\n\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t_Touch[i].Update(TouchX(i), TouchY(i))\n\t\t\t\t\n\t\t\t\tIf (i > 0 And Not _Touch[i].Used) Exit\n\t\t\tNext\n\t\t\t\n\t\t#ElseIf TARGET = \"html5\" Or TARGET = \"flash\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Update()\n\t\t\tEnd If\n\t\t\t\n\t\t\t_Touch[0].Update(TouchX(), TouchY())\n\t\t\t\n\t\t#ElseIf TARGET = \"xna\"\n\t\t\tIf (Not FlxG.Mobile) Then\n\t\t\t\tKeys.Update()\n\t\t\t\t_Touch[0].Update(TouchX(), TouchY())\n\t\t\tElse\n\t\t\t\tFor Local i:Int = 0 Until _TOUCH_COUNT\n\t\t\t\t\t_Touch[i].Update(TouchX(i), TouchY(i))\n\t\t\t\t\t\n\t\t\t\t\tIf (i > 0 And Not _Touch[i].Used) Exit\n\t\t\t\tNext\n\t\t\tEnd If\n\t\t\t\t\t\n\t\t#Else\n\t\t\tKeys.Update()\t\t\t\t\n\t\t\t_Touch[0].Update(TouchX(), TouchY())\n\t\t#End\n\t\t\n\t\t#If TARGET = \"android\"\n\t\t\tKeys.Update()\n\t\t#End\n\t\t\n\t\tIf (Not _Game._debuggerUp Or Not _Game._debugger.hasMouse) Then\n\t\t\tMouse.Update(MouseX(), MouseY())\n\t\tEnd If\n\tEnd Function\n\t\n\tFunction UpdateCameras:Void()\n\t\tLocal cam:FlxCamera\n\t\tLocal cams:Stack = FlxG.Cameras\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = cams.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tcam = cams.Get(i)\n\t\t\tIf (cam <> Null And cam.exists And cam.active) cam.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction UpdatePlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.active) plugin.Update()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction DrawPlugins:Void()\n\t\tLocal plugin:FlxBasic\n\t\tLocal pluginList:Stack = FlxG.Plugins\n\t\tLocal i:Int = 0\n\t\tLocal l:Int = pluginList.Length()\n\t\t\n\t\tWhile(i < l)\n\t\t\tplugin = pluginList.Get(i)\n\t\t\tIf (plugin.exists And plugin.visible) plugin.Draw()\t\t\t\n\t\t\ti+=1\n\t\tWend\n\tEnd Function\n\t\n\tFunction Joystick:JoystickInput(unit:Int = 0)\n\t\tReturn _Joystick[unit]\n\tEnd Function\n\t\n\tFunction Touch:TouchInput(index:Int = 0)\n\t\tReturn _Touch[index]\n\tEnd Function\n\t\n\tFunction JoystickCount:Int()\n\t\tReturn _JOY_UNITS_COUNT\n\tEnd Function\n\t\n\tFunction TouchCount:Int()\n\t\tReturn _TOUCH_COUNT\n\tEnd Function\n\nEnd Class\n\nPrivate\nClass FlxCollideProcessListener Implements FlxOverlapProcessListener\n\t\n\tMethod OnOverlapProcess:Bool(object1:FlxObject, object2:FlxObject)\n\t\tReturn FlxObject.Separate(object1, object2)\n\tEnd Method\n\nEnd Class","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"e8a06dc20e5330e36a8baa0b2926bcd6f310746d","subject":"I forgot the 'CopyArray' command already had a default for that situation. This should fix any issues. I also changed 'IsObject' to 'TypeIsObject' globally.","message":"I forgot the 'CopyArray' command already had a default for that situation. This should fix any issues. I also changed 'IsObject' to 'TypeIsObject' globally.\n","repos":"Regal-Internet-Brothers\/util,Regal-Internet-Brothers\/util","old_file":"util.monkey","new_file":"util.monkey","new_contents":"Strict\n\nPublic\n\n' Preprocessor related:\n#Rem\n#If TARGET = \"glfw\" Or TARGET = \"sexy\"\n\t#GLFW_TARGET = True\n#End\n#End\n\n#UTIL_IMPLEMENTED = True\n\n#If IOELEMENT_IMPLEMENTED\n\t#UTIL_SUPPORT_IOELEMENTS = True\n#Else\n\t#UTIL_SUPPORT_IOELEMENTS = False\n#End\n\n#If CONFIG = \"debug\"\n\t#DEBUG_PRINT = True\n#Else\n\t#DEBUG_PRINT = False\n#End\n\n#If CONFIG = \"release\"\n\t#DEBUG_PRINT_ON_ERROR = True\n#Else\n\t#DEBUG_PRINT_ON_ERROR = False\n#End\n\n#DEBUG_PRINT_QUOTES = False\n\n#READ_LINE_QUICKLY = True\n\n#If HOST = \"winnt\"\n\t#WRITE_LINE_ENDTYPE = \"CRLF\"\n#Else\n\t#WRITE_LINE_ENDTYPE = \"LF\"\n#End\n\n' Imports (Public):\nImport autostream\n\nImport byteorder\nImport imagedimensions\nImport retrostrings\nImport stringutil\nImport vector\n\n#If CONSOLE_IMPLEMENTED\n\tImport console\n#End\n\nImport sizeof\nImport time\n\n#If Not BRL_GAMETARGET_IMPLEMENTED\n\tImport mojoemulator\n#End\n\n' Imports (Private):\nPrivate\n\n' Unofficial:\n#If UTIL_SUPPORT_IOELEMENTS\n\tImport ioelement\n#End\n\n' Official:\n\n' BRL:\nImport brl.databuffer\nImport brl.stream\nImport brl.filepath\n\nPublic\n\n' Constant variable(s):\n\n' Type codes (Mainly used for generic classes):\nConst TYPE_OBJECT:Int\t\t\t= 0\nConst TYPE_INT:Int\t\t\t\t= 1\nConst TYPE_BOOL:Int\t\t\t\t= 2\nConst TYPE_FLOAT:Int\t\t\t= 3\nConst TYPE_STRING:Int\t\t\t= 4\n\n' Ascii codes:\nConst ASCII_CARRIAGE_RETURN:Int = 13\nConst ASCII_LINE_FEED:Int = 10\n\n' Used mainly for external code where '-9999...' isn't ever going to be valid.\n' You should stick to 'Null' in most cases; try not to use this.\nConst NOVAR:Int = -999999\n\n' This is for situations where the length of something can be optional.\nConst AUTOMATIC_LENGTH:Int = -1\n\nConst ErrorTemplate:String = \"[ERROR] {Debug}: \" ' + Space\nConst LogTemplate:String = \"[Info] {Debug}: \" ' + Space\n\n' Global variable(s) (Public):\n#If CONSOLE_IMPLEMENTED\n\tGlobal DebugConsole:Console = Null\n#End\n\n' A global stack logging randomization seeds.\n' This is commonly accessed by the 'PushSeed' and 'PopSeed' functions.\nGlobal SeedStack:Stack = Null\n\n' Global variable(s) (Private):\nPrivate\n\n' Nothing so far.\n\nPublic\n\n' Functions:\nFunction FLAG:Int(ID:Int)\n\tReturn Pow(2, ID)\nEnd\n\n' This command is little-endian only:\nFunction AsByte:Int(I:Int)\n\tReturn ((I Shl 24) Shr 24)\nEnd\n\n' This command treats data as 8-bit (Turns something like $F7, into $FFFFFFF7)\n' This is only applied on little-endian systems,\n' please use this command for hex values (Monkey converts hex on compile-time).\nFunction PaddedHex:Int(I:Int)\n\tIf (Not BigEndian()) Then\n\t\tReturn AsByte(I)\n\tEndif\n\t\n\tReturn I\nEnd\n\nFunction Transfer:Bool(InputStream:Stream, OutputStream:Stream, DataSize:Int)\n\t' Check for errors:\n\tIf (DataSize = 0) Then Return False\n\tIf (InputStream = Null Or InputStream.Eof()) Then Return False\n\tIf (OutputStream = Null) Then Return False\n\t\n\t' Local variable(s):\n\t#If FLAG_TEMP_BUFFERS\n\t\tLocal Data:DataBuffer = New DataBuffer(DataSize)\n\t\tLocal DataLength:= DataSize ' Data.Length()\n\t\t\n\t\t' Read from the input-stream, then write to the output-stream:\n\t\tInputStream.Read(Data, 0, DataLength)\n\t\tOutputStream.Write(Data, 0, DataLength)\n\t\t\n\t\tData.Discard()\n\t#Else\n\t\t'Local Data:Int[DataSize]\n\t\t\n\t\tFor Local I:Int = 1 To DataSize ' Data.Length()\n\t\t\tOutputStream.WriteByte(InputStream.ReadByte())\n\t\tNext\n\t#End\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\nFunction Sq:Float(Input:Float)\n\tReturn Pow(Input, 2.0) ' Input * Input\nEnd\n\nFunction Sq:Int(Input:Int)\n\tReturn Pow(Input, 2)\nEnd\n\nFunction WrapAngle:Float(A:Float)\n\tWhile (A < 0.0)\n\t\tA += 360.0\n\tWend\n\t\n\tWhile (A > 360.0)\n\t\tA -= 360.0\n\tWend\n\t\n\tReturn A\nEnd\n\nFunction WrapColor:Float(C:Float)\n\t#Rem\n\tWhile (C < 0.0)\n\t\tC += 255.0\n\tWend\n\t\n\tWhile (C > 255.0)\n\t\tC -= 255.0\n\tWend\n\t#End\n\t\n\tReturn C Mod 256.0\nEnd\n\n' This command is a helper function for \nFunction ProcessColorLocation:Int(Point:Int)\n\t' Check for errors:\n\tIf (Point < 0) Then\n\t\tReturn 0\n\tEndif\n\t\n\tReturn (SizeOf_Integer_InBits-(SizeOf_Octet_InBits*(Point+1))) ' ((SizeOf_Integer_InBits-SizeOf_Octet_InBits)-(SizeOf_Octet_InBits*Point))\nEnd\n\n' NOTE: This command will produce incorrect color values without all characters present in the encode-string.\nFunction ColorToString:String(Pixel:Int, Encoding:String=\"ARGB\")\n\t' Ensure the encoding is always described as uppercase.\n\tEncoding = Encoding.ToUpper()\n\t\n\t' Return the encoded color-string.\n\tReturn (\"R: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"R\"))) & $000000FF) +\n\t\t\t\", G: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"G\"))) & $000000FF) +\n\t\t\t\", B: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"B\"))) & $000000FF) +\n\t\t\t\", A: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"A\"))) & $000000FF))\nEnd\n\nFunction PrintColor:Void(Pixel:Int, Encoding:String=\"ARGB\")\n\tPrint(ColorToString(Pixel, Encoding))\n\t\n\tReturn\nEnd\n\n' This is just a wrapper for the main implementation:\nFunction PushSeed:Bool()\n\tReturn PushSeed(Seed)\nEnd\n\n' The return value of this function specifies if the seed-stack already existed.\nFunction PushSeed:Bool(Seed:Int)\n\t' Local variable(s):\n\tLocal Response:Bool = (SeedStack <> Null)\n\t\n\tIf (Not Response) Then\n\t\tSeedStack = New IntStack()\n\tEndif\n\t\n\tSeedStack.Push(Seed)\n\t\n\t' Return the calculated response.\n\tReturn Response\nEnd\n\n' This command retrieves a seed from the seed-stack,\n' if no seed exists, the current randomization seed is returned.\nFunction PopSeed:Int()\n\tIf (SeedStack <> Null) Then\n\t\tIf (Not SeedStack.IsEmpty()) Then\n\t\t\tReturn SeedStack.Pop()\n\t\tEndif\n\tEndif\n\t\n\t' Return the default response.\n\tReturn Seed\nEnd\n\n' This command writes a standard line to a 'Stream'.\n' This supports both 'LF', and 'CRLF' line endings currently, and this can be configured with 'WRITE_LINE_ENDTYPE'.\n' Though character encoding is supported with this, only ASCII is supported by 'ReadLine'.\nFunction WriteLine:Bool(S:Stream, Line:String, CharacterEncoding:String=\"ascii\")\n\t' Check for errors:\n\tIf (S = Null) Then\n\t\tReturn False\n\tEndif\n\t\n\tS.WriteString(Line, CharacterEncoding)\n\t\n\t#If WRITE_LINE_ENDTYPE = \"CRLF\"\n\t\tS.WriteByte(ASCII_CARRIAGE_RETURN)\n\t#End\n\t\n\tS.WriteByte(ASCII_LINE_FEED)\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\n' This command reads a standard line from a 'Stream'. (This supports both 'LF', and 'CRLF' line endings currently)\n' In addition, only 'ASCII' is currently supported.\nFunction ReadLine:String(S:Stream)\n\t' Local variable(s):\n\tLocal Position:= S.Position()\n\tLocal Padding:Int = 0 ' * SizeOf_Char\n\tLocal Str:String\n\t\n\t#If Not READ_LINE_QUICKLY\n\t\tLocal Size:Int = 0\n\t#End\n\t\n\tWhile (Not S.Eof())\n\t\tLocal Char:= S.ReadByte()\n\t\t\n\t\tIf (Char <> ASCII_LINE_FEED) Then\n\t\t\tIf (Char <> ASCII_CARRIAGE_RETURN) Then\n\t\t\t\t#If READ_LINE_QUICKLY\n\t\t\t\t\tStr += String.FromChar(Char)\n\t\t\t\t#Else\n\t\t\t\t\tSize += 1\n\t\t\t\t#End\n\t\t\tElse\n\t\t\t\tPadding = 2*SizeOf_Char\n\t\t\tEndif\n\t\tElse\n\t\t\t#Rem\n\t\t\t\tIf (Padding = 0) Then\n\t\t\t\t\tPadding = 1\n\t\t\t\tEndif\n\t\t\t#End\n\t\t\t\n\t\t\tPadding = Max(Padding, 1*SizeOf_Char)\n\t\t\t\n\t\t\tExit\n\t\tEndif\n\tWend\n\t\n\t#If Not READ_LINE_QUICKLY\n\t\tS.Seek(Position)\n\t\t\n\t\tStr = S.ReadString(Size, \"ascii\")\n\t\t\n\t\tS.Seek(S.Position()+Padding)\n\t#End\n\t\n\t' Return the string we read from the stream.\n\tReturn Str\nEnd\n\nFunction ResizeBuffer:DataBuffer(Buffer:DataBuffer, Size:Int=AUTOMATIC_LENGTH, CopyData:Bool=True, DiscardOldBuffer:Bool=False, OnlyWhenDifferentSizes:Bool=False)\n\tLocal BufferAvailable:Bool = (Buffer <> Null)\n\t\n\tIf (BufferAvailable And OnlyWhenDifferentSizes) Then\n\t\tIf (Size <> AUTOMATIC_LENGTH And Buffer.Length() = Size) Then\n\t\t\tReturn Buffer\n\t\tEndif\n\tEndif\n\t\n\tIf (Size = AUTOMATIC_LENGTH) Then\n\t\tSize = Buffer.Length()\n\tEndif\n\t\n\t' Allocate a new data-buffer.\n\tLocal B:= New DataBuffer(Size)\n\t\n\t' Copy the buffer's bytes over to 'B'.\n\tIf (BufferAvailable) Then\n\t\tIf (CopyData) Then\n\t\t\t' Copy the contents of 'Buffer' to the newly generated buffer-object.\n\t\t\tBuffer.CopyBytes(0, B, 0, Buffer.Length())\n\t\tEndif\n\t\t\n\t\tIf (DiscardOldBuffer) Then\n\t\t\t' Discard the old buffer.\n\t\t\tBuffer.Discard()\n\t\tEndif\n\tEndif\n\t\n\t' Return the newly generated buffer.\n\tReturn B\nEnd\n\n#If CONSOLE_IMPLEMENTED\n\tFunction DebugBind:Bool(C:Console)\n\t\tIf (C = Null) Then Return False\n\t\t\n\t\tDebugConsole = C\n\t\t\n\t\t' Return the default response.\n\t\tReturn True\n\tEnd\n#End\n\nFunction DebugError:Void(E:Throwable, StopExecution:Bool=True)\n\t#If CONFIG = \"debug\"\n\t\tDebugStop()\n\t#Else\n\t\tDebugPrint(\"Unknown exception has been thrown; continuing anyway.\")\n\t#End\n\t\n\tReturn\nEnd\n\nFunction DebugError:Void(Msg:String, StopExecution:Bool=True)\n\t#If DEBUG_PRINT\n\t\t' Local variable(s):\n\t\tLocal TempMsg:String\n\t\t\n\t\tIf (StopExecution) Then\n\t\t\tTempMsg = ErrorTemplate\n\t\tElse\n\t\t\tTempMsg = LogTemplate\n\t\tEndif\n\t\t\n\t\t#If DEBUG_PRINT_QUOTES\t\t\t\n\t\t\tMsg = Tempmsg + Quote + Msg + Quote\n\t\t#Else\n\t\t\tMsg = TempMsg + Msg\n\t\t#End\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\tDebugConsole.WriteLine(Msg, True)\n\t\t\tElse\n\t\t#End\n\t\t\n\t\tPrint(Msg)\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tEndif\n\t\t#End\n\t#Else\n\t\t' This may change later:\n\t\tIf (StopExecution) Then\n\t\t\tMsg = ErrorTemplate + Msg\n\t\tEndif\n\t#End\n\n\tIf (StopExecution) Then\n\t\t#If CONFIG = \"debug\"\n\t\t\t#If DEBUG_PRINT_ON_ERROR\n\t\t\t\tDebugStop()\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#Else\n\t\t\t#If DEBUG_PRINT\n\t\t\t\tLocal FinalStr:String = (ErrorTemplate + Quote + \"Attempt to stop execution failed. (Reason: Release-mode)\" + Quote)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\t\t\tDebugConsole.WriteLine(FinalStr, True)\n\t\t\t\t\tElse\n\t\t\t\t#End\n\t\t\t\t\n\t\t\t\tPrint(FinalStr)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tEndif\n\t\t\t\t#End\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#End\n\tEndif\n\t\n\t#If CONFIG = \"debug\"\n\t\t' Nothing so far.\n\t#Else\n\t\t' Nothing so far.\n\t#End\n\n\tReturn\nEnd\n\nFunction DebugPrint:Void(Str:String, StopExecution:Bool=False)\n\tDebugError(Str, StopExecution)\n\n\tReturn\nEnd\n\n' The following functions are designed to be used with generic classes:\nFunction TypeIsObject:Bool(O:Object)\n\tReturn True\nEnd\n\nFunction TypeIsObject:Bool(I:Int)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(B:Bool)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(F:Float)\n\tReturn False\nEnd\n\nFunction TypeIsObject:Bool(S:String)\n\tReturn False\nEnd\n\nFunction TypeOf:Int(O:Object)\n\tReturn TYPE_OBJECT\nEnd\n\nFunction TypeOf:Int(I:Int)\n\tReturn TYPE_INT\nEnd\n\nFunction TypeOf:Int(B:Bool)\n\tReturn TYPE_BOOL\nEnd\n\nFunction TypeOf:Int(F:Float)\n\tReturn TYPE_FLOAT\nEnd\n\nFunction TypeOf:Int(S:String)\n\tReturn TYPE_STRING\nEnd\n\n' Classes:\nClass GenericUtilities\n\t' Constant variable(s):\n\t\n\t' Comparison response codes (Positive numbers are for error-reporting):\n\tConst COMPARE_RESPONSE_IDENTICAL:Int\t\t\t= -1\n\tConst COMPARE_RESPONSE_WRONG_LENGTH:Int\t\t\t= -2\n\t\n\t' Other:\n\tConst AUTO:Int = -1\n\t\n\t' Global variable(s):\n\t\n\t' For internal and extern use. That being said, please do not modify this value.\n\tGlobal NIL:T\n\t\n\t' Functions:\n\t\n\t' This command gives the user the type-code of 'T'.\n\tFunction Type:Int()\n\t\t' Return the type code of 'NIL'.\n\t\tReturn TypeOf(NIL)\n\tEnd\n\t\n\t' This command specifies if 'T' is an object.\n\tFunction IsObject:Bool()\n\t\tReturn TypeIsObject(NIL)\n\tEnd\n\t\n\t' This command wraps the standard 'BoolToString' conversion command.\n\tFunction AsString:String(Input:Bool)\n\t\tReturn BoolToString(Input)\n\tEnd\n\t\n\t' This command reads a string from a standard 'Stream' object.\n\tFunction AsString:String(S:Stream, Length:Int=AUTO, Encoding:String=\"utf8\")\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = S.Length()\n\t\tEndif\n\t\t\n\t\tReturn S.ReadString(Length, Encoding)\n\tEnd\n\t\n\tFunction AsString:String(Input:T[], Offset:Int=0, Length:Int=AUTO, AddSpaces:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal Output:String = LeftBracket\n\t\t\n\t\t' If no length was specified, use the array's length.\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Input.Length()\n\t\tEndif\n\t\t\n\t\tLocal VirtualLength:= Length+Offset\n\t\t\n\t\tFor Local Index:Int = Offset Until VirtualLength\n\t\t\tOutput += Input[Index]\n\t\t\t\n\t\t\tIf (Index+1 < VirtualLength) Then\n\t\t\t\tOutput += Comma\n\t\t\t\t\n\t\t\t\tIf (AddSpaces) Then\n\t\t\t\t\tOutput += Space\n\t\t\t\tEndif\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\tReturn Output + RightBracket\n\tEnd\n\t\n\tFunction CopyStringToArray:T[](S:String, Input:T[], Offset:Int=0, Length:Int=AUTO)\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Min(S.Length(), Input.Length())\n\t\tEndif\n\t\t\n\t\tFor Local I:Int = Offset Until Length\n\t\t\tInput[I] = S[I]\n\t\tNext\n\t\t\n\t\t' Just for the sake of convenience, return the 'Input' array.\n\t\tReturn Input\n\tEnd\n\t\n\tFunction IndexOfList:T(L:List, Index:Int=0)\n\t\t' Local variable(s):\n\t\tLocal Data:list.Node = L.FirstNode()\n\t\t\t\t\n\t\tFor Local I:= 0 Until Index\n\t\t\tData = Data.NextNode()\n\t\t\t\n\t\t\t' Not my favorite method, but it works:\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn NIL\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the value of the assessed node.\n\t\tReturn Data.Value()\n\tEnd\n\t\n\tFunction Zero:T[](Input:T[])\n\t\tReturn Nil(Input)\n\tEnd\n\t\n\tFunction Nil:T[](Input:T[])\n\t\tFor Local Index:= 0 Until Input.Length()\n\t\t\tInput[Index] = NIL\n\t\tNext\n\t\t\n\t\tReturn Input\n\tEnd\n\t\n\tFunction PrintArray:Void(Input:T[])\n\t\tPrint(AsString(Input))\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\t\tNOTES:\n\t\t\t* In the event of an error, an empty array will be produced.\n\t\t\t\n\t\t\t* The 'CopyArray' command's 'FitSource' argument should only be enabled with the\n\t\t\tknowledge that the original destination may have been discarded.\n\t\t\t\n\t\t\tYour code must reflect this by disregarding the original array,\n\t\t\tand simply assigning the old array to the retrun value.\n\t\t\t\n\t\t\tEXAMPLE:\n\t\t\t\t' Local variable(s):\n\t\t\t\tLocal A:T[10], A2:T[3]\n\t\t\t\t\n\t\t\t\t' This will likely produce a new 'T' array, based on the area-delta.\n\t\t\t\tA2 = CopyArray(A, A2, True)\n\t#End\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], FitSource:Bool)\n\t\tReturn CopyArray(Source, Destination, 0, 0, AUTO, AUTO, FitSource)\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], Source_Offset:Int=0, Destination_Offset:Int=0, Source_Length:Int=AUTO, Destination_Length:Int=AUTO, FitSource:Bool=False)\n\t\tIf (Source_Length = AUTO) Then\n\t\t\tSource_Length = Source.Length()\n\t\tEndif\n\t\t\n\t\tIf (Destination_Length = AUTO) Then\n\t\t\tDestination_Length = Destination.Length()\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\t\n\t\t' These two are used as caches for the real lengths of the arrays:\n\t\tLocal Destination_RealLength:= Destination.Length()\n\t\tLocal Source_RealLength:= Source.Length()\n\t\t\n\t\t' Calculate the source and destination areas:\n\t\tLocal Source_Area:Int = (Source_Length-Source_Offset)\n\t\t\n\t\t' Make sure we have a source to work with:\n\t\tIf (Source_Area <= 0) Then\n\t\t\t' The source-area is too small for use, return an empty array.\n\t\t\tReturn []\n\t\tEndif\n\t\t\n\t\tLocal Destination_Area:Int = (Destination_Length-Destination_Offset)\n\t\t\n\t\t' For the sake of safety, we'll also check the destination area:\n\t\tIf (Destination_Area <= 0) Then\n\t\t\t' The destination-area is too small for use, return an empty array.\n\t\t\tReturn []\n\t\tEndif\n\t\t\n\t\tLocal Operation_Area:Int\n\t\t\n\t\tIf (FitSource And Destination_Area < Source_Area) Then\n\t\t\tLocal AreaDelta:Int = (Source_Area-Destination_Area)\n\t\t\tLocal NewArea:Int = (Destination_RealLength+AreaDelta)\n\t\t\t\n\t\t\tIf (NewArea > Destination_RealLength) Then\n\t\t\t\tDestination = Destination.Resize(NewArea)\n\t\t\tElse\n\t\t\t\tDestination = Destination.Resize(Destination_Length+AreaDelta)\n\t\t\tEndif\n\t\t\t\n\t\t\tDestination_Area = Source_Area\n\t\t\tOperation_Area = Destination_Area\n\t\tElse\n\t\t\tOperation_Area = Min(Source_Area, Destination_Area)\n\t\tEndif\n\t\t\n\t\t' Copy the contents of the source-array into the destination-array:\n\t\tFor Local Index:= 0 Until Operation_Area\n\t\t\tDestination[Index+Destination_Offset] = Source[Index+Source_Offset]\n\t\tNext\n\t\t\n\t\t' Return the destination-array.\n\t\tReturn Destination\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[])\n\t\tReturn CloneArray(Source)\n\tEnd\n\t\n\tFunction CloneArray:T[](Source:T[])\n\t\tReturn CopyArray(Source, New T[Source.Length()])\n\tEnd\n\t\n\t' This command returns a positive number upon an error,\n\t' otherwise a 'response code' will be given (See the \"Contant variable(s)\" section for details).\n\tFunction Compare:Int(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal A1_Length:= A1.Length\n\t\tLocal A2_Length:= A2.Length\n\t\t\n\t\t' Check for errors:\n\t\tIf (CheckLength) Then\n\t\t\t' Make sure they're both the same length.\n\t\t\tIf (A1_Length <> A2_Length) Then\n\t\t\t\tReturn COMPARE_RESPONSE_WRONG_LENGTH\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tFor Local I:= 0 Until Min(A1_Length, A2_Length)\n\t\t\tIf (A1[I] <> A2[I]) Then\n\t\t\t\t' Not the best of escape methods, but it works.\n\t\t\t\tReturn I\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the default response.\n\t\tReturn COMPARE_RESPONSE_IDENTICAL\n\tEnd\n\t\n\t' This function returns positive if both arrays are identical.\n\tFunction SimpleCompare:Bool(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\tReturn (Compare(A1, A2, CheckLength) = COMPARE_RESPONSE_IDENTICAL)\n\tEnd\n\t\n\tFunction Read:T(S:Stream)\n\t\tReturn Read(S, NIL)\n\tEnd\n\t\t\n\tFunction Read:T[](S:Stream, DataArray:T[], Size:Int=AUTO)\n\t\tIf (Size = AUTO) Then Size = S.ReadInt()\n\t\t\n\t\tIf (Size > 0) Then\n\t\t\tIf (DataArray.Length() = 0) Then\n\t\t\t\tDataArray = New T[Size]\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\tLocal DLength:Int = Min(DataArray.Length, Size)\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tDataArray[Index] = Read(S, NIL)\n\t\tNext\n\t\t\n\t\tReturn DataArray\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, DataArray:T[], WriteLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal DLength:= DataArray.Length()\n\t\t\n\t\tIf (WriteLength) Then S.WriteInt(DLength)\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tWrite(S, DataArray[Index])\n\t\tNext\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:Int(S:Stream, Indentifier:Int, Size:Int=4)\n\t\t' Local variable(s):\n\t\tLocal Data:Int = 0\n\t\t\n\t\tIf (Size > 1) Then\n\t\t\tIf (Size < 4) Then\n\t\t\t\tData = S.ReadShort()\n\t\t\tElse\n\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\tS.ReadInt()\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tData = S.ReadInt()\n\t\t\tEndif\n\t\tElse\n\t\t\tData = S.ReadByte()\n\t\tEndif\n\t\t\n\t\tReturn Data\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:Int, Size:Int=4)\n\t\tSize = IntSize(Size)\n\t\t\n\t\tIf (Size > 1) Then\n\t\t\tIf (Size < 4) Then\n\t\t\t\tS.WriteShort(Data)\n\t\t\tElse\n\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\tS.WriteInt(0)\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tS.WriteInt(Data)\n\t\t\tEndif\n\t\tElse\n\t\t\tS.WriteByte(Data)\n\t\tEndif\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\tFunction Read:Bool(S:Stream, Identifier:Bool)\n\t\tReturn Read(S, Int(Identifier), 1)\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, B:Bool)\n\t\tWrite(S, Int(B), 1)\n\t\t\n\t\tReturn\n\tEnd\n\t#End\n\t\n\tFunction Read:Float(S:Stream, Identifier:Float)\t\t\n\t\tReturn S.ReadFloat()\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:Float)\n\t\tS.WriteFloat(Data)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:String(S:Stream, Data:String, Encoding:String=\"utf8\", Size:Int=AUTO)\n\t\tIf (Size = AUTO) Then\n\t\t\tSize = S.ReadInt()\n\t\tEndif\n\t\t\n\t\tData = S.ReadString(Size, Encoding)\n\t\t\n\t\t' Return the newly read string.\n\t\tReturn Data\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:String, Encoding:String=\"utf8\", WriteSize:Bool=True)\n\t\tIf (WriteSize) Then\n\t\t\tS.WriteInt(Data.Length())\n\t\tEndif\n\t\t\n\t\tS.WriteString(Data, Encoding)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#If UTIL_SUPPORT_IOELEMENTS\n\t\tFunction Read:Void(S:Stream, Data:InputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Load(S)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:OutputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Save(S)\n\t\tEnd\n\t#End\n\t\n\t' Constructor(s):\n\t\n\t' DO NOT CREATE NEW INSTANCES OF THIS CLASS.\n\tMethod New()\n\t\tDebugError(\"This class should not be used in this was.\")\n\tEnd\nEnd","old_contents":"Strict\n\nPublic\n\n' Preprocessor related:\n#Rem\n#If TARGET = \"glfw\" Or TARGET = \"sexy\"\n\t#GLFW_TARGET = True\n#End\n#End\n\n#UTIL_IMPLEMENTED = True\n\n#If IOELEMENT_IMPLEMENTED\n\t#UTIL_SUPPORT_IOELEMENTS = True\n#Else\n\t#UTIL_SUPPORT_IOELEMENTS = False\n#End\n\n#If CONFIG = \"debug\"\n\t#DEBUG_PRINT = True\n#Else\n\t#DEBUG_PRINT = False\n#End\n\n#If CONFIG = \"release\"\n\t#DEBUG_PRINT_ON_ERROR = True\n#Else\n\t#DEBUG_PRINT_ON_ERROR = False\n#End\n\n#DEBUG_PRINT_QUOTES = False\n\n#READ_LINE_QUICKLY = True\n\n#If HOST = \"winnt\"\n\t#WRITE_LINE_ENDTYPE = \"CRLF\"\n#Else\n\t#WRITE_LINE_ENDTYPE = \"LF\"\n#End\n\n' Imports (Public):\nImport autostream\n\nImport byteorder\nImport imagedimensions\nImport retrostrings\nImport stringutil\nImport vector\n\n#If CONSOLE_IMPLEMENTED\n\tImport console\n#End\n\nImport sizeof\nImport time\n\n#If Not BRL_GAMETARGET_IMPLEMENTED\n\tImport mojoemulator\n#End\n\n' Imports (Private):\nPrivate\n\n' Unofficial:\n#If UTIL_SUPPORT_IOELEMENTS\n\tImport ioelement\n#End\n\n' Official:\n\n' BRL:\nImport brl.databuffer\nImport brl.stream\nImport brl.filepath\n\nPublic\n\n' Constant variable(s):\n\n' Type codes (Mainly used for generic classes):\nConst TYPE_OBJECT:Int\t\t\t= 0\nConst TYPE_INT:Int\t\t\t\t= 1\nConst TYPE_BOOL:Int\t\t\t\t= 2\nConst TYPE_FLOAT:Int\t\t\t= 3\nConst TYPE_STRING:Int\t\t\t= 4\n\n' Ascii codes:\nConst ASCII_CARRIAGE_RETURN:Int = 13\nConst ASCII_LINE_FEED:Int = 10\n\n' Used mainly for external code where '-9999...' isn't ever going to be valid.\n' You should stick to 'Null' in most cases; try not to use this.\nConst NOVAR:Int = -999999\n\n' This is for situations where the length of something can be optional.\nConst AUTOMATIC_LENGTH:Int = -1\n\nConst ErrorTemplate:String = \"[ERROR] {Debug}: \" ' + Space\nConst LogTemplate:String = \"[Info] {Debug}: \" ' + Space\n\n' Global variable(s) (Public):\n#If CONSOLE_IMPLEMENTED\n\tGlobal DebugConsole:Console = Null\n#End\n\n' A global stack logging randomization seeds.\n' This is commonly accessed by the 'PushSeed' and 'PopSeed' functions.\nGlobal SeedStack:Stack = Null\n\n' Global variable(s) (Private):\nPrivate\n\n' Nothing so far.\n\nPublic\n\n' Functions:\nFunction FLAG:Int(ID:Int)\n\tReturn Pow(2, ID)\nEnd\n\n' This command is little-endian only:\nFunction AsByte:Int(I:Int)\n\tReturn ((I Shl 24) Shr 24)\nEnd\n\n' This command treats data as 8-bit (Turns something like $F7, into $FFFFFFF7)\n' This is only applied on little-endian systems,\n' please use this command for hex values (Monkey converts hex on compile-time).\nFunction PaddedHex:Int(I:Int)\n\tIf (Not BigEndian()) Then\n\t\tReturn AsByte(I)\n\tEndif\n\t\n\tReturn I\nEnd\n\nFunction Transfer:Bool(InputStream:Stream, OutputStream:Stream, DataSize:Int)\n\t' Check for errors:\n\tIf (DataSize = 0) Then Return False\n\tIf (InputStream = Null Or InputStream.Eof()) Then Return False\n\tIf (OutputStream = Null) Then Return False\n\t\n\t' Local variable(s):\n\t#If FLAG_TEMP_BUFFERS\n\t\tLocal Data:DataBuffer = New DataBuffer(DataSize)\n\t\tLocal DataLength:= DataSize ' Data.Length()\n\t\t\n\t\t' Read from the input-stream, then write to the output-stream:\n\t\tInputStream.Read(Data, 0, DataLength)\n\t\tOutputStream.Write(Data, 0, DataLength)\n\t\t\n\t\tData.Discard()\n\t#Else\n\t\t'Local Data:Int[DataSize]\n\t\t\n\t\tFor Local I:Int = 1 To DataSize ' Data.Length()\n\t\t\tOutputStream.WriteByte(InputStream.ReadByte())\n\t\tNext\n\t#End\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\nFunction Sq:Float(Input:Float)\n\tReturn Pow(Input, 2.0) ' Input * Input\nEnd\n\nFunction Sq:Int(Input:Int)\n\tReturn Pow(Input, 2)\nEnd\n\nFunction WrapAngle:Float(A:Float)\n\tWhile (A < 0.0)\n\t\tA += 360.0\n\tWend\n\t\n\tWhile (A > 360.0)\n\t\tA -= 360.0\n\tWend\n\t\n\tReturn A\nEnd\n\nFunction WrapColor:Float(C:Float)\n\t#Rem\n\tWhile (C < 0.0)\n\t\tC += 255.0\n\tWend\n\t\n\tWhile (C > 255.0)\n\t\tC -= 255.0\n\tWend\n\t#End\n\t\n\tReturn C Mod 256.0\nEnd\n\n' This command is a helper function for \nFunction ProcessColorLocation:Int(Point:Int)\n\t' Check for errors:\n\tIf (Point < 0) Then\n\t\tReturn 0\n\tEndif\n\t\n\tReturn (SizeOf_Integer_InBits-(SizeOf_Octet_InBits*(Point+1))) ' ((SizeOf_Integer_InBits-SizeOf_Octet_InBits)-(SizeOf_Octet_InBits*Point))\nEnd\n\n' NOTE: This command will produce incorrect color values without all characters present in the encode-string.\nFunction ColorToString:String(Pixel:Int, Encoding:String=\"ARGB\")\n\t' Ensure the encoding is always described as uppercase.\n\tEncoding = Encoding.ToUpper()\n\t\n\t' Return the encoded color-string.\n\tReturn (\"R: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"R\"))) & $000000FF) +\n\t\t\t\", G: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"G\"))) & $000000FF) +\n\t\t\t\", B: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"B\"))) & $000000FF) +\n\t\t\t\", A: \" + ((Pixel Shr ProcessColorLocation(Encoding.Find(\"A\"))) & $000000FF))\nEnd\n\nFunction PrintColor:Void(Pixel:Int, Encoding:String=\"ARGB\")\n\tPrint(ColorToString(Pixel, Encoding))\n\t\n\tReturn\nEnd\n\n' This is just a wrapper for the main implementation:\nFunction PushSeed:Bool()\n\tReturn PushSeed(Seed)\nEnd\n\n' The return value of this function specifies if the seed-stack already existed.\nFunction PushSeed:Bool(Seed:Int)\n\t' Local variable(s):\n\tLocal Response:Bool = (SeedStack <> Null)\n\t\n\tIf (Not Response) Then\n\t\tSeedStack = New IntStack()\n\tEndif\n\t\n\tSeedStack.Push(Seed)\n\t\n\t' Return the calculated response.\n\tReturn Response\nEnd\n\n' This command retrieves a seed from the seed-stack,\n' if no seed exists, the current randomization seed is returned.\nFunction PopSeed:Int()\n\tIf (SeedStack <> Null) Then\n\t\tIf (Not SeedStack.IsEmpty()) Then\n\t\t\tReturn SeedStack.Pop()\n\t\tEndif\n\tEndif\n\t\n\t' Return the default response.\n\tReturn Seed\nEnd\n\n' This command writes a standard line to a 'Stream'.\n' This supports both 'LF', and 'CRLF' line endings currently, and this can be configured with 'WRITE_LINE_ENDTYPE'.\n' Though character encoding is supported with this, only ASCII is supported by 'ReadLine'.\nFunction WriteLine:Bool(S:Stream, Line:String, CharacterEncoding:String=\"ascii\")\n\t' Check for errors:\n\tIf (S = Null) Then\n\t\tReturn False\n\tEndif\n\t\n\tS.WriteString(Line, CharacterEncoding)\n\t\n\t#If WRITE_LINE_ENDTYPE = \"CRLF\"\n\t\tS.WriteByte(ASCII_CARRIAGE_RETURN)\n\t#End\n\t\n\tS.WriteByte(ASCII_LINE_FEED)\n\t\n\t' Return the default response.\n\tReturn True\nEnd\n\n' This command reads a standard line from a 'Stream'. (This supports both 'LF', and 'CRLF' line endings currently)\n' In addition, only 'ASCII' is currently supported.\nFunction ReadLine:String(S:Stream)\n\t' Local variable(s):\n\tLocal Position:= S.Position()\n\tLocal Padding:Int = 0 ' * SizeOf_Char\n\tLocal Str:String\n\t\n\t#If Not READ_LINE_QUICKLY\n\t\tLocal Size:Int = 0\n\t#End\n\t\n\tWhile (Not S.Eof())\n\t\tLocal Char:= S.ReadByte()\n\t\t\n\t\tIf (Char <> ASCII_LINE_FEED) Then\n\t\t\tIf (Char <> ASCII_CARRIAGE_RETURN) Then\n\t\t\t\t#If READ_LINE_QUICKLY\n\t\t\t\t\tStr += String.FromChar(Char)\n\t\t\t\t#Else\n\t\t\t\t\tSize += 1\n\t\t\t\t#End\n\t\t\tElse\n\t\t\t\tPadding = 2*SizeOf_Char\n\t\t\tEndif\n\t\tElse\n\t\t\t#Rem\n\t\t\t\tIf (Padding = 0) Then\n\t\t\t\t\tPadding = 1\n\t\t\t\tEndif\n\t\t\t#End\n\t\t\t\n\t\t\tPadding = Max(Padding, 1*SizeOf_Char)\n\t\t\t\n\t\t\tExit\n\t\tEndif\n\tWend\n\t\n\t#If Not READ_LINE_QUICKLY\n\t\tS.Seek(Position)\n\t\t\n\t\tStr = S.ReadString(Size, \"ascii\")\n\t\t\n\t\tS.Seek(S.Position()+Padding)\n\t#End\n\t\n\t' Return the string we read from the stream.\n\tReturn Str\nEnd\n\nFunction ResizeBuffer:DataBuffer(Buffer:DataBuffer, Size:Int=AUTOMATIC_LENGTH, CopyData:Bool=True, DiscardOldBuffer:Bool=False, OnlyWhenDifferentSizes:Bool=False)\n\tLocal BufferAvailable:Bool = (Buffer <> Null)\n\t\n\tIf (BufferAvailable And OnlyWhenDifferentSizes) Then\n\t\tIf (Size <> AUTOMATIC_LENGTH And Buffer.Length() = Size) Then\n\t\t\tReturn Buffer\n\t\tEndif\n\tEndif\n\t\n\tIf (Size = AUTOMATIC_LENGTH) Then\n\t\tSize = Buffer.Length()\n\tEndif\n\t\n\t' Allocate a new data-buffer.\n\tLocal B:= New DataBuffer(Size)\n\t\n\t' Copy the buffer's bytes over to 'B'.\n\tIf (BufferAvailable) Then\n\t\tIf (CopyData) Then\n\t\t\t' Copy the contents of 'Buffer' to the newly generated buffer-object.\n\t\t\tBuffer.CopyBytes(0, B, 0, Buffer.Length())\n\t\tEndif\n\t\t\n\t\tIf (DiscardOldBuffer) Then\n\t\t\t' Discard the old buffer.\n\t\t\tBuffer.Discard()\n\t\tEndif\n\tEndif\n\t\n\t' Return the newly generated buffer.\n\tReturn B\nEnd\n\n#If CONSOLE_IMPLEMENTED\n\tFunction DebugBind:Bool(C:Console)\n\t\tIf (C = Null) Then Return False\n\t\t\n\t\tDebugConsole = C\n\t\t\n\t\t' Return the default response.\n\t\tReturn True\n\tEnd\n#End\n\nFunction DebugError:Void(E:Throwable, StopExecution:Bool=True)\n\t#If CONFIG = \"debug\"\n\t\tDebugStop()\n\t#Else\n\t\tDebugPrint(\"Unknown exception has been thrown; continuing anyway.\")\n\t#End\n\t\n\tReturn\nEnd\n\nFunction DebugError:Void(Msg:String, StopExecution:Bool=True)\n\t#If DEBUG_PRINT\n\t\t' Local variable(s):\n\t\tLocal TempMsg:String\n\t\t\n\t\tIf (StopExecution) Then\n\t\t\tTempMsg = ErrorTemplate\n\t\tElse\n\t\t\tTempMsg = LogTemplate\n\t\tEndif\n\t\t\n\t\t#If DEBUG_PRINT_QUOTES\t\t\t\n\t\t\tMsg = Tempmsg + Quote + Msg + Quote\n\t\t#Else\n\t\t\tMsg = TempMsg + Msg\n\t\t#End\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\tDebugConsole.WriteLine(Msg, True)\n\t\t\tElse\n\t\t#End\n\t\t\n\t\tPrint(Msg)\n\t\t\n\t\t#If CONSOLE_IMPLEMENTED\n\t\t\tEndif\n\t\t#End\n\t#Else\n\t\t' This may change later:\n\t\tIf (StopExecution) Then\n\t\t\tMsg = ErrorTemplate + Msg\n\t\tEndif\n\t#End\n\n\tIf (StopExecution) Then\n\t\t#If CONFIG = \"debug\"\n\t\t\t#If DEBUG_PRINT_ON_ERROR\n\t\t\t\tDebugStop()\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#Else\n\t\t\t#If DEBUG_PRINT\n\t\t\t\tLocal FinalStr:String = (ErrorTemplate + Quote + \"Attempt to stop execution failed. (Reason: Release-mode)\" + Quote)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tIf (DebugConsole <> Null) Then\n\t\t\t\t\t\tDebugConsole.WriteLine(FinalStr, True)\n\t\t\t\t\tElse\n\t\t\t\t#End\n\t\t\t\t\n\t\t\t\tPrint(FinalStr)\n\t\t\t\t\n\t\t\t\t#If CONSOLE_IMPLEMENTED\n\t\t\t\t\tEndif\n\t\t\t\t#End\n\t\t\t#Else\n\t\t\t\tError(Msg)\n\t\t\t#End\n\t\t#End\n\tEndif\n\t\n\t#If CONFIG = \"debug\"\n\t\t' Nothing so far.\n\t#Else\n\t\t' Nothing so far.\n\t#End\n\n\tReturn\nEnd\n\nFunction DebugPrint:Void(Str:String, StopExecution:Bool=False)\n\tDebugError(Str, StopExecution)\n\n\tReturn\nEnd\n\n' The following functions are designed to be used with generic classes:\nFunction IsObject:Bool(O:Object)\n\tReturn True\nEnd\n\nFunction IsObject:Bool(I:Int)\n\tReturn False\nEnd\n\nFunction IsObject:Bool(B:Bool)\n\tReturn False\nEnd\n\nFunction IsObject:Bool(F:Float)\n\tReturn False\nEnd\n\nFunction IsObject:Bool(S:String)\n\tReturn False\nEnd\n\nFunction TypeOf:Int(O:Object)\n\tReturn TYPE_OBJECT\nEnd\n\nFunction TypeOf:Int(I:Int)\n\tReturn TYPE_INT\nEnd\n\nFunction TypeOf:Int(B:Bool)\n\tReturn TYPE_BOOL\nEnd\n\nFunction TypeOf:Int(F:Float)\n\tReturn TYPE_FLOAT\nEnd\n\nFunction TypeOf:Int(S:String)\n\tReturn TYPE_STRING\nEnd\n\n' Classes:\nClass GenericUtilities\n\t' Constant variable(s):\n\t\n\t' Comparison response codes (Positive numbers are for error-reporting):\n\tConst COMPARE_RESPONSE_IDENTICAL:Int\t\t\t= -1\n\tConst COMPARE_RESPONSE_WRONG_LENGTH:Int\t\t\t= -2\n\t\n\t' Other:\n\tConst AUTO:Int = -1\n\t\n\t' Global variable(s):\n\t\n\t' For internal and extern use. That being said, please do not modify this value.\n\tGlobal NIL:T\n\t\n\t' Functions:\n\t\n\t' This command gives the user the type-code of 'T'.\n\tFunction Type:Int()\n\t\t' Return the type code of 'NIL'.\n\t\tReturn TypeOf(NIL)\n\tEnd\n\t\n\t' This command specifies if 'T' is an object.\n\tFunction IsObject:Bool()\n\t\tReturn util.IsObject(NIL)\n\tEnd\n\t\n\t' This command wraps the standard 'BoolToString' conversion command.\n\tFunction AsString:String(Input:Bool)\n\t\tReturn BoolToString(Input)\n\tEnd\n\t\n\t' This command reads a string from a standard 'Stream' object.\n\tFunction AsString:String(S:Stream, Length:Int=AUTO, Encoding:String=\"utf8\")\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = S.Length()\n\t\tEndif\n\t\t\n\t\tReturn S.ReadString(Length, Encoding)\n\tEnd\n\t\n\tFunction AsString:String(Input:T[], Offset:Int=0, Length:Int=AUTO, AddSpaces:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal Output:String = LeftBracket\n\t\t\n\t\t' If no length was specified, use the array's length.\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Input.Length()\n\t\tEndif\n\t\t\n\t\tLocal VirtualLength:= Length+Offset\n\t\t\n\t\tFor Local Index:Int = Offset Until VirtualLength\n\t\t\tOutput += Input[Index]\n\t\t\t\n\t\t\tIf (Index+1 < VirtualLength) Then\n\t\t\t\tOutput += Comma\n\t\t\t\t\n\t\t\t\tIf (AddSpaces) Then\n\t\t\t\t\tOutput += Space\n\t\t\t\tEndif\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\tReturn Output + RightBracket\n\tEnd\n\t\n\tFunction CopyStringToArray:T[](S:String, Input:T[], Offset:Int=0, Length:Int=AUTO)\n\t\tIf (Length = AUTO) Then\n\t\t\tLength = Min(S.Length(), Input.Length())\n\t\tEndif\n\t\t\n\t\tFor Local I:Int = Offset Until Length\n\t\t\tInput[I] = S[I]\n\t\tNext\n\t\t\n\t\t' Just for the sake of convenience, return the 'Input' array.\n\t\tReturn Input\n\tEnd\n\t\n\tFunction IndexOfList:T(L:List, Index:Int=0)\n\t\t' Local variable(s):\n\t\tLocal Data:list.Node = L.FirstNode()\n\t\t\t\t\n\t\tFor Local I:= 0 Until Index\n\t\t\tData = Data.NextNode()\n\t\t\t\n\t\t\t' Not my favorite method, but it works:\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn NIL\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the value of the assessed node.\n\t\tReturn Data.Value()\n\tEnd\n\t\n\tFunction Zero:T[](Input:T[])\n\t\tReturn Nil(Input)\n\tEnd\n\t\n\tFunction Nil:T[](Input:T[])\n\t\tFor Local Index:= 0 Until Input.Length()\n\t\t\tInput[Index] = NIL\n\t\tNext\n\t\t\n\t\tReturn Input\n\tEnd\n\t\n\tFunction PrintArray:Void(Input:T[])\n\t\tPrint(AsString(Input))\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\t\tNOTES:\n\t\t\t* In the event of an error, an empty array will be produced.\n\t\t\t\n\t\t\t* The 'CopyArray' command's 'FitSource' argument should only be enabled with the\n\t\t\tknowledge that the original destination may have been discarded.\n\t\t\t\n\t\t\tYour code must reflect this by disregarding the original array,\n\t\t\tand simply assigning the old array to the retrun value.\n\t\t\t\n\t\t\tEXAMPLE:\n\t\t\t\t' Local variable(s):\n\t\t\t\tLocal A:T[10], A2:T[3]\n\t\t\t\t\n\t\t\t\t' This will likely produce a new 'T' array, based on the area-delta.\n\t\t\t\tA2 = CopyArray(A, A2, True)\n\t#End\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], FitSource:Bool=False)\n\t\tReturn CopyArray(Source, Destination, 0, 0, AUTO, AUTO, FitSource)\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[], Destination:T[], Source_Offset:Int=0, Destination_Offset:Int=0, Source_Length:Int=AUTO, Destination_Length:Int=AUTO, FitSource:Bool=False)\n\t\tIf (Source_Length = AUTO) Then\n\t\t\tSource_Length = Source.Length()\n\t\tEndif\n\t\t\n\t\tIf (Destination_Length = AUTO) Then\n\t\t\tDestination_Length = Destination.Length()\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\t\n\t\t' These two are used as caches for the real lengths of the arrays:\n\t\tLocal Destination_RealLength:= Destination.Length()\n\t\tLocal Source_RealLength:= Source.Length()\n\t\t\n\t\t' Calculate the source and destination areas:\n\t\tLocal Source_Area:Int = (Source_Length-Source_Offset)\n\t\t\n\t\t' Make sure we have a source to work with:\n\t\tIf (Source_Area <= 0) Then\n\t\t\t' The source-area is too small for use, return an empty array.\n\t\t\tReturn []\n\t\tEndif\n\t\t\n\t\tLocal Destination_Area:Int = (Destination_Length-Destination_Offset)\n\t\t\n\t\t' For the sake of safety, we'll also check the destination area:\n\t\tIf (Destination_Area <= 0) Then\n\t\t\t' The destination-area is too small for use, return an empty array.\n\t\t\tReturn []\n\t\tEndif\n\t\t\n\t\tLocal Operation_Area:Int\n\t\t\n\t\tIf (FitSource And Destination_Area < Source_Area) Then\n\t\t\tLocal AreaDelta:Int = (Source_Area-Destination_Area)\n\t\t\tLocal NewArea:Int = (Destination_RealLength+AreaDelta)\n\t\t\t\n\t\t\tIf (NewArea > Destination_RealLength) Then\n\t\t\t\tDestination = Destination.Resize(NewArea)\n\t\t\tElse\n\t\t\t\tDestination = Destination.Resize(Destination_Length+AreaDelta)\n\t\t\tEndif\n\t\t\t\n\t\t\tDestination_Area = Source_Area\n\t\t\tOperation_Area = Destination_Area\n\t\tElse\n\t\t\tOperation_Area = Min(Source_Area, Destination_Area)\n\t\tEndif\n\t\t\n\t\t' Copy the contents of the source-array into the destination-array:\n\t\tFor Local Index:= 0 Until Operation_Area\n\t\t\tDestination[Index+Destination_Offset] = Source[Index+Source_Offset]\n\t\tNext\n\t\t\n\t\t' Return the destination-array.\n\t\tReturn Destination\n\tEnd\n\t\n\tFunction CopyArray:T[](Source:T[])\n\t\tReturn CloneArray(Source)\n\tEnd\n\t\n\tFunction CloneArray:T[](Source:T[])\n\t\tReturn CopyArray(Source, New T[Source.Length()])\n\tEnd\n\t\n\t' This command returns a positive number upon an error,\n\t' otherwise a 'response code' will be given (See the \"Contant variable(s)\" section for details).\n\tFunction Compare:Int(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal A1_Length:= A1.Length\n\t\tLocal A2_Length:= A2.Length\n\t\t\n\t\t' Check for errors:\n\t\tIf (CheckLength) Then\n\t\t\t' Make sure they're both the same length.\n\t\t\tIf (A1_Length <> A2_Length) Then\n\t\t\t\tReturn COMPARE_RESPONSE_WRONG_LENGTH\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tFor Local I:= 0 Until Min(A1_Length, A2_Length)\n\t\t\tIf (A1[I] <> A2[I]) Then\n\t\t\t\t' Not the best of escape methods, but it works.\n\t\t\t\tReturn I\n\t\t\tEndif\n\t\tNext\n\t\t\n\t\t' Return the default response.\n\t\tReturn COMPARE_RESPONSE_IDENTICAL\n\tEnd\n\t\n\t' This function returns positive if both arrays are identical.\n\tFunction SimpleCompare:Bool(A1:T[], A2:T[], CheckLength:Bool=True)\n\t\tReturn (Compare(A1, A2, CheckLength) = COMPARE_RESPONSE_IDENTICAL)\n\tEnd\n\t\n\tFunction Read:T(S:Stream)\n\t\tReturn Read(S, NIL)\n\tEnd\n\t\t\n\tFunction Read:T[](S:Stream, DataArray:T[], Size:Int=AUTO)\n\t\tIf (Size = AUTO) Then Size = S.ReadInt()\n\t\t\n\t\tIf (Size > 0) Then\n\t\t\tIf (DataArray.Length() = 0) Then\n\t\t\t\tDataArray = New T[Size]\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\t' Local variable(s):\n\t\tLocal DLength:Int = Min(DataArray.Length, Size)\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tDataArray[Index] = Read(S, NIL)\n\t\tNext\n\t\t\n\t\tReturn DataArray\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, DataArray:T[], WriteLength:Bool=True)\n\t\t' Local variable(s):\n\t\tLocal DLength:= DataArray.Length()\n\t\t\n\t\tIf (WriteLength) Then S.WriteInt(DLength)\n\t\t\n\t\tFor Local Index:= 0 Until DLength\n\t\t\tWrite(S, DataArray[Index])\n\t\tNext\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:Int(S:Stream, Indentifier:Int, Size:Int=4)\n\t\t' Local variable(s):\n\t\tLocal Data:Int = 0\n\t\t\n\t\tIf (Size > 1) Then\n\t\t\tIf (Size < 4) Then\n\t\t\t\tData = S.ReadShort()\n\t\t\tElse\n\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\tS.ReadInt()\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tData = S.ReadInt()\n\t\t\tEndif\n\t\tElse\n\t\t\tData = S.ReadByte()\n\t\tEndif\n\t\t\n\t\tReturn Data\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:Int, Size:Int=4)\n\t\tSize = IntSize(Size)\n\t\t\n\t\tIf (Size > 1) Then\n\t\t\tIf (Size < 4) Then\n\t\t\t\tS.WriteShort(Data)\n\t\t\tElse\n\t\t\t\tIf (Size > 4) Then\n\t\t\t\t\tS.WriteInt(0)\n\t\t\t\tEndif\n\t\t\t\t\n\t\t\t\tS.WriteInt(Data)\n\t\t\tEndif\n\t\tElse\n\t\t\tS.WriteByte(Data)\n\t\tEndif\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#Rem\n\tFunction Read:Bool(S:Stream, Identifier:Bool)\n\t\tReturn Read(S, Int(Identifier), 1)\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, B:Bool)\n\t\tWrite(S, Int(B), 1)\n\t\t\n\t\tReturn\n\tEnd\n\t#End\n\t\n\tFunction Read:Float(S:Stream, Identifier:Float)\t\t\n\t\tReturn S.ReadFloat()\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:Float)\n\t\tS.WriteFloat(Data)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tFunction Read:String(S:Stream, Data:String, Encoding:String=\"utf8\", Size:Int=AUTO)\n\t\tIf (Size = AUTO) Then\n\t\t\tSize = S.ReadInt()\n\t\tEndif\n\t\t\n\t\tData = S.ReadString(Size, Encoding)\n\t\t\n\t\t' Return the newly read string.\n\t\tReturn Data\n\tEnd\n\t\n\tFunction Write:Void(S:Stream, Data:String, Encoding:String=\"utf8\", WriteSize:Bool=True)\n\t\tIf (WriteSize) Then\n\t\t\tS.WriteInt(Data.Length())\n\t\tEndif\n\t\t\n\t\tS.WriteString(Data, Encoding)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t#If UTIL_SUPPORT_IOELEMENTS\n\t\tFunction Read:Void(S:Stream, Data:InputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Load(S)\n\t\t\t\n\t\t\tReturn\n\t\tEnd\n\t\t\n\t\tFunction Write:Void(S:Stream, Data:OutputChildElement)\n\t\t\tIf (Data = Null) Then\n\t\t\t\tReturn\n\t\t\tEndif\n\t\t\t\n\t\t\tData.Save(S)\n\t\tEnd\n\t#End\n\t\n\t' Constructor(s):\n\t\n\t' DO NOT CREATE NEW INSTANCES OF THIS CLASS.\n\tMethod New()\n\t\tDebugError(\"This class should not be used in this was.\")\n\tEnd\nEnd","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"6edd9222919b87ad0410ad174b3e4ac65eb171e4","subject":"Added quitApp global flag to help quitting with Win8 apps.","message":"Added quitApp global flag to help quitting with Win8 apps.\n","repos":"programmerby\/diddy-mirror,programmerby\/diddy-mirror,programmerby\/diddy-mirror,programmerby\/diddy-mirror","old_file":"src\/diddy\/framework.monkey","new_file":"src\/diddy\/framework.monkey","new_contents":"#Rem\nCopyright (c) 2011 Steve Revill and Shane Woolcock\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n#End\n\n#rem\nHeader: The Screen-Based Diddy Game Framework\nThis framework allows developers to quickly build screens and move between them quickly.\nAlso included are image and sound resource managers, a delta timer, sprite and particle classes.\nExample of how to set up the DiddyApp:\n[code]\nStrict\n\nImport diddy\n\nFunction Main:Int()\n\tNew MyGame()\n\tReturn 0\nEnd\n\nGlobal titleScreen:TitleScreen\n\nClass MyGame extends DiddyApp\n\tMethod Create:Void()\n\t\ttitleScreen = New TitleScreen\n\t\tStart(titleScreen)\n\tEnd\nEnd\n\nClass TitleScreen Extends Screen\n\tMethod New()\n\t\tname = \"Title\"\n\tEnd\n\t\n\tMethod Start:Void()\n\t\t' Load and set up items here\n\tEnd\n\t\n\tMethod Render:Void()\n\t\tCls\n\t\tDrawText \"TITLE SCREEN!\", SCREEN_WIDTH2, SCREEN_HEIGHT2, 0.5, 0.5\n\t\tDrawText \"Escape to Quit!\", SCREEN_WIDTH2, SCREEN_HEIGHT2 + 40, 0.5, 0.5\n\tEnd\n\t\n\tMethod Update:Void()\n\t\tIf KeyHit(KEY_ESCAPE)\n\t\t\t' fading to Null is the same as fading to diddyGame.exitScreen (which exits the game)\n\t\t\tFadeToScreen(Null)\n\t\tEnd\n\tEnd\nEnd\n[\/code]\n#End\nStrict\n\nImport mojo\nImport functions\nImport collections\nImport inputcache\nImport xml\nImport diddydata\n\n'Device width and height\nGlobal DEVICE_WIDTH:Float\nGlobal DEVICE_HEIGHT:Float\n\n' Screen width and height\nGlobal SCREEN_WIDTH:Float\nGlobal SCREEN_HEIGHT:Float\n\n' Half of SCREEN_WIDTH and HEIGHT\nGlobal SCREEN_WIDTH2:Float\nGlobal SCREEN_HEIGHT2:Float\n\n' Used for Virtual Res\nGlobal SCREENX_RATIO:Float = 1\nGlobal SCREENY_RATIO:Float = 1\n\n' THE GAME!!\nGlobal diddyGame:DiddyApp\n\n' Used for delta timing movement\nGlobal dt:DeltaTimer\n\n' Default fade time\nGlobal defaultFadeTime:Float = 600\n\r\n' quit flag to exit the app via OnBack\r\nGlobal quitApp:Bool = False\r\n\n'Summary: The main class extends Mojo App\nClass DiddyApp Extends App\n\n\tField debugKeyOn:Bool = False\n\tField debugOn:Bool = False\n\tField drawFPSOn:Bool = False\n\tField debugKey:Int = KEY_F1\n\t\n\tField virtualResOn:Bool = True\n\tField aspectRatioOn:Bool = False\n\tField autoCls:Bool = False\n\n\tField aspectRatio:Float\n\tField multi:Float\n\tField widthBorder:Float\t\t\t\t' Size of border at sides\n\tField heightBorder:Float\t\t\t' Size of border at top\/bottom\n\t\n\tField deviceChanged:Int\t\t\t\t' Device size changed\n\tField virtualScaledW:Float\n\tField virtualScaledH:Float\n\tField virtualXOff:Float\n\tField virtualYOff:Float\n\t\n\tField FPS:Int = 60\n\t\n\t' current Screen\n\tField currentScreen:Screen\n\t' next Screen\n\tField nextScreen:Screen\n\t' exit Screen\n\tField exitScreen:ExitScreen\n\t' used for fading\n\tField screenFade:ScreenFade\n\t' scroll\n\tField scrollX:Float\n\tField scrollY:Float\n\t\n\t' mouse\n\tField mouseX:Int, mouseY:Int\n\tField mouseHit:Int\n\tField diddyMouse:DiddyMouse\n\t\n\t' store the images here\n\tField images:ImageBank\n\t' store the sounds here\n\tField sounds:SoundBank\n\t' store screens\n\tField screens:Screens\n\t\n\t' volume control\n\tField musicFile:String = \"\"\n\tField soundVolume:Int = 100\n\tField musicVolume:Int = 100\n\tField mojoMusicVolume:Float = 1.0\n\tField musicOkay:Int\n\t\n\tField clickSound:GameSound\n\t\n\t' input\n\tField inputCache:InputCache\n\n\t' fixed rate logic stuff\n\tField frameRate:Float = 200 ' speed the logic runs at\n\tField ms:Float = 0 ' milliseconds per frame eg 1000ms\/200framerate = 5ms per frame\n\tField tmpMs:Float\n\tField numTicks:Float\n\tField lastNumTicks:Float\n\tField maxMs:Int = 50\n\tField lastTime:Float\n\t\n\tField diddyData:DiddyData\n\t\nPrivate\n\tField useFixedRateLogic:Bool = False\n\tField vsx:Float, vsy:Float, vsw:Float, vsh:Float\n\t\nPublic\n\tMethod New()\n\t\t' DiddyApp now assigns itself to game, so you just need to do: New MyGame()\n\t\t' Assigning it manually will have no effect, but won't break anything.\n\t\tdiddyGame = Self\n\t\tSelf.screens = New Screens\n\t\tSelf.exitScreen = New ExitScreen\n\t\tSelf.screenFade = New ScreenFade\n\t\tSelf.images = New ImageBank\n\t\tSelf.sounds = New SoundBank\n\t\tSelf.inputCache = New InputCache\n\t\tdiddyMouse = New DiddyMouse\n\tEnd\n\t\t\t\n\tMethod OnCreate:Int()\n\t\tTry\n\t\t\t' Store the device width and height\n\t\t\tDEVICE_WIDTH = DeviceWidth()\n\t\t\tDEVICE_HEIGHT = DeviceHeight()\n\t\t\t\n\t\t\tSetScreenSize(DEVICE_WIDTH, DEVICE_HEIGHT)\n\t\t\tdeviceChanged = True\n\t\t\t\n\t\t\t' set the mouse x,y\n\t\t\tmouseX = MouseX() \/ SCREENX_RATIO\n\t\t\tmouseY = MouseY() \/ SCREENY_RATIO\n\t\t\t\n\t\t\t' Set the Random seed\n\t\t\tSeed = RealMillisecs()\n\t\t\t' Create the delta timer\n\t\t\tdt = New DeltaTimer(FPS)\n\t\t\t' Set the update rate\n\t\t\tSetUpdateRate FPS\n\t\t\t\n\t\t\t'create all the particles\n\t\t\tParticle.Cache()\n\t\t\t\n\t\t\t' fixed rate logic timing\n\t\t\tIf useFixedRateLogic\n\t\t\t\tResetFixedRateLogic()\n\t\t\tEnd\n\t\t\t\n\t\t\t'call Create\n\t\t\tCreate()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\t'summary: Main creation method\n\tMethod Create:Void()\n\tEnd\n\t\n\t'summary: Sets up the virtual resolution\n\tMethod SetScreenSize:Void(w:Float, h:Float, useAspectRatio:Bool = False)\n\t\tSCREEN_WIDTH = w\n\t\tSCREEN_HEIGHT = h\n\t\tSCREEN_WIDTH2 = SCREEN_WIDTH \/ 2\n\t\tSCREEN_HEIGHT2 = SCREEN_HEIGHT \/ 2\n\t\t\n\t\tSCREENX_RATIO = DEVICE_WIDTH\/SCREEN_WIDTH\n\t\tSCREENY_RATIO = DEVICE_HEIGHT\/SCREEN_HEIGHT\n\t\t\n\t\tIf SCREENX_RATIO <> 1 Or SCREENY_RATIO <> 1\n\t\t\tvirtualResOn = True\n\t\t\taspectRatioOn = useAspectRatio\n\t\t\taspectRatio = h \/ w\n\t\tEnd\n\t\tIf DeviceWidth() <> SCREEN_WIDTH Or DeviceHeight() <> SCREEN_HEIGHT Then\n\t\t\tdeviceChanged = True\n\t\tEnd\n\tEnd\n\n\tMethod OnRender:Int()\n\t\tTry\n\t\t\tFPSCounter.Update()\n\t\t\tIf virtualResOn\n\t\t\t\tPushMatrix\n\t\t\t\tIf aspectRatioOn\n\t\t\t\t\tIf (DeviceWidth() <> DEVICE_WIDTH) Or (DeviceHeight() <> DEVICE_HEIGHT) Or deviceChanged\n\t\t\t\t\t\tDEVICE_WIDTH = DeviceWidth()\n\t\t\t\t\t\tDEVICE_HEIGHT = DeviceHeight()\n\t\t\t\t\t\tdeviceChanged = False\n\n\t\t\t\t\t\tLocal deviceRatio:Float = DEVICE_HEIGHT \/ DEVICE_WIDTH\n\t\t\t\t\t\tIf deviceRatio >= aspectRatio\n\t\t\t\t\t\t\tmulti = DEVICE_WIDTH \/ SCREEN_WIDTH\n\t\t\t\t\t\t\theightBorder = (DEVICE_HEIGHT - SCREEN_HEIGHT * multi) * 0.5\n\t\t\t\t\t\t\twidthBorder = 0\n\t\t\t\t\t\tElse\n\t\t\t\t\t\t\tmulti = DEVICE_HEIGHT \/ SCREEN_HEIGHT \n\t\t\t\t\t\t\twidthBorder = (DEVICE_WIDTH - SCREEN_WIDTH * multi) * 0.5\n\t\t\t\t\t\t\theightBorder = 0\n\t\t\t\t\t\tEnd\n\t\t\t\t\t\n\t\t\t\t\t\tvsx = Max(0.0, widthBorder )\n\t\t\t\t\t\tvsy = Max(0.0, heightBorder )\n\t\t\t\t\t\tvsw = Min(DEVICE_WIDTH - widthBorder * 2.0, DEVICE_WIDTH)\n\t\t\t\t\t\tvsh = Min(DEVICE_HEIGHT- heightBorder * 2.0, DEVICE_HEIGHT)\n\t\t\t\t\t\t\n\t\t\t\t\t\tvirtualScaledW = (SCREEN_WIDTH * multi)\n\t\t\t\t\t\tvirtualScaledH = (SCREEN_HEIGHT * multi)\n\t\t\t\t\t\t\n\t\t\t\t\t\tvirtualXOff = (DEVICE_WIDTH - virtualScaledW) * 0.5\n\t\t\t\t\t\tvirtualYOff = (DEVICE_HEIGHT - virtualScaledH) * 0.5\n\t\t\t\t\t\t\n\t\t\t\t\t\tvirtualXOff = virtualXOff \/ multi\n\t\t\t\t\t\tvirtualYOff = virtualYOff\/ multi\n\t\t\t\t\tEnd\n\t\t\t\t\t\n\t\t\t\t\tSetScissor 0, 0, DEVICE_WIDTH , DEVICE_HEIGHT \n\t\t\t\t\tCls 0, 0, 0\n\t\t\t\t\t\n\t\t\t\t\tSetScissor vsx, vsy, vsw, vsh\n\t\t\n\t\t\t\t\tScale multi, multi\n\n\t\t\t\t\tTranslate virtualXOff, virtualYOff \n\t\t\t\tElse\n\t\t\t\t\tScale SCREENX_RATIO, SCREENY_RATIO\n\t\t\t\tEnd\n\t\t\tEnd\n\t\t\t\n\t\t\t' auto cls\n\t\t\tIf autoCls Then Cls()\n\t\t\t\n\t\t\t' render the screen\n\t\t\tcurrentScreen.RenderBackgroundLayers()\n\t\t\tcurrentScreen.Render()\n\t\t\tcurrentScreen.RenderForegroundLayers()\n\t\t\t\n\t\t\tIf virtualResOn\n\t\t\t\tIf aspectRatioOn\n\t\t\t\t\tSetScissor 0, 0, DEVICE_WIDTH , DEVICE_HEIGHT\n\t\t\t\tEnd\n\t\t\t\tPopMatrix\n\t\t\tEnd\n\t\t\t\n\t\t\tcurrentScreen.ExtraRender()\n\t\t\tIf screenFade.active Then screenFade.Render()\n\t\t\tcurrentScreen.DebugRender()\n\t\t\tIf debugOn\n\t\t\t\tDrawDebug()\n\t\t\tEnd\n\t\t\tIf drawFPSOn\n\t\t\t\tDrawFPS()\n\t\t\tEnd\n\t\t\tdiddyMouse.Update()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\n\tMethod ReadInputs:Void()\n\t\tIf aspectRatioOn\n\t\t\tLocal mouseOffsetX:Float = MouseX() - DEVICE_WIDTH * 0.5\n\t\t\tLocal x:Float = (mouseOffsetX \/ multi) \/ 1 + (SCREEN_WIDTH * 0.5)\n\t\t\tmouseX = x\n\t\t\tLocal mouseOffsetY:Float = MouseY() - DEVICE_HEIGHT * 0.5\n\t\t\tLocal y:Float = (mouseOffsetY \/ multi) \/ 1 + (SCREEN_HEIGHT * 0.5)\n\t\t\tmouseY = y\n\t\tElse\n\t\t\tmouseX = MouseX() \/ SCREENX_RATIO\n\t\t\tmouseY = MouseY() \/ SCREENY_RATIO\n\t\tEnd\n\t\tmouseHit = MouseHit()\n\t\tinputCache.ReadInput()\n\t\tinputCache.HandleEvents(currentScreen)\n\t\t\n\t\tIf debugKeyOn\n\t\t\tIf KeyHit(debugKey)\n\t\t\t\tdebugOn = Not debugOn\n\t\t\tEnd\n\t\tEnd\n\tEnd\n\t\n\tMethod OnUpdate:Int()\n\t\tTry\r\n\t\t\tIf quitApp Then OnBack()\n\t\t\tReadInputs()\n\t\t\tOverrideUpdate()\n\t\t\tIf useFixedRateLogic\n\t\t\t\tLocal now:Int = Millisecs()\n\t\t\t\tIf now < lastTime\n\t\t\t\t\tnumTicks = lastNumTicks\n\t\t\t\tElse\n\t\t\t\t\ttmpMs = now - lastTime\n\t\t\t\t\tIf tmpMs > maxMs tmpMs = maxMs\n\t\t\t\t\tnumTicks = tmpMs \/ ms\n\t\t\t\tEndif\n\t\t\t\n\t\t\t\tlastTime = now\n\t\t\t\tlastNumTicks = numTicks\n\t\t\t\tFor Local i:Int = 1 To Floor(numTicks)\n\t\t\t\t\tUpdate(1)\n\t\t\t\tNext\n\t\t\t\t\n\t\t\t\tLocal re:Float = numTicks Mod 1\n\t\t\t\tIf re > 0 Then\n\t\t\t\t\tUpdate(re)\n\t\t\t\tEnd\n\t\t\tElse\n\t\t\t\tUpdate(0)\n\t\t\tEnd\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\t\n\t\tReturn 0\n\tEnd\n\t\n\tMethod OverrideUpdate:Void()\n\tEnd\n\n\tMethod Update:Void(fixedRateLogicDelta:Float)\n\t\tdt.UpdateDelta()\n\t\tIf useFixedRateLogic\n\t\t\tdt.delta = fixedRateLogicDelta\n\t\tEnd\n\n\t\tIf screenFade.active Then screenFade.Update()\n\t\tIf Not screenFade.active Or screenFade.allowScreenUpdate Then currentScreen.Update()\n\tEnd\n\n\t'summary: Draws debug information\n\tMethod DrawDebug:Void()\n\t\tSetColor 255, 255, 255\n\t\tFPSCounter.Draw(0,0)\n\t\tLocal y:Int = 10\n\t\tLocal gap:Int = 14\n\t\tDrawText \"Screen = \"+currentScreen.name, 0, y\n\t\ty += gap\n\t\tDrawText \"Delta = \"+FormatNumber(dt.delta, 2) , 0, y\n\t\ty += gap\n\t\tDrawText \"Frame Time = \"+dt.frametime , 0, y\t\t\n\t\ty += gap\n\t\tDrawText \"Screen Width = \"+SCREEN_WIDTH, 0, y\n\t\ty += gap\n\t\tDrawText \"Screen Height = \"+SCREEN_HEIGHT, 0, y\n\t\ty += gap\n\t\tDrawText \"VMouseX = \"+Self.mouseX, 0, y\n\t\ty += gap\n\t\tDrawText \"VMouseY = \"+Self.mouseY, 0, y\n\t\ty += gap\n\t\tDrawText \"MouseX = \"+MouseX(), 0, y\n\t\ty += gap\n\t\tDrawText \"MouseY = \"+MouseY(), 0, y\n\t\ty += gap\n\t\tDrawText \"Music File = \"+musicFile, 0, y\n\t\ty += gap\n\t\tDrawText \"MusicOkay = \"+musicOkay, 0, y\n\t\ty += gap\n\t\tDrawText \"Music State = \"+MusicState(), 0, y\n\t\ty += gap\n\t\tDrawText \"Music Volume = \"+Self.musicVolume, 0, y\n\t\ty += gap\n\t\tDrawText \"Mojo Music Volume = \"+Self.mojoMusicVolume, 0, y\n\t\ty += gap\n\t\tDrawText \"Sound Volume = \"+Self.soundVolume, 0, y\n\t\ty += gap\n\t\tDrawText \"Sound Channel = \"+SoundPlayer.channel, 0, y\n\t\ty += gap\n\t\tDrawText \"Back Screen Name = \"+currentScreen.backScreenName, 0, y\n\t\ty += gap\n\tEnd\n\t\n\t'summary: Draws current FPS at 0,0\n\tMethod DrawFPS:Void()\n\t\tDrawText FPSCounter.totalFPS, 0, 0\n\tEnd\n\t\n\t'summary: Wrapper for PlayMusic\n\tMethod MusicPlay:Void(file:String, flags:Int=1)\n\t\tmusicFile = file\n\t\t\n\t\tmusicOkay = PlayMusic(\"music\/\"+musicFile, flags)\n\t\tIf musicOkay = -1\n\t\t\tPrint \"Error Playing Music - Music must be in the data\\music folder\"\n\t\tEnd\n\tEnd\n\t\n\t'summary: Sets the Music volume\n\tMethod MusicSetVolume:Void(volume:Int)\n\t\tIf volume < 0 Then volume = 0\n\t\tIf volume > 100 Then volume = 100\n\t\tSelf.musicVolume = volume\n\t\tSetMojoMusicVolume(musicVolume\/100.0)\n\tEnd\n\t\n\tMethod SetMojoMusicVolume:Void(volume:Float)\n\t\tIf volume < 0 Then volume = 0\n\t\tIf volume > 1 Then volume = 1\n\t\tmojoMusicVolume = volume\n\t\tSetMusicVolume(mojoMusicVolume)\n\tEnd\n\t\n\tMethod SoundSetVolume:Void(volume:Int)\n\t\tIf volume < 0 Then volume = 0\n\t\tIf volume > 100 Then volume = 100\n\t\tSelf.soundVolume = volume\n\t\tFor Local i% = 0 To SoundPlayer.MAX_CHANNELS\n\t\t\tSetChannelVolume(i, diddyGame.soundVolume \/ 100.0)\n\t\tNext\n\tEnd\n\t\n\t'summary: returns an animation length in game frames\n\tMethod CalcAnimLength:Float(ms:Int)\n\t\tReturn ms \/ (1000.0 \/ FPS)\n\tEnd\n\t\n\tMethod UseFixedRateLogic:Bool() Property\n\t\tReturn Self.useFixedRateLogic\n\tEnd\n\t\n\tMethod UseFixedRateLogic:Void(useFrl:Bool) Property\n\t\tSelf.useFixedRateLogic = useFrl\n\t\tResetFixedRateLogic()\n\tEnd\n\t\n\tMethod ResetFixedRateLogic:Void()\n\t\tms = 1000 \/ frameRate\n\t\tnumTicks = 0\n\t\tlastNumTicks = 1\n\t\tlastTime = Millisecs()\n\t\tIf dt <> Null\n\t\t\tdt.delta = 1\n\t\tEnd\n\tEnd\n\t\n\t' convenience method that will trigger a fade in and call PreStart() on the screen (used for first screen)\n\tMethod Start:Void(firstScreen:Screen, autoFadeIn:Bool=True, fadeInTime:Float=defaultFadeTime, fadeSound:Bool=False, fadeMusic:Bool=False)\n\t\tfirstScreen.autoFadeIn = autoFadeIn\n\t\tIf autoFadeIn Then\n\t\t\tfirstScreen.autoFadeInTime = fadeInTime\n\t\t\tfirstScreen.autoFadeInSound = fadeSound\n\t\t\tfirstScreen.autoFadeInMusic = fadeMusic\n\t\tEnd\n\t\tfirstScreen.PreStart()\n\tEnd\n\t\n\tMethod OnSuspend:Int()\n\t\tTry\n\t\t\tcurrentScreen.Suspend()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\n\tMethod OnResume:Int()\n\t\tTry\n\t\t\tdt.currentticks = Millisecs()\n\t\t\tdt.lastticks = dt.currentticks\n\t\t\tcurrentScreen.Resume()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\tMethod OnBack:Int()\n\t\tTry\r\n\t\t\tIf quitApp Then\r\n\t\t\t\tExitApp()\r\n\t\t\t\tReturn 0\r\n\t\t\tEnd\n\t\t\tcurrentScreen.Back()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\t'summary: Loads in the diddydata xml file\n\tMethod LoadDiddyData:Void(filename:String=\"diddydata.xml\")\n\t\tautoCls = True\n\t\tdiddyData = New DiddyData(filename)\n\tEnd\nEnd\n\n\n'summary: Map to store the Screens\nClass Screens Extends StringMap\r\n\tMethod Set:Bool(key:String, value:Screen)\r\n\t\tReturn Super.Set(key.ToUpper(), value)\r\n\tEnd\r\n\t\n\tMethod Find:Screen(name:String)\n\t\tname = name.ToUpper()\n\n\t\t' debug: print all keys in the map\n\t\tIf diddyGame.debugOn\n\t\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\t\tPrint key + \" is stored in the Screens map.\"\n\t\t\tNext\n\t\tEnd\n\n\t\tLocal i:Screen = Self.Get(name)\n\t\tAssertNotNull(i, \"Screen '\" + name + \"' not found in the Screens map\")\n\t\tReturn i\n\tEnd\nEnd\n\n'summary: Simple screen fading\nClass ScreenFade\n\tField fadeTime:Float\n\tField fadeOut:Bool\n\tField ratio:Float = 0\n\tField active:Bool\n\tField counter:Float\n\tField fadeMusic:Bool\n\tField fadeSound:Bool\n\tField allowScreenUpdate:Bool\n\t\n\tMethod Start:Void(fadeTime:Float, fadeOut:Bool, fadeSound:Bool = False, fadeMusic:Bool = False, allowScreenUpdate:Bool = True)\n\t\tIf active Then Return\n\t\tactive = True\n\t\tSelf.fadeTime = diddyGame.CalcAnimLength(fadeTime)\n\t\tSelf.fadeOut = fadeOut\n\t\tSelf.fadeMusic = fadeMusic\n\t\tSelf.fadeSound = fadeSound\n\t\tSelf.allowScreenUpdate = allowScreenUpdate\n\t\tIf fadeOut Then\n\t\t\tratio = 1\n\t\tElse\n\t\t\tratio = 0\n\t\t\t' set the music volume to zero if fading in the music\n\t\t\tIf Self.fadeMusic\n\t\t\t\tdiddyGame.SetMojoMusicVolume(0)\n\t\t\tEnd\t\t\t\n\t\tEnd\n\t\tcounter = 0\n\tEnd\n\n\tMethod Update:Void()\n\t\tIf Not active Return\n\t\tcounter += dt.delta\n\t\tCalcRatio()\n\t\tIf fadeSound Then\n\t\t\tFor Local i% = 0 To SoundPlayer.MAX_CHANNELS\n\t\t\t\tSetChannelVolume(i, (ratio) * (diddyGame.soundVolume \/ 100.0))\n\t\t\tNext\n\t\tEnd\n\t\tIf fadeMusic Then\n\t\t\tdiddyGame.SetMojoMusicVolume((ratio) * (diddyGame.musicVolume \/ 100.0))\n\t\tEnd\n\t\tIf counter > fadeTime\n\t\t\tactive = False\n\t\t\tIf fadeOut\t\t\t\n\t\t\t\tdiddyGame.currentScreen.PostFadeOut()\n\t\t\tElse\n\t\t\t\tdiddyGame.currentScreen.PostFadeIn()\n\t\t\tEnd\n\t\tEnd\n\tEnd\n\t\t\n\tMethod CalcRatio:Void()\n\t\tratio = counter\/fadeTime\n\t\tIf ratio < 0\n\t\t\tratio = 0\n\t\t\tIf fadeMusic\n\t\t\t\tdiddyGame.SetMojoMusicVolume(0)\n\t\t\tEnd\n\t\tEnd\n\t\tIf ratio > 1\n\t\t\tratio = 1\n\t\t\tIf fadeMusic\n\t\t\t\tdiddyGame.SetMojoMusicVolume(diddyGame.musicVolume \/ 100.0)\n\t\t\tEnd\n\t\tEnd\n\t\tIf fadeOut Then\n\t\t\tratio = 1 - ratio\n\t\tEnd\n\tEnd\n\t\n\tMethod Render:Void()\n\t\tIf Not active Return\n\t\tSetAlpha 1 - ratio\n\t\tSetColor 0, 0, 0\n\t\tDrawRect 0, 0, DEVICE_WIDTH, DEVICE_HEIGHT\n\t\tSetAlpha 1\n\t\tSetColor 255, 255, 255\n\tEnd\n\t\nEnd\n\n'summary: Screen to exit the application\nClass ExitScreen Extends Screen\n\tMethod New()\n\t\tSuper.New(\"exit\")\n\tEnd\n\t\n\tMethod Start:Void()\n\t\tquitApp = True\n\tEnd\n\t\n\tMethod Render:Void()\n\tEnd \n\t\n\tMethod Update:Void()\n\tEnd\nEnd\n\n'summary: Abstract Screen class\nClass Screen Abstract\nPrivate\n\tField autoFadeIn:Bool = False\n\tField autoFadeInTime:Float = 50\n\tField autoFadeInSound:Bool = False\n\tField autoFadeInMusic:Bool = False\n\tField musicPath:String\n\tField musicFlag:Int\n\nPublic\n\tField name:String = \"\"\n\tField backScreenName:String = \"\"\n\tField layers:DiddyDataLayers\n\t\n\tMethod New(name:String=\"\")\n\t\tSelf.name = name\n\tEnd\n\t\n\tMethod PreStart:Void()\n\t\tdiddyGame.screens.Set(name, Self)\n\t\tdiddyGame.currentScreen = Self\n\t\tIf autoFadeIn Then\n\t\t\tautoFadeIn = False\n\t\t\tdiddyGame.screenFade.Start(autoFadeInTime, False, autoFadeInSound, autoFadeInMusic)\n\t\tEnd\n\t\t\n\t\t' load screens graphics\n\t\tLocal tmpImage:Image\n\t\tFor Local key:String = EachIn diddyGame.images.Keys()\n\t\t\tLocal i:GameImage = diddyGame.images.Get(key)\n\t\t\tIf i.preLoad And i.screenName.ToUpper() = name.ToUpper()\n\t\t\t\tIf i.frames > 1\n\t\t\t\t\ti.LoadAnim(i.path, i.w, i.h, i.frames, tmpImage, i.midhandle, i.readPixels, i.maskRed, i.maskGreen, i.maskBlue, False, i.screenName)\n\t\t\t\tElse\n\t\t\t\t\ti.Load(i.path, i.midhandle, i.readPixels, i.maskRed, i.maskGreen, i.maskBlue, False, i.screenName)\n\t\t\t\tEnd\n\t\t\tEnd\n\t\tNext\n\t\t\n\t\t' load screens sounds\n\t\tFor Local key:String = EachIn diddyGame.sounds.Keys()\n\t\t\tLocal i:GameSound = diddyGame.sounds.Get(key)\n\t\t\tIf i.preLoad And i.screenName.ToUpper() = name.ToUpper()\n\t\t\t\ti.Load(i.path, False, i.screenName)\n\t\t\tEnd\n\t\tNext\n\t\t\n\t\t' play the screen's music if its set\n\t\tIf musicPath <> \"\" Then diddyGame.MusicPlay(musicPath, musicFlag)\n\t\t\n\t\tStart()\n\tEnd\n\t\n\tMethod RenderBackgroundLayers:Void()\n\t\tIf layers Then\n\t\t\tFor Local layer:DiddyDataLayer = Eachin layers\n\t\t\t\tIf layer.index >= 0 Then Return\n\t\t\t\tlayer.Render()\n\t\t\tNext\n\t\tEnd\n\tEnd\n\t\n\tMethod RenderForegroundLayers:Void()\n\t\tIf layers Then\n\t\t\tFor Local layer:DiddyDataLayer = Eachin layers\n\t\t\t\tIf layer.index >= 0 Then\n\t\t\t\t\tlayer.Render()\n\t\t\t\tEnd\n\t\t\tNext\n\t\tEnd\n\tEnd\n\t\n\tMethod Start:Void() Abstract\n\t\n\tMethod Render:Void() Abstract\n\t\n\tMethod Update:Void() Abstract\n\t\n\tMethod Back:Void()\n\t\tIf backScreenName=\"exit\" Then\n\t\t\tFadeToScreen(Null)\n\t\tElseIf backScreenName Then\n\t\t\tLocal scr:Screen = diddyGame.screens.Find(backScreenName)\n\t\t\tIf scr Then FadeToScreen(scr)\n\t\tEnd\n\tEnd\n\t\n\tMethod Suspend:Void()\n\tEnd\n\n\tMethod Resume:Void()\n\tEnd\n\n\tMethod PostFadeOut:Void()\n\t\tKill()\n\t\tdiddyGame.nextScreen.PreStart()\n\tEnd\n\t\n\tMethod Kill:Void()\n\tEnd\n\t\n\tMethod PostFadeIn:Void()\n\tEnd\n\t\n\tMethod ExtraRender:Void()\n\tEnd\n\t\n\tMethod DebugRender:Void()\n\tEnd\n\t\n\t' fired when you first touch the screen\n\tMethod OnTouchHit:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n\t\n\t' fired when you release a finger from the screen\n\tMethod OnTouchReleased:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n\t\n\t' fired when one of your fingers drags along the screen\n\tMethod OnTouchDragged:Void(x:Int, y:Int, dx:Int, dy:Int, pointer:Int)\n\tEnd\n\t\n\tMethod OnTouchClick:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n \n\t' fired if you touch the screen and hold the finger in the same position for one second (configurable using game.inputCache.LongPressTime)\n\t' this is checked at a specific time after touching the screen, so if you move your finger around and then\n\t' hold it still, it won't fire\n\tMethod OnTouchLongPress:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n\n\t' fired after you release a finger from the screen, if it was moving fast enough (configurable using game.inputCache.FlingThreshold)\n\t' velocityx\/y\/speed is in pixels per second, but speed is taken from the entire vector, by pythagoras\n\t' ie. velocitySpeed = Sqrt(velocityX*velocityX + velocityY*velocityY) in pixels per second\n\tMethod OnTouchFling:Void(releaseX:Int, releaseY:Int, velocityX:Float, velocityY:Float, velocitySpeed:Float, pointer:Int)\n\tEnd\n\t\n\t' fired once if any key was hit (before OnKeyHit)\n\tMethod OnAnyKeyHit:Void()\n\tEnd\n\t\n\t' fired for each key that was hit\n\tMethod OnKeyHit:Void(key:Int)\n\tEnd\n\t\n\t' fired once if any key is down (before OnKeyDown)\n\tMethod OnAnyKeyDown:Void()\n\tEnd\n\t\n\t' fired for each key that is down\n\tMethod OnKeyDown:Void(key:Int)\n\tEnd\n\t\n\t' fired once if any key was released (before OnKeyReleased)\n\tMethod OnAnyKeyReleased:Void()\n\tEnd\n\t\n\t' fired for each key that was released\n\tMethod OnKeyReleased:Void(key:Int)\n\tEnd\n\t\n\tMethod OnMouseHit:Void(x:Int, y:Int, button:Int)\n\tEnd\n\t\n\tMethod OnMouseDown:Void(x:Int, y:Int, button:Int)\n\tEnd\n\t\n\tMethod OnMouseReleased:Void(x:Int, y:Int, button:Int)\n\tEnd\n\t\n\t'summary: convenience method\n\tMethod FadeToScreen:Void(screen:Screen, fadeTime:Float = defaultFadeTime, fadeSound:Bool = False, fadeMusic:Bool = False, allowScreenUpdate:Bool = True)\n\t\t' don't try to fade twice\n\t\tIf diddyGame.screenFade.active Then Return\n\t\t\n\t\t' if the screen is null, assume we're exiting\n\t\tIf Not screen Then screen = diddyGame.exitScreen\n\t\t\n\t\t' configure the autofade values\n\t\tscreen.autoFadeIn = True\n\t\tscreen.autoFadeInTime = fadeTime\n\t\tscreen.autoFadeInSound = fadeSound\n\t\tscreen.autoFadeInMusic = fadeMusic\n\t\t\n\t\t' trigger the fade out\n\t\tdiddyGame.nextScreen = screen\n\t\tdiddyGame.screenFade.Start(fadeTime, True, fadeSound, fadeMusic, allowScreenUpdate)\n\tEnd\n\t\n\t'summary: sets the screen's music which autoplays when the screen starts\n\tMethod SetMusic:Void(path:String, flag:Int = 0)\n\t\tSelf.musicPath = path\n\t\tSelf.musicFlag = flag\n\tEnd\nEnd\n\n'summary: Simple Frames per second counter\nClass FPSCounter Abstract\n\tGlobal fpsCount:Int\n\tGlobal startTime:Int\n\tGlobal totalFPS:Int\n\n\tFunction Update:Void()\n\t\tIf Millisecs() - startTime >= 1000\n\t\t\ttotalFPS = fpsCount\n\t\t\tfpsCount = 0\n\t\t\tstartTime = Millisecs()\n\t\tElse\n\t\t\tfpsCount+=1\n\t\tEnd\n\tEnd\n\n\tFunction Draw:Void(x% = 0, y% = 0, ax# = 0, ay# = 0)\n\t\tDrawText(\"FPS: \" + totalFPS, x, y, ax, ay)\n\tEnd\nEnd\n\n'summary: DeltaTimer by James Boyd\nClass DeltaTimer\n\tField targetfps:Float = 60\n\tField currentticks:Float\n\tField lastticks:Float\n\tField frametime:Float\n\tField delta:Float\n\t\n\tMethod New (fps:Float)\n\t\ttargetfps = fps\n\t\tlastticks = Millisecs()\n\tEnd\n\t\n\tMethod UpdateDelta:Void()\n\t\tcurrentticks = Millisecs()\n\t\tframetime = currentticks - lastticks\n\t\tdelta = frametime \/ (1000.0 \/ targetfps)\n\t\tlastticks = currentticks\n\tEnd\nEnd\n\n'summary: Image resource bank\n'Images must be stored in graphics folder\nClass ImageBank Extends StringMap\n\tConst ATLAS_PREFIX:String = \"_diddyAtlas_\"\n\tConst SPARROW_ATLAS:Int = 0\n\tConst LIBGDX_ATLAS:Int = 1\n\t\n\tField path:String = \"graphics\/\"\n\t\n\tMethod LoadAtlas:Void(fileName:String, format:Int = SPARROW_ATLAS, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tIf format = SPARROW_ATLAS\n\t\t\tLoadSparrowAtlas(fileName, midHandle, readPixels, maskRed, maskGreen, maskBlue)\n\t\tElseif format = LIBGDX_ATLAS\n\t\t\tLoadLibGdxAtlas(fileName, midHandle, readPixels, maskRed, maskGreen, maskBlue)\n\t\tElse\n\t\t\tError \"Invalid atlas format\"\n\t\tEnd\n\tEnd\n\t\n\tMethod LoadAtlasString:String(fileName:String)\n\t\tLocal str:String = LoadString(path + fileName)\n\t\t' check to see if the file is valid\n\t\tAssertNotEqualInt(str.Length(), 0, \"Error loading Atlas \"+ path + fileName)\n\t\tReturn str\t\t\n\tEnd\n\t\n\tMethod SaveAtlasToBank:String(pointer:Image, fileName:String)\n\t\t' save the whole atlas with prefix\n\t\tLocal atlasGameImage:GameImage = New GameImage\n\t\tatlasGameImage.name = ATLAS_PREFIX + StripAll(fileName).ToUpper()\n\t\tatlasGameImage.image = pointer\n\t\tatlasGameImage.CalcSize()\n\t\tSelf.Set(atlasGameImage.name, atlasGameImage)\n\t\tReturn atlasGameImage.name\n\tEnd\n\t\n\tMethod LoadLibGdxAtlas:Void(fileName:String, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tLocal str:String = LoadAtlasString(fileName)\n\t\tLocal all:String[] = str.Split(\"~n\")\n\t\tLocal spriteFileName:String = all[0].Trim()\n\t\tLocal pointer:Image = LoadImage(path + spriteFileName)\n\t\tAssertNotNull(pointer, \"Error loading bitmap atlas \"+ path + spriteFileName)\n\t\tLocal atlasGameImageName:String = SaveAtlasToBank(pointer, fileName)\n\t\t\n\t\tLocal line:String = \"\"\n\t\tLocal i:Int = 4\n\t\tLocal xy:String[] =[\"\",\"\"]\n\t\tLocal debug:Bool = False\n\t\tWhile True\n\t\t\t' name of the image\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"name = \"+line\n\t\t\tIf line = \"\" Then Exit\n\t\t\tLocal name:String = line\n\t\t\t'rotate\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"rotate = \"+line\n\t\t\tLocal rotate:String = line\n\t\t\t' x and y\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"x and y = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal x:Int = Int(xy[0].Trim())\n\t\t\tLocal y:Int = Int(xy[1].Trim())\n\t\t\t' width and height\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"width and height = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal width:Int = Int(xy[0].Trim())\n\t\t\tLocal height:Int = Int(xy[1].Trim())\n\t\t\t' origX and origY\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"origX and origY = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal origX:Int = Int(xy[0].Trim())\n\t\t\tLocal origY:Int = Int(xy[1].Trim())\n\t\t\t' offsets\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"offsets = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal offsetX:Int = Int(xy[0].Trim())\n\t\t\tLocal offsetY:Int = Int(xy[1].Trim())\n\t\t\t'index\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"index = \"+line\n\t\t\tLocal index:Int = Int(line[ (line.FindLast(\":\") + 1) ..].Trim())\n\t\t\ti+=1\n\t\t\tLocal gi:GameImage = New GameImage\n\t\t\tIf index > - 1\n\t\t\t\tname += index\n\t\t\tEnd\n\t\t\tIf debug\n\t\t\t\tPrint \"name = \" + name\n\t\t\t\tPrint \"x = \" + x\n\t\t\t\tPrint \"y = \" + y\n\t\t\t\tPrint \"width = \" + width\n\t\t\t\tPrint \"height = \" + height\n\t\t\t\tPrint \"origX = \" + origX\n\t\t\t\tPrint \"origY = \" + origY\n\t\t\t\tPrint \"offsetX = \" + offsetX\n\t\t\t\tPrint \"offsetY = \" + offsetY\n\t\t\t\tPrint \"index = \" + index\n\t\t\tEnd\n\t\t\t\n\t\t\tgi.name = name.ToUpper()\n\t\t\tgi.image = pointer.GrabImage(x, y, width, height)\n\t\t\tgi.CalcSize()\n\t\t\tgi.MidHandle(midHandle)\n\t\t\t\n\t\t\tgi.atlasName = atlasGameImageName\n\t\t\tgi.subX = x\n\t\t\tgi.subY = y\n\t\t\tgi.readPixels = readPixels\n\t\t\tgi.SetMaskColor(maskRed, maskGreen, maskBlue)\n\t\t\t\n\t\t\tSelf.Set(gi.name, gi)\n\t\tWend\n\t\t\n\tEnd\n\t\n\tMethod LoadSparrowAtlas:Void(fileName:String, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tLocal str:String = LoadAtlasString(fileName)\n\t\t' parse the xml\n\t\tLocal parser:XMLParser = New XMLParser\n\t\tLocal doc:XMLDocument = parser.ParseString(str)\n\t\tLocal rootElement:XMLElement = doc.Root\n\t\tLocal spriteFileName:String = rootElement.GetAttribute(\"imagePath\")\n\t\t\n\t\tLocal pointer:Image = LoadImage(path + spriteFileName)\n\t\tAssertNotNull(pointer, \"Error loading bitmap atlas \"+ path + spriteFileName)\n\t\t\n\t\tLocal atlasGameImageName:String = SaveAtlasToBank(pointer, fileName)\n\t\t\n\t\tFor Local node:XMLElement = Eachin rootElement.GetChildrenByName(\"SubTexture\")\n\t\t\tLocal x:Int = Int(node.GetAttribute(\"x\").Trim())\n\t\t\tLocal y:Int = Int(node.GetAttribute(\"y\").Trim())\n\t\t\tLocal width:Int = Int(node.GetAttribute(\"width\").Trim())\n\t\t\tLocal height:Int = Int(node.GetAttribute(\"height\").Trim())\n\t\t\tLocal name:String = node.GetAttribute(\"name\").Trim()\n\n\t\t\tLocal gi:GameImage = New GameImage\n\t\t\tgi.name = name.ToUpper()\n\t\t\tgi.image = pointer.GrabImage(x, y, width, height)\n\t\t\tgi.CalcSize()\n\t\t\tgi.MidHandle(midHandle)\n\t\t\t\n\t\t\tgi.atlasName = atlasGameImageName\n\t\t\tgi.subX = x\n\t\t\tgi.subY = y\n\t\t\tgi.readPixels = readPixels\n\t\t\tgi.SetMaskColor(maskRed, maskGreen, maskBlue)\n\t\t\tSelf.Set(gi.name, gi)\n\t\tNext\n\tEnd\n\t\n\tMethod Load:GameImage(name:String, nameoverride:String = \"\", midhandle:Bool = True, ignoreCache:Bool = False, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\t' check if we already have the image in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old image if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).image.Discard()\n\t\tLocal i:GameImage = New GameImage\n\t\ti.Load(path + name, midhandle, readPixels, maskRed, maskGreen, maskBlue, preLoad, screenName)\n\t\ti.name = storeKey\n\t\tSelf.Set(i.name, i)\n\t\tReturn i\n\tEnd\n\t\n\tMethod LoadAnim:GameImage(name:String, w:Int, h:Int, total:Int, tmpImage:Image, midhandle:Bool = True, ignoreCache:Bool = False, nameoverride:String = \"\", readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\t' check if we already have the image in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old image if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).image.Discard()\n\n\t\tLocal i:GameImage = New GameImage\n\t\ti.LoadAnim(path + name, w, h, total, tmpImage, midhandle, readPixels, maskRed, maskGreen, maskBlue, preLoad, screenName)\n\t\ti.name = storeKey\n\t\tSelf.Set(i.name, i)\n\t\tReturn i\n\tEnd\n \n\tMethod LoadTileset:GameImage(name:String, tileWidth%, tileHeight%, tileMargin% = 0, tileSpacing% = 0, nameoverride:String = \"\", midhandle:Bool=False, ignoreCache:Bool=False, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\t' check if we already have the image in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old image if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).image.Discard()\n\t\t\n\t\t' load the new one\n\t\tLocal i:GameImage = New GameImage\n\t\ti.LoadTileset(path + name, tileWidth, tileHeight, tileMargin, tileSpacing, midhandle, readPixels, maskRed, maskGreen, maskBlue)\n\t\ti.name = storeKey\n\t\tSelf.Set(i.name, i)\n\t\tReturn i\n\tEnd\n\t\n\tMethod Find:GameImage(name:String)\n\t\tname = name.ToUpper()\n\n\t\t' debug: print all keys in the map\n\t\tIf diddyGame.debugOn\n\t\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\t\tLocal i:GameImage = Self.Get(key)\n\t\t\t\tif Not i.preLoad Then\n\t\t\t\t\tPrint key + \" is stored in the image map.\"\n\t\t\t\tEnd\n\t\t\tNext\n\t\tEnd\n\t\tLocal i:GameImage = Self.Get(name)\n\t\tAssertNotNull(i, \"Image '\" + name + \"' not found in the ImageBank\")\n\t\tIf i.preLoad and i.image = null Then AssertError(\"Image '\" + name + \"' not found in the ImageBank\")\n\t\tReturn i\n\tEnd\n\t\n\t'summary: This returns an animation gameimage from an previous loaded Atas and adds it to the image bank.\n\t'So you get then just use Find to return the animation gameimage later.\n\t'name: The first image in the atlas\n\t'w,h: The width and height of the frames\n\t'frames: The number of frames to capture from the atlas\n\t'midhandle: Sets the midhandle of the image\n\t'nameoverride: If supplied, changes the stored name in the image bank\n\tMethod FindSet:GameImage(name:String, w:Int, h:Int, frames:Int=0, midhandle:Bool = True, nameoverride:String = \"\")\n\t\tname = name.ToUpper()\n\t\tLocal subImage:GameImage = Self.Get(name)\n\t\tAssertNotNull(subImage, \"Image '\" + name + \"' not found in the ImageBank\")\n\t\tLocal atlasGameImage:GameImage = Self.Get(subImage.atlasName)\n\t\tAssertNotNull(atlasGameImage, \"Atlas Image '\" + name + \"' not found in the ImageBank\")\n\t\tLocal image:Image = atlasGameImage.image.GrabImage(subImage.subX, subImage.subY, w, h, frames)\n\t\t\n\t\tLocal gi:GameImage = New GameImage\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = name.ToUpper()\n\t\tgi.name = storeKey\n\t\tgi.image = image\n\t\tgi.CalcSize()\n\t\tgi.MidHandle(midhandle)\n\t\tReturn gi\n\tEnd\n\t\n\tMethod PreCache:Void()\n\t\tLocal gi:GameImage\n\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\tgi = Self.Get(key)\n\t\t\tgi.PreCache()\n\t\tNext\n\tEnd\n\t\n\tMethod ReadPixelsArray:Void()\n\t\tLocal gi:GameImage\n\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\tgi = Self.Get(key)\n\t\t\tgi.ReadPixelsArray()\n\t\tNext\n\tEnd\nEnd\n\n'summary: GameImage Class\nClass GameImage\n\nPrivate\n\tField pixels:Int[]\n\tField maskRed:Int = 0\n\tField maskGreen:Int = 0\n\tField maskBlue:Int = 0\n\tField preLoad:Bool = False\n\tField path:String\n\tField midhandle:Bool\n\tField screenName:String\nPublic\n\tField name:String\n\tField image:Image\n\tField w:Int\n\tField h:Int\n\tField w2:Float\n\tField h2:Float\n\tField midhandled:Int = 0\n\tField frames:Int\n\t\n\tField leftMargin:Int = 0\n\tField rightMargin:Int = 0\n\tField topMargin:Int = 0\n\tField bottomMargin:Int = 0\n\t\n\tField tileWidth:Int, tileHeight:Int\n\tField tileCountX:Int, tileCountY:Int\n\tField tileCount:Int\n\tField tileSpacing:Int, tileMargin:Int\n\t\n\tField subX:Int\n\tField subY:Int\n\tField atlasName:String\n\n\tField readPixels:Bool\n\tField readPixelsComplete:Bool = False\n\n\tMethod Pixels:Int[]() Property\n\t\tIf readPixels Then\n\t\t\tIf Not readPixelsComplete Then\n\t\t\t#If CONFIG=\"debug\"\n\t\t\t\tPrint \"Read Pixels have not been completed, please use ReadPixels on GameImage \"+name\n\t\t\t#End\n\t\t\tEnd\n\t\tEnd\n\t\tReturn pixels\n\tEnd\n\t\n\tMethod SetMaskColor:Void(r:Int, g:Int, b:Int)\n\t\tmaskRed = r\n\t\tmaskGreen = g\n\t\tmaskBlue = b\n\tEnd\n\t\n\tMethod Load:Void(file:String, midhandle:Bool = True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\tname = StripAll(file.ToUpper())\n\t\tpath = file\n\t\tSelf.midhandle = midhandle\n\t\tSelf.preLoad = preLoad\n\t\tSelf.screenName = screenName.ToUpper()\n\t\tIf Not preLoad Then\n\t\t\timage = LoadBitmap(file)\n\t\t\tCalcSize()\n\t\t\tMidHandle(midhandle)\n\t\t\tpixels = New Int[image.Width() * image.Height()]\n\t\t\tSelf.readPixels = readPixels\n\t\tEnd\n\t\tSetMaskColor(maskRed, maskGreen, maskBlue)\n\tEnd\n\t\n\tMethod LoadAnim:Void(file:String, w:Int, h:Int, total:Int, tmpImage:Image, midhandle:Bool = True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\tname = StripAll(file.ToUpper())\n\t\tpath = file\n\t\tSelf.midhandle = midhandle\n\t\tSelf.preLoad = preLoad\n\t\tSelf.screenName = screenName.ToUpper()\n\t\tSelf.w = w\n\t\tSelf.h = h\n\t\tSelf.frames = total\n\t\tIf not preLoad Then\n\t\t\timage = LoadAnimBitmap(file, w, h, total, tmpImage)\n\t\t\tCalcSize()\n\t\t\tMidHandle(midhandle)\n\t\t\tpixels = New Int[image.Width() * image.Height()]\n\t\t\tSelf.readPixels = readPixels\n\t\tEnd\n\t\tSetMaskColor(maskRed, maskGreen, maskBlue)\n\tEnd\n\t\n\tMethod LoadTileset:Void(file:String, tileWidth:Int, tileHeight:Int, tileMargin:Int = 0, tileSpacing:Int = 0, midhandle:Bool=False, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tLoad(file, midhandle)\n\t\tSelf.tileWidth = tileWidth\n\t\tSelf.tileHeight = tileHeight\n\t\tSelf.tileMargin = tileMargin\n\t\tSelf.tileSpacing = tileSpacing\n\t\ttileCountX = (w - tileMargin) \/ (tileWidth + tileSpacing)\n\t\ttileCountY = (h - tileMargin) \/ (tileHeight + tileSpacing)\n\t\ttileCount = tileCountX * tileCountY\n\t\tpixels = New Int[image.Width() * image.Height()]\n\t\tSelf.readPixels = readPixels\n\t\tSetMaskColor(maskRed, maskGreen, maskBlue)\n\tEnd\n\t\n\tMethod CalcSize:Void()\n\t\tIf image <> Null Then\n\t\t\tw = image.Width()\n\t\t\th = image.Height()\n\t\t\tw2 = w\/2\n\t\t\th2 = h\/2\n\t\tEnd\n\tEnd\n\t\n\tMethod MidHandle:Void(midhandle:Bool) Property\n\t\tIf midhandle Then\n\t\t\timage.SetHandle(w2, h2)\n\t\t\tSelf.midhandled=1\n\t\tElse\n\t\t\timage.SetHandle(0, 0)\n\t\t\tSelf.midhandled=0\n\t\tEnd \n\tEnd\n\t\n\tMethod SetHandle:Void(handleX:Float, handleY:Float)\n\t\timage.SetHandle(handleX, handleY)\n\tEnd\n\t\n\tMethod MidHandle:Bool() Property\n\t\tReturn Self.midhandled = 1\n\tEnd\n\t\n\tMethod Draw:Void(x:Float, y:Float, rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\tDrawImage(Self.image, x, y, rotation, scaleX, scaleY, frame)\n\tEnd\n\t\n\tMethod DrawSubImage:Void(destX:Float, destY:Float, srcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int, rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\tDrawImageRect(Self.image, destX, destY, srcX, srcY, srcWidth, srcHeight, rotation, scaleX, scaleY, frame)\n\tEnd\n\t\n\tMethod DrawTile:Void(x:Float, y:Float, tile:Int = 0, rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1)\n\t\tLocal srcX% = tileMargin + (tileWidth + tileSpacing) * (tile Mod tileCountX)\n\t\tLocal srcY% = tileMargin + (tileHeight + tileSpacing) * (tile \/ tileCountX)\n\t\tDrawImageRect(Self.image, x, y, srcX, srcY, tileWidth, tileHeight, rotation, scaleX, scaleY)\n\tEnd\n\t\n\tMethod DrawStretched:Void(destX:Float, destY:Float, destWidth:Float, destHeight:Float,\n\t\t\trotation:Float = 0)', scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\t' scales for stretching\n\t\tLocal stretchScaleX:Float = destWidth \/ w\n\t\tLocal stretchScaleY:Float = destHeight \/ h\n\t\tDrawImage(Self.image, destX, destY, rotation, stretchScaleX, stretchScaleY)', frame)\n\tEnd\n\t\n\tMethod DrawGrid:Void(x:Float, y:Float, rw:Float, rh:Float, frame:Int = 0)\n\t\t' draw top left corner\n\t\tDrawImageRect(Self.image, x, y, 0, 0, leftMargin, topMargin, frame)\n\t\t' draw top right corner\n\t\tDrawImageRect(Self.image, x+rw-rightMargin, y, w-rightMargin, 0, rightMargin, topMargin, frame)\n\t\t' draw bottom left corner\n\t\tDrawImageRect(Self.image, x, y+rh-bottomMargin, 0, h-bottomMargin, leftMargin, bottomMargin, frame)\n\t\t' draw bottom right corner\n\t\tDrawImageRect(Self.image, x+rw-rightMargin, y+rh-bottomMargin, w-rightMargin, h-bottomMargin, rightMargin, bottomMargin, frame)\n\t\t\n\t\t' work out how many horizontal and vertical tiles\n\t\tLocal tileWidth% = (w-leftMargin-rightMargin)\n\t\tLocal tileHeight% = (h-topMargin-bottomMargin)\n\t\tLocal tileXCount% = (rw-leftMargin-rightMargin) \/ tileWidth\n\t\tLocal tileYCount% = (rh-topMargin-bottomMargin) \/ tileHeight\n\t\tLocal tileXOverflow% = (rw-leftMargin-rightMargin) Mod tileWidth\n\t\tLocal tileYOverflow% = (rh-topMargin-bottomMargin) Mod tileHeight\n\t\t\n\t\t' tile top and bottom edges\n\t\tFor Local i% = 0 Until tileXCount\n\t\t\tDrawImageRect(Self.image, leftMargin+i*tileWidth,0,leftMargin,0,tileWidth,topMargin,frame)\n\t\t\tDrawImageRect(Self.image, leftMargin+i*tileWidth,rh-bottomMargin,leftMargin,h-bottomMargin,tileWidth,bottomMargin,frame)\n\t\tNext\n\t\tIf tileXOverflow > 0 Then\n\t\t\tDrawImageRect(Self.image, leftMargin+tileXCount*tileWidth,0,leftMargin,0,tileXOverflow,topMargin,frame)\n\t\t\tDrawImageRect(Self.image, leftMargin+tileXCount*tileWidth,rh-bottomMargin,leftMargin,h-bottomMargin,tileXOverflow,bottomMargin,frame)\n\t\tEnd\n\t\t\n\t\t' tile left and right edges\n\t\tFor Local i% = 0 Until tileYCount\n\t\t\tDrawImageRect(Self.image, 0, topMargin+i*tileHeight,0,topMargin,leftMargin,tileHeight,frame)\n\t\t\tDrawImageRect(Self.image, rw-rightMargin,topMargin+i*tileHeight,w-rightMargin,topMargin,rightMargin,tileHeight,frame)\n\t\tNext\n\t\tIf tileYOverflow > 0 Then\n\t\t\tDrawImageRect(Self.image, 0, topMargin+tileYCount*tileHeight,0,topMargin,leftMargin,tileYOverflow,frame)\n\t\t\tDrawImageRect(Self.image, rw-rightMargin,topMargin+tileYCount*tileHeight,w-rightMargin,topMargin,rightMargin,tileYOverflow,frame)\n\t\tEnd\n\t\t\n\t\t' tile centre\n\t\t' TODO\n\tEnd\n\t\n\tMethod DrawSubStretched:Void(destX:Float, destY:Float, destWidth:Float, destHeight:Float, srcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int,\n\t\t\trotation:Float = 0)', scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\t' scales for stretching\n\t\tLocal stretchScaleX:Float = destWidth \/ srcWidth\n\t\tLocal stretchScaleY:Float = destHeight \/ srcHeight\n\t\tDrawImageRect(Self.image, destX, destY, srcX, srcY, srcWidth, srcHeight, rotation, stretchScaleX, stretchScaleY)', frame)\n\tEnd\n\t\n\t' Yes, a crapload of parameters. Thankfully most of them are optional, and this will usually only be called internally by the GUI.\n\t' TODO: apply scale to parameters\n\tMethod DrawSubGrid:Void(x:Float, y:Float, width:Float, height:Float,\n\t\t\tsrcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int,\n\t\t\tleftMargin:Int, rightMargin:Int, topMargin:Int, bottomMargin:Int,\n\t\t\t'rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1,\n\t\t\tdrawTopLeft:Bool = True, drawTop:Bool = True, drawTopRight:Bool = True,\n\t\t\tdrawLeft:Bool = True, drawCenter:Bool = True, drawRight:Bool = True,\n\t\t\tdrawBottomLeft:Bool = True, drawBottom:Bool = True, drawBottomRight:Bool = True)\n\t\t' draw the corners\n\t\tIf drawTopLeft Then DrawImageRect(Self.image,\n\t\t\t\tx, y, srcX, srcY,\n\t\t\t\tleftMargin, topMargin)', rotation, scaleX, scaleY)\n\t\tIf drawTopRight Then DrawImageRect(Self.image,\n\t\t\t\tx+width-rightMargin, y, srcX+srcWidth-rightMargin, srcY,\n\t\t\t\trightMargin, topMargin)', rotation, scaleX, scaleY)\n\t\tIf drawBottomLeft Then DrawImageRect(Self.image,\n\t\t\t\tx, y+height-bottomMargin, srcX, srcY+srcHeight-bottomMargin,\n\t\t\t\tleftMargin, bottomMargin)', rotation, scaleX, scaleY)\n\t\tIf drawBottomRight Then DrawImageRect(Self.image,\n\t\t\t\tx+width-rightMargin, y+height-bottomMargin, srcX+srcWidth-rightMargin, srcY+srcHeight-bottomMargin,\n\t\t\t\trightMargin, bottomMargin)', rotation, scaleX, scaleY)\n\t\t\n\t\t' scales for stretching\n\t\tLocal stretchScaleX:Float = (width-leftMargin-rightMargin) \/ (srcWidth-leftMargin-rightMargin)\n\t\tLocal stretchScaleY:Float = (height-topMargin-bottomMargin) \/ (srcHeight-topMargin-bottomMargin)\n\t\t\n\t\t' draw edges\n\t\tIf drawLeft Then DrawImageRect(Self.image,\n\t\t\t\tx, y+topMargin, srcX, srcY+topMargin,\n\t\t\t\tleftMargin, srcHeight-topMargin-bottomMargin,\n\t\t\t\t0, 1, stretchScaleY)\n\t\tIf drawRight Then DrawImageRect(Self.image,\n\t\t\t\tx+width-rightMargin, y+topMargin, srcX+srcWidth-rightMargin, srcY+topMargin,\n\t\t\t\trightMargin, srcHeight-topMargin-bottomMargin,\n\t\t\t\t0, 1, stretchScaleY)\n\t\tIf drawTop Then DrawImageRect(Self.image,\n\t\t\t\tx+leftMargin, y, srcX+leftMargin, srcY,\n\t\t\t\tsrcWidth-leftMargin-rightMargin, topMargin,\n\t\t\t\t0, stretchScaleX, 1)\n\t\tIf drawBottom Then DrawImageRect(Self.image,\n\t\t\t\tx+leftMargin, y+height-bottomMargin, srcX+leftMargin, srcY+srcHeight-bottomMargin,\n\t\t\t\tsrcWidth-leftMargin-rightMargin, bottomMargin,\n\t\t\t\t0, stretchScaleX, 1)\n\t\t\n\t\t' draw center\n\t\tIf drawCenter Then DrawImageRect(Self.image,\n\t\t\t\tx+leftMargin, y+topMargin, srcX+leftMargin, srcY+topMargin,\n\t\t\t\tsrcWidth-leftMargin-rightMargin, srcHeight-topMargin-bottomMargin,\n\t\t\t\t0, stretchScaleX, stretchScaleY)\n\tEnd\n\t\n\tMethod PreCache:Void()\n\t\tDrawImage Self.image, -Self.w-50, -Self.h-50\n\tEnd\n\t\n\tMethod ReadPixelsArray:Void()\n\t\tCls 0, 0, 0\n\t\tLocal posX:Int = SCREEN_WIDTH2\n\t\tLocal posY:Int = SCREEN_HEIGHT2\n\t\tDrawImage Self.image, posX, posY\n\t\tIf readPixels\n\t\t\tReadPixels(pixels, posX - image.HandleX(), posY - image.HandleY(), image.Width(), image.Height())\n\t\t\treadPixelsComplete = True\n\t\t\tPixelArrayMask(pixels, maskRed, maskGreen, maskBlue)\t\t\n\t\tEnd\t\n\tEnd\n\t\nEnd\n\n'summary: Sound resource bank\n'Images must be stored in sounds folder\nClass SoundBank Extends StringMap\n\t\n\tGlobal path$ = \"sounds\/\"\n\t\n\tMethod Load:GameSound(name:String, nameoverride:String = \"\", ignoreCache:Bool = False, soundDelay:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\t' check if we already have the sound in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old sound if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).sound.Discard()\n\t\t\n\t\tLocal s:GameSound = New GameSound\n\t\ts.Load(name, preLoad, screenName)\n\t\ts.name = storeKey\n\t\ts.soundDelay = soundDelay\n\t\tSelf.Set(s.name, s)\n\t\tReturn s\n\tEnd\n\t \n\tMethod Find:GameSound(name:String)\n\t\tname = name.ToUpper()\n\n\t\t' debug: print all keys in the map\n\t\tIf diddyGame.debugOn\n\t\t\tFor Local key:String = EachIn Self.Keys()\n\t\t\t\tLocal i:GameSound = Self.Get(key)\n\t\t\t\tIf Not i.preLoad Then Print key + \" is stored in the sound map.\"\n\t\t\tNext\n\t\tEnd\n\t\t\n\t\tLocal i:GameSound = Self.Get(name)\n\t\tLocal err:String = \"Sound '\" + name + \"' not found in the SoundBank\"\n\t\tIf i.preLoad and i.sound = null Then AssertError(err)\n\t\tAssertNotNull(i, err)\n\t\tReturn i\n\tEnd\nEnd\n\n'summary: GameSound Class\nClass GameSound\n\tField name:String\n\tField sound:Sound\n\tField rate:Float = 1\n\tField pan:Float = 0\n\tField volume:Float = 1\n\tField loop:Int = 0\n\tField channel:Int\n\tField loopChannelList:IntArrayList = New IntArrayList\n\tField soundAvailableMillis:Int\n\tField soundDelay:Int\n\tField stopChannelBeforePlaying:Bool = true\n\tField screenName:String\n\tField preLoad:Bool\n\tField path:String\n\t\n\tMethod Load:Void(file:String, preLoad:Bool = False, screenName:String = \"\")\n\t\tSelf.path = file\n\t\tSelf.preLoad = preLoad\n\t\tSelf.screenName = screenName\n\t\tIf Not preLoad\n\t\t\tIf file.Contains(\".wav\") Or file.Contains(\".ogg\") Or file.Contains(\".mp3\") Or file.Contains(\".m4a\") Or file.Contains(\".wma\") Then\n\t\t\t\tsound = LoadSoundSample(SoundBank.path + file)\n\t\t\tElse\n\t\t\t\t#if TARGET=\"flash\"\n\t\t\t\t\tsound = LoadSoundSample(SoundBank.path + file +\".mp3\")\n\t\t\t\t#else If TARGET=\"android\"\n\t\t\t\t\tsound = LoadSoundSample(SoundBank.path + file +\".ogg\")\n\t\t\t\t#else\n\t\t\t\t\tsound = LoadSoundSample(SoundBank.path + file +\".wav\")\n\t\t\t\t#endif\n\t\t\tEnd\n\t\tEnd\n\t\tname = StripAll(file.ToUpper())\n\tEnd\n\t\n\tMethod Play:Bool(playChannel:Int = -1, force:Bool=False)\n\t\tIf force Or soundDelay = 0 Or soundAvailableMillis < dt.currentticks\n\t\t\tif stopChannelBeforePlaying And Self.IsPlaying()\n\t\t\t\tSelf.Stop()\n\t\t\tEnd\n\t\t\tchannel = SoundPlayer.PlayFx(sound, pan, rate, volume * (diddyGame.soundVolume \/ 100.0), loop, playChannel)\n\t\t\tIf loop = 1\n\t\t\t\tloopChannelList.Add(channel)\n\t\t\tEnd\n\t\t\tsoundAvailableMillis = dt.currentticks + soundDelay\n\t\t\tReturn True\n\t\tEnd\n\t\tReturn False\n\tEnd\n\t\n\tMethod Stop:Void()\n\t\tSoundPlayer.PlayerStopChannel(channel)\n\t\tIf loopChannelList.Size > 0\n\t\t\tLocal ch:Int\n\t\t\tFor Local i:Int = 0 Until loopChannelList.Size\n\t\t\t\tch = loopChannelList.GetInt(i)\n\t\t\t\tSoundPlayer.PlayerStopChannel(ch)\n\t\t\tNext\n\t\t\tloopChannelList.Clear()\n\t\tEnd\n\tEnd\n\n\tMethod IsPlaying:Int()\n\t\t#if TARGET=\"flash\"\n\t\t\tReturn 0\n\t\t#end\n\t\tReturn(ChannelState(channel))\n\tEnd\n\t\n\tMethod Pause:Void()\n\t\tIf IsPlaying() Then\n\t\t\tPauseChannel(channel)\n\t\tEnd\n\tEnd\n\n\tMethod Resume:Void()\n\t\tIf IsPlaying() Then\n\t\t\tResumeChannel(channel)\n\t\tEnd\n\tEnd\nEnd\n\n'summary: SoundPlayer Class\nClass SoundPlayer\n\tGlobal channel:Int\n\tConst MAX_CHANNELS:Int = 31\n\tGlobal playerChannelState:Int[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ' 32 indexes - (0 to 31)\n\t\n\tFunction StopChannels:Void()\n\t\tFor Local i:Int = 0 To MAX_CHANNELS\n\t\t\tStopChannel(i)\n\t\t\tplayerChannelState[i] = 0\n\t\tNext\n\tEnd\n\t\n\tFunction PlayerStopChannel:Void(playerChannel:Int)\n\t\tStopChannel(playerChannel)\n\t\tplayerChannelState[playerChannel] = 0\n\tEnd\n\t\n\tFunction PlayFx:Int(s:Sound, pan:Float=0, rate:Float=1, volume:Float=1, loop:Int = 0, playChannel:Int = -1)\n\t\tIf playChannel = -1 Then\n\t\t\tLocal cnt:Int = 0\n\t\t\tchannel += 1\n\t\t\tIf (channel > MAX_CHANNELS) Then channel = 0\n\t\t\tWhile playerChannelState[channel] = 1 ' channel State doesnt work with Flash\n\t\t\t\tchannel += 1\n\t\t\t\tIf (channel > MAX_CHANNELS) Then channel = 0\n\t\t\t\tcnt=+1\n\t\t\t\tIf cnt > MAX_CHANNELS * 2 Then Exit ' stop infinite loop if case all channels are playing\n\t\t\tEnd\n\t\tElse\n\t\t\tchannel = playChannel\n\t\t\tplayerChannelState[playChannel] = 0\n\t\tEnd\n\n\t\tStopChannel(channel)\n\t\tPlaySound(s, channel, loop)\n\t\tSetChannelPan(channel, pan)\n\t\tSetChannelRate(channel, rate)\n\t\tSetChannelVolume(channel, volume)\n\t\tIf loop Then playerChannelState[channel] = 1\t\t\n\t\tReturn channel\n\tEnd\n\t\nEnd\n\n'summary: Sprite Class\nClass Sprite\n\tField name:String\n\tField visible:Bool = True\n\tField x:Float, y:Float\n\tField ox:Float, oy:Float\n\tField dx:Float, dy:Float\n\tField speedX:Float, speedY:Float, speed:Float\n\tField maxXSpeed:Float, maxYSpeed:Float\n\tField image:GameImage\n\tField scaleX:Float = 1, scaleY:Float = 1\n\n\tField red:Int = 255, green:Int = 255, blue:Int = 255, alpha:Float = 1\n\tField hitBox:HitBox\n\n\t' Animation\n\tField frame:Int\n\tField frameTimer:Int\n\tField frameStart:Int\n\tField frameEnd:Int\n\tField frameSpeed:Int = 0 \n\tField reverse:Bool = False\n\tField pingPong:Bool = False\n\tField loop:Bool = True\n\tField ping:Int\n\t\n\t' Scale\n\tField scaleCounter:Float = 0\n\tField scaleXSpeed:Float = 0.1\n\tField scaleYSpeed:Float = 0.1\n\tField ygravity:Float\n\tField maxFrame:Int\n\t\n\t' Rotation\n\tField rotationCounter:Float = 0\n\tField rotationLength:Int = 1000\n\tField rotationLoop:Int = 0\n\tField rotation:Float\n\tField rotationSpeed:Float = 1\n\t\n\tMethod New(img:GameImage, x:Float, y:Float)\n\t\tSelf.image = img\n\t\tSelf.x = x\n\t\tSelf.y = y\n\t\tSelf.alpha = 1\n\t\tSelf.SetHitBox(-img.image.HandleX(), -img.image.HandleY(), img.w, img.h)\n\t\tSelf.visible = True\n\tEnd\n\t\n\tMethod SetImage:Void(gi:GameImage)\n\t\timage = gi\n\t\tGetSize()\n\tEnd\n\t\n\tMethod GetSize:Void()\n\t\t'Sets w and h based on the current image.\n\t\tIf image <> Null Then\n\t\t\timage.w = image.image.Width()\n\t\t\timage.h = image.image.Height()\n\t\t\timage.w2 = image.w\/2\n\t\t\timage.h2 = image.h\/2\n\t\tEnd\t\n\tEnd\n\t\n\tMethod Precache:Void()\n\t\tDrawImage image.image, -image.w-50, -image.h-50\t\t\n\tEnd\n\t\n\tMethod SetRGB:Void(r:Int, g:Int ,b:Int)\n\t\tSelf.red = r\n\t\tSelf.green = g\n\t\tSelf.blue = b\n\tEnd\n\t\n\tMethod SetScaleXY:Void(sx:Float, sy:Float)\n\t\tSelf.scaleX = sx\n\t\tSelf.scaleY = sy\n\tEnd\n\t\n\tMethod Move:Void()\n\t\tSelf.x+=Self.dx * dt.delta\n\t\tSelf.y+=Self.dy * dt.delta\n\t\t\n\t\tIf ygravity > 0 Then dy += ygravity * dt.delta\n\tEnd\n\t\n\tMethod ManageScale:Void()\n\t\tIf scaleCounter>0 Then\n\t\t\tscaleCounter-=1*dt.delta\n\t\t\tscaleX+=scaleXSpeed*dt.delta\n\t\t\tscaleY+=scaleYSpeed*dt.delta\n\t\tEnd\n\tEnd\n\t\n\tMethod ManageRotation:Void()\n\t\tIf rotationLoop Then\n\t\t\trotation+=rotationSpeed*dt.delta\n\t\t\tIf rotation >= 360 Then rotation-=360\n\t\t\tIf rotation <0 Then rotation+=360\n\t\tElse\n\t\t\tIf rotationCounter>0 Then\n\t\t\t\trotationCounter-=1 * dt.delta\n\t\t\t\trotation+=rotationSpeed * dt.delta\n\t\t\tEnd\n\t\tEnd\n\tEnd\n\t\n\tMethod MoveForward:Void()\n\t\tdx = -Sin(rotation) * speed\n\t\tdy = -Cos(rotation) * speed\n\n\t\tMove()\n\tEnd\n\n\tMethod SetFrame:Void(startFrame:Int=0, endFrame:Int=0, speed:Int=125, pingPong:Bool = False, loop:Bool = True)\n\t\tframe = startFrame\n\t\tframeStart = startFrame\n\t\tframeEnd = endFrame\n\t\tIf startFrame > endFrame\n\t\t\treverse = True\n\t\tElse\n\t\t\treverse = False\n\t\tEnd\n\t\tSelf.pingPong = pingPong\n\t\tSelf.loop = loop\n\t\tframeSpeed = speed\n\t\tframeTimer = Millisecs()\n\t\tping = 0\n\tEnd\n\t\n\t'summary: Animation process, deals with changing frames. Returns 1 if the animation has finished (only for non looping animations).\n\tMethod UpdateAnimation:Int()\n\t\tLocal rv:Int = 0\n\t\tIf frameSpeed > 0\n\t\t\tIf Millisecs() > frameTimer + frameSpeed\n\t\t\t\tIf Not reverse\n\t\t\t\t\tframe+=1\n\t\t\t\t\tIf frame > frameEnd\n\t\t\t\t\t\trv = ResetAnim()\n\t\t\t\t\tEnd\n\t\t\t\tElse\n\t\t\t\t\tframe-=1\n\t\t\t\t\tIf frame < frameEnd\n\t\t\t\t\t\trv = ResetAnim()\n\t\t\t\t\tEnd\t\t\t\n\t\t\t\tEnd\n\t\t\t\tframeTimer = Millisecs()\n\t\t\tEnd\t\n\t\tEnd\n\t\tReturn rv\n\tEnd\n\t\n\tMethod ResetAnim:Int()\n\t\tIf loop Then\n\t\t\tIf pingPong\n\t\t\t\treverse = Not reverse\n\t\t\t\tframe = frameEnd\n\t\t\t\tLocal ts% = frameStart\n\t\t\t\tframeStart = frameEnd\n\t\t\t\tframeEnd = ts\n\t\t\tElse\n\t\t\t\tframe = frameStart\n\t\t\tEnd\n\t\tElse\n\t\t\tIf pingPong And ping <1\n\t\t\t\treverse = Not reverse\n\t\t\t\tframe = frameEnd\n\t\t\t\tLocal ts% = frameStart\n\t\t\t\tframeStart = frameEnd\n\t\t\t\tframeEnd = ts\n\t\t\t\tping+=1\n\t\t\tElse\n\t\t\t\tframe = frameEnd\n\t\t\t\tReturn 1\n\t\t\tEnd\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\tMethod Draw:Void()\n\t\tDraw(0,0)\n\tEnd\n\t\n\tMethod Draw:Void(rounded:Bool)\n\t\tDraw(0,0, rounded)\n\tEnd\n\t\n\tMethod Draw:Void(offsetx:Float, offsety:Float, rounded:Bool = False)\n\t\tIf Not visible Then Return\n\t\t\n\t\tIf x - offsetx + (image.w * scaleX) + (image.h * scaleY) < 0 Or\n\t\t\tx - offsetx - (image.w * scaleX) - (image.h * scaleY) >= SCREEN_WIDTH Or\n\t\t\ty - offsety + (image.h * scaleY) + (image.w * scaleX) < 0 Or \n\t\t\ty - offsety - (image.h * scaleY) - (image.w * scaleX) >= SCREEN_HEIGHT Then Return\n\n\t\tIf Self.alpha > 1 Then Self.alpha = 1\n\t\tIf Self.alpha < 0 Then Self.alpha = 0\n\t\t\n\t\tSetAlpha Self.alpha\n\t\tSetColor red, green, blue\n\t\tIf rounded\n\t\t\tDrawImage(image.image, Floor(x - offsetx + 0.5), Floor(y- offsety + 0.5), rotation, scaleX, scaleY, frame)\n\t\tElse\n\t\t\tDrawImage(image.image, x - offsetx, y - offsety, rotation, scaleX, scaleY, frame)\n\t\tEnd\n\t\t\n\t\tSetColor 255, 255, 255\n\t\tSetAlpha 1\n\tEnd\n\t\n\tMethod DrawHitBox:Void(offsetx:Float = 0, offsety:Float = 0)\n\t\tIf Not visible Then Return\n\t\t' Draw the midhandle\n\t\tDrawRect x - 1 - offsetx, y - 1 - offsety, 2, 2\n\t\t' Draw the hit box\n\t\tDrawRectOutline(x + hitBox.x - offsetx, y + hitBox.y - offsety, hitBox.w, hitBox.h)\n\tEnd\n\n\tMethod SetupRotation:Void(rotationSpeed:Float, length:Int, loop:Bool = False, rndPosition:Bool = False)\t\n\t\tSelf.rotationSpeed = rotationSpeed\n\t\tIf loop Then\n\t\t\trotationLoop = 1\n\t\t\tIf rndPosition Then rotation = Rnd(0,360)\n\t\tElse\n\t\t\trotationLength = length\n\t\t\trotationCounter = rotationLength \t\n\t\tEnd\n\tEnd\n\t\n\tMethod Collide:Int(sprite:Sprite)\n\t\tReturn RectsOverlap(x + hitBox.x, y + hitBox.y, hitBox.w, hitBox.h,\n\t\t\t\t\t\t\tsprite.x +sprite.hitBox.x, sprite.y + sprite.hitBox.y, sprite.hitBox.w, sprite.hitBox.h)\n\tEnd\n\t\t\n\tMethod SetHitBox:Void(hitX:Int, hitY:Int, hitWidth:Int, hitHeight:Int)\n\t\thitBox = New HitBox(hitX, hitY, hitWidth, hitHeight)\n\tEnd\nEnd\n\n'summary: Simple HitBox class\nClass HitBox\n\tField x:Float, y:Float\n\tField w:Float, h:Float\n\t\n\tMethod New(x:Float, y:Float, w:Float, h:Float)\n\t\tSelf.x = x\n\t\tSelf.y = y\n\t\tSelf.w = w\n\t\tSelf.h = h\n\tEnd\nEnd\n\n'summary: Particle Class\nClass Particle Extends Sprite\n\tGlobal MAX_PARTICLES:Int = 800\n\tGlobal particles:Particle[MAX_PARTICLES]\n\tGlobal lastDeath:Int = 0\n\tGlobal maxIndex:Int = -1\n\tGlobal minIndex:Int = -1\n\tGlobal particleCount:Int = 0\n\tField lifeCounter:Float = 0\n\tField fadeIn:Float = 0\n\tField fadeCounter:Float\n\tField fadeInLength:Float = 0\n\tField fadeLength:Float = 0\n\tField active:Int = 0\n\t\n\tFunction Cache:Void()\n\t\tFor Local i:Int = 0 To MAX_PARTICLES - 1\n\t\t\tparticles[i] = New Particle()\n\t\tNext\n\tEnd\n\t\n\tFunction Create:Particle(gi:GameImage, x:Float, y:Float, dx:Float = 0, dy:Float = 0, gravity:Float = 0, fadeLength:Float = 0, lifeCounter:Int = 0)\n\t\tLocal i%=lastDeath\n\t\tRepeat\n\t\t\tIf particles[i] = Null Then particles[i] = New Particle()\n\t\t\tIf Not particles[i].active Then\n\t\t\t\tparticles[i].SetImage(gi)\n\t\t\t\tparticles[i].x = x\n\t\t\t\tparticles[i].y = y\n\t\t\t\tparticles[i].dx = dx\n\t\t\t\tparticles[i].dy = dy\n\n\t\t\t\tparticles[i].ygravity = gravity\n\t\t\t\tparticles[i].fadeLength = fadeLength \/ 10\n\t\t\t\tparticles[i].fadeCounter = particles[i].fadeLength\n\t\t\t\tIf lifeCounter>0 Then particles[i].lifeCounter = lifeCounter \/ 10\n\t\t\t\tparticles[i].active = 1\n\t\t\t\tIf maxIndex < 0 Or i > maxIndex Then maxIndex = i\n\t\t\t\tIf minIndex < 0 Or i < minIndex Then minIndex = i\n\t\t\t\tparticleCount += 1\n\t\t\t\tReturn particles[i]\n\t\t\tEnd\n\t\t\ti += 1\n\t\t\tIf i >= MAX_PARTICLES Then i = 0\n\t\tUntil i = lastDeath\n\t\tReturn Null\n\tEnd\n\t\n\tFunction Clear:Void()\n\t\tFor Local i:Int = 0 To MAX_PARTICLES - 1\n\t\t\tparticles[i].alpha = 0\n\t\t\tparticles[i].active = False\n\t\tNext\n\t\tminIndex = -1\n\t\tmaxIndex = -1\n\t\tparticleCount = 0\n\t\tlastDeath = 0\n\tEnd\n\t\n\tFunction DrawAll:Void(offsetx:Float = 0, offsety:Float = 0)\n\t\tIf minIndex < 0 Or maxIndex < 0 Then Return\n\t\tFor Local i% = minIndex To maxIndex\n\t\t\tIf particles[i] <> Null And particles[i].image <> Null\n\t\t\t\tIf particles[i].fadeCounter > 0 And particles[i].active Then\n\t\t\t\t\tIf particles[i].fadeIn Then\n\t\t\t\t\t\tparticles[i].alpha = particles[i].fadeCounter\/particles[i].fadeInLength\n\t\t\t\t\tElse\n\t\t\t\t\t\tparticles[i].alpha = particles[i].fadeCounter\/particles[i].fadeLength\n\t\t\t\t\tEnd\n\t\t\t\tEnd\n\t\t\t\tparticles[i].Draw(offsetx, offsety)\n\t\t\tEnd\n\t\tNext\n\tEnd\n\t\n\tFunction UpdateAll:Void()\n\t\tIf minIndex < 0 Or maxIndex < 0 Then Return\n\t\tLocal newMinIndex:Int = -1\n\t\tLocal newMaxIndex:Int = -1\n\t\tFor Local i:Int = minIndex To maxIndex\n\t\t\tIf particles[i] <> Null And particles[i].image <> Null\n\t\t\t\tIf particles[i].active\n\t\t\t\t\tparticles[i].Update()\n\t\t\t\t\tIf particles[i].active Then\n\t\t\t\t\t\tIf newMinIndex < 0 Then newMinIndex = i\n\t\t\t\t\t\tnewMaxIndex = i\n\t\t\t\t\tElse\n\t\t\t\t\t\tlastDeath = i\n\t\t\t\t\t\tparticleCount -= 1\n\t\t\t\t\tEnd\n\t\t\t\tEnd\n\t\t\tEnd\n\t\tNext\n\t\tminIndex = newMinIndex\n\t\tmaxIndex = newMaxIndex\n\tEnd\t\n\t\n\tMethod Update:Void()\n\t\tSuper.Move()\n\n\t\tIf fadeIn Then\n\t\t\tfadeCounter+=dt.delta\n\n\t\t\tIf fadeCounter >= fadeInLength Then\n\t\t\t\tfadeCounter = fadeLength\n\t\t\t\tfadeIn = 0\n\t\t\t\talpha = 1\n\t\t\tEnd\n\t\tElseif fadeCounter>0 Then\n\t\t\tfadeCounter-=dt.delta\n\t\t\tIf fadeCounter <= 0 Then\n\t\t\t\talpha = 0\n\t\t\t\tactive = 0\n\t\t\tEnd \n\t\tEnd\n\tEnd\nEnd\n\n'summary: Simple Mouse functions class\nClass DiddyMouse\n\tField lastX:Int\n\tField lastY:Int\n\n\tMethod New()\n\t\tMouseZInit()\n\tEnd\n\t\n\t'summary: Returns the MouseX speed\n\tMethod MouseXSpeed:Int()\n\t\tReturn diddyGame.mouseX - lastX\n\tEnd\n\t\n\t'summary: Returns the MouseY speed\n\tMethod MouseYSpeed:Int()\n\t\tReturn diddyGame.mouseY - lastY\n\tEnd\n\t\n\t'summary: Updates the last positions\n\tMethod Update:Void()\n\t\tlastX = diddyGame.mouseX\n\t\tlastY = diddyGame.mouseY\n\tEnd\nEnd\n\n'summary: Wrapper function for MouseXSpeed\nFunction MouseXSpeed:Int()\n\tReturn diddyGame.diddyMouse.MouseXSpeed()\nEnd\n\n'summary: Wrapper function for MouseYSpeed\nFunction MouseYSpeed:Int()\n\tReturn diddyGame.diddyMouse.MouseYSpeed()\nEnd\n","old_contents":"#Rem\nCopyright (c) 2011 Steve Revill and Shane Woolcock\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n#End\n\n#rem\nHeader: The Screen-Based Diddy Game Framework\nThis framework allows developers to quickly build screens and move between them quickly.\nAlso included are image and sound resource managers, a delta timer, sprite and particle classes.\nExample of how to set up the DiddyApp:\n[code]\nStrict\n\nImport diddy\n\nFunction Main:Int()\n\tNew MyGame()\n\tReturn 0\nEnd\n\nGlobal titleScreen:TitleScreen\n\nClass MyGame extends DiddyApp\n\tMethod Create:Void()\n\t\ttitleScreen = New TitleScreen\n\t\tStart(titleScreen)\n\tEnd\nEnd\n\nClass TitleScreen Extends Screen\n\tMethod New()\n\t\tname = \"Title\"\n\tEnd\n\t\n\tMethod Start:Void()\n\t\t' Load and set up items here\n\tEnd\n\t\n\tMethod Render:Void()\n\t\tCls\n\t\tDrawText \"TITLE SCREEN!\", SCREEN_WIDTH2, SCREEN_HEIGHT2, 0.5, 0.5\n\t\tDrawText \"Escape to Quit!\", SCREEN_WIDTH2, SCREEN_HEIGHT2 + 40, 0.5, 0.5\n\tEnd\n\t\n\tMethod Update:Void()\n\t\tIf KeyHit(KEY_ESCAPE)\n\t\t\t' fading to Null is the same as fading to diddyGame.exitScreen (which exits the game)\n\t\t\tFadeToScreen(Null)\n\t\tEnd\n\tEnd\nEnd\n[\/code]\n#End\nStrict\n\nImport mojo\nImport functions\nImport collections\nImport inputcache\nImport xml\nImport diddydata\n\n'Device width and height\nGlobal DEVICE_WIDTH:Float\nGlobal DEVICE_HEIGHT:Float\n\n' Screen width and height\nGlobal SCREEN_WIDTH:Float\nGlobal SCREEN_HEIGHT:Float\n\n' Half of SCREEN_WIDTH and HEIGHT\nGlobal SCREEN_WIDTH2:Float\nGlobal SCREEN_HEIGHT2:Float\n\n' Used for Virtual Res\nGlobal SCREENX_RATIO:Float = 1\nGlobal SCREENY_RATIO:Float = 1\n\n' THE GAME!!\nGlobal diddyGame:DiddyApp\n\n' Used for delta timing movement\nGlobal dt:DeltaTimer\n\n' Default fade time\nGlobal defaultFadeTime:Float = 600\n\n'Summary: The main class extends Mojo App\nClass DiddyApp Extends App\n\n\tField debugKeyOn:Bool = False\n\tField debugOn:Bool = False\n\tField drawFPSOn:Bool = False\n\tField debugKey:Int = KEY_F1\n\t\n\tField virtualResOn:Bool = True\n\tField aspectRatioOn:Bool = False\n\tField autoCls:Bool = False\n\n\tField aspectRatio:Float\n\tField multi:Float\n\tField widthBorder:Float\t\t\t\t' Size of border at sides\n\tField heightBorder:Float\t\t\t' Size of border at top\/bottom\n\t\n\tField deviceChanged:Int\t\t\t\t' Device size changed\n\tField virtualScaledW:Float\n\tField virtualScaledH:Float\n\tField virtualXOff:Float\n\tField virtualYOff:Float\n\t\n\tField FPS:Int = 60\n\t\n\t' current Screen\n\tField currentScreen:Screen\n\t' next Screen\n\tField nextScreen:Screen\n\t' exit Screen\n\tField exitScreen:ExitScreen\n\t' used for fading\n\tField screenFade:ScreenFade\n\t' scroll\n\tField scrollX:Float\n\tField scrollY:Float\n\t\n\t' mouse\n\tField mouseX:Int, mouseY:Int\n\tField mouseHit:Int\n\tField diddyMouse:DiddyMouse\n\t\n\t' store the images here\n\tField images:ImageBank\n\t' store the sounds here\n\tField sounds:SoundBank\n\t' store screens\n\tField screens:Screens\n\t\n\t' volume control\n\tField musicFile:String = \"\"\n\tField soundVolume:Int = 100\n\tField musicVolume:Int = 100\n\tField mojoMusicVolume:Float = 1.0\n\tField musicOkay:Int\n\t\n\tField clickSound:GameSound\n\t\n\t' input\n\tField inputCache:InputCache\n\n\t' fixed rate logic stuff\n\tField frameRate:Float = 200 ' speed the logic runs at\n\tField ms:Float = 0 ' milliseconds per frame eg 1000ms\/200framerate = 5ms per frame\n\tField tmpMs:Float\n\tField numTicks:Float\n\tField lastNumTicks:Float\n\tField maxMs:Int = 50\n\tField lastTime:Float\n\t\n\tField diddyData:DiddyData\n\t\nPrivate\n\tField useFixedRateLogic:Bool = False\n\tField vsx:Float, vsy:Float, vsw:Float, vsh:Float\n\t\nPublic\n\tMethod New()\n\t\t' DiddyApp now assigns itself to game, so you just need to do: New MyGame()\n\t\t' Assigning it manually will have no effect, but won't break anything.\n\t\tdiddyGame = Self\n\t\tSelf.screens = New Screens\n\t\tSelf.exitScreen = New ExitScreen\n\t\tSelf.screenFade = New ScreenFade\n\t\tSelf.images = New ImageBank\n\t\tSelf.sounds = New SoundBank\n\t\tSelf.inputCache = New InputCache\n\t\tdiddyMouse = New DiddyMouse\n\tEnd\n\t\t\t\n\tMethod OnCreate:Int()\n\t\tTry\n\t\t\t' Store the device width and height\n\t\t\tDEVICE_WIDTH = DeviceWidth()\n\t\t\tDEVICE_HEIGHT = DeviceHeight()\n\t\t\t\n\t\t\tSetScreenSize(DEVICE_WIDTH, DEVICE_HEIGHT)\n\t\t\tdeviceChanged = True\n\t\t\t\n\t\t\t' set the mouse x,y\n\t\t\tmouseX = MouseX() \/ SCREENX_RATIO\n\t\t\tmouseY = MouseY() \/ SCREENY_RATIO\n\t\t\t\n\t\t\t' Set the Random seed\n\t\t\tSeed = RealMillisecs()\n\t\t\t' Create the delta timer\n\t\t\tdt = New DeltaTimer(FPS)\n\t\t\t' Set the update rate\n\t\t\tSetUpdateRate FPS\n\t\t\t\n\t\t\t'create all the particles\n\t\t\tParticle.Cache()\n\t\t\t\n\t\t\t' fixed rate logic timing\n\t\t\tIf useFixedRateLogic\n\t\t\t\tResetFixedRateLogic()\n\t\t\tEnd\n\t\t\t\n\t\t\t'call Create\n\t\t\tCreate()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\t'summary: Main creation method\n\tMethod Create:Void()\n\tEnd\n\t\n\t'summary: Sets up the virtual resolution\n\tMethod SetScreenSize:Void(w:Float, h:Float, useAspectRatio:Bool = False)\n\t\tSCREEN_WIDTH = w\n\t\tSCREEN_HEIGHT = h\n\t\tSCREEN_WIDTH2 = SCREEN_WIDTH \/ 2\n\t\tSCREEN_HEIGHT2 = SCREEN_HEIGHT \/ 2\n\t\t\n\t\tSCREENX_RATIO = DEVICE_WIDTH\/SCREEN_WIDTH\n\t\tSCREENY_RATIO = DEVICE_HEIGHT\/SCREEN_HEIGHT\n\t\t\n\t\tIf SCREENX_RATIO <> 1 Or SCREENY_RATIO <> 1\n\t\t\tvirtualResOn = True\n\t\t\taspectRatioOn = useAspectRatio\n\t\t\taspectRatio = h \/ w\n\t\tEnd\n\t\tIf DeviceWidth() <> SCREEN_WIDTH Or DeviceHeight() <> SCREEN_HEIGHT Then\n\t\t\tdeviceChanged = True\n\t\tEnd\n\tEnd\n\n\tMethod OnRender:Int()\n\t\tTry\n\t\t\tFPSCounter.Update()\n\t\t\tIf virtualResOn\n\t\t\t\tPushMatrix\n\t\t\t\tIf aspectRatioOn\n\t\t\t\t\tIf (DeviceWidth() <> DEVICE_WIDTH) Or (DeviceHeight() <> DEVICE_HEIGHT) Or deviceChanged\n\t\t\t\t\t\tDEVICE_WIDTH = DeviceWidth()\n\t\t\t\t\t\tDEVICE_HEIGHT = DeviceHeight()\n\t\t\t\t\t\tdeviceChanged = False\n\n\t\t\t\t\t\tLocal deviceRatio:Float = DEVICE_HEIGHT \/ DEVICE_WIDTH\n\t\t\t\t\t\tIf deviceRatio >= aspectRatio\n\t\t\t\t\t\t\tmulti = DEVICE_WIDTH \/ SCREEN_WIDTH\n\t\t\t\t\t\t\theightBorder = (DEVICE_HEIGHT - SCREEN_HEIGHT * multi) * 0.5\n\t\t\t\t\t\t\twidthBorder = 0\n\t\t\t\t\t\tElse\n\t\t\t\t\t\t\tmulti = DEVICE_HEIGHT \/ SCREEN_HEIGHT \n\t\t\t\t\t\t\twidthBorder = (DEVICE_WIDTH - SCREEN_WIDTH * multi) * 0.5\n\t\t\t\t\t\t\theightBorder = 0\n\t\t\t\t\t\tEnd\n\t\t\t\t\t\n\t\t\t\t\t\tvsx = Max(0.0, widthBorder )\n\t\t\t\t\t\tvsy = Max(0.0, heightBorder )\n\t\t\t\t\t\tvsw = Min(DEVICE_WIDTH - widthBorder * 2.0, DEVICE_WIDTH)\n\t\t\t\t\t\tvsh = Min(DEVICE_HEIGHT- heightBorder * 2.0, DEVICE_HEIGHT)\n\t\t\t\t\t\t\n\t\t\t\t\t\tvirtualScaledW = (SCREEN_WIDTH * multi)\n\t\t\t\t\t\tvirtualScaledH = (SCREEN_HEIGHT * multi)\n\t\t\t\t\t\t\n\t\t\t\t\t\tvirtualXOff = (DEVICE_WIDTH - virtualScaledW) * 0.5\n\t\t\t\t\t\tvirtualYOff = (DEVICE_HEIGHT - virtualScaledH) * 0.5\n\t\t\t\t\t\t\n\t\t\t\t\t\tvirtualXOff = virtualXOff \/ multi\n\t\t\t\t\t\tvirtualYOff = virtualYOff\/ multi\n\t\t\t\t\tEnd\n\t\t\t\t\t\n\t\t\t\t\tSetScissor 0, 0, DEVICE_WIDTH , DEVICE_HEIGHT \n\t\t\t\t\tCls 0, 0, 0\n\t\t\t\t\t\n\t\t\t\t\tSetScissor vsx, vsy, vsw, vsh\n\t\t\n\t\t\t\t\tScale multi, multi\n\n\t\t\t\t\tTranslate virtualXOff, virtualYOff \n\t\t\t\tElse\n\t\t\t\t\tScale SCREENX_RATIO, SCREENY_RATIO\n\t\t\t\tEnd\n\t\t\tEnd\n\t\t\t\n\t\t\t' auto cls\n\t\t\tIf autoCls Then Cls()\n\t\t\t\n\t\t\t' render the screen\n\t\t\tcurrentScreen.RenderBackgroundLayers()\n\t\t\tcurrentScreen.Render()\n\t\t\tcurrentScreen.RenderForegroundLayers()\n\t\t\t\n\t\t\tIf virtualResOn\n\t\t\t\tIf aspectRatioOn\n\t\t\t\t\tSetScissor 0, 0, DEVICE_WIDTH , DEVICE_HEIGHT\n\t\t\t\tEnd\n\t\t\t\tPopMatrix\n\t\t\tEnd\n\t\t\t\n\t\t\tcurrentScreen.ExtraRender()\n\t\t\tIf screenFade.active Then screenFade.Render()\n\t\t\tcurrentScreen.DebugRender()\n\t\t\tIf debugOn\n\t\t\t\tDrawDebug()\n\t\t\tEnd\n\t\t\tIf drawFPSOn\n\t\t\t\tDrawFPS()\n\t\t\tEnd\n\t\t\tdiddyMouse.Update()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\n\tMethod ReadInputs:Void()\n\t\tIf aspectRatioOn\n\t\t\tLocal mouseOffsetX:Float = MouseX() - DEVICE_WIDTH * 0.5\n\t\t\tLocal x:Float = (mouseOffsetX \/ multi) \/ 1 + (SCREEN_WIDTH * 0.5)\n\t\t\tmouseX = x\n\t\t\tLocal mouseOffsetY:Float = MouseY() - DEVICE_HEIGHT * 0.5\n\t\t\tLocal y:Float = (mouseOffsetY \/ multi) \/ 1 + (SCREEN_HEIGHT * 0.5)\n\t\t\tmouseY = y\n\t\tElse\n\t\t\tmouseX = MouseX() \/ SCREENX_RATIO\n\t\t\tmouseY = MouseY() \/ SCREENY_RATIO\n\t\tEnd\n\t\tmouseHit = MouseHit()\n\t\tinputCache.ReadInput()\n\t\tinputCache.HandleEvents(currentScreen)\n\t\t\n\t\tIf debugKeyOn\n\t\t\tIf KeyHit(debugKey)\n\t\t\t\tdebugOn = Not debugOn\n\t\t\tEnd\n\t\tEnd\n\tEnd\n\t\n\tMethod OnUpdate:Int()\n\t\tTry\n\t\t\tReadInputs()\n\t\t\tOverrideUpdate()\n\t\t\tIf useFixedRateLogic\n\t\t\t\tLocal now:Int = Millisecs()\n\t\t\t\tIf now < lastTime\n\t\t\t\t\tnumTicks = lastNumTicks\n\t\t\t\tElse\n\t\t\t\t\ttmpMs = now - lastTime\n\t\t\t\t\tIf tmpMs > maxMs tmpMs = maxMs\n\t\t\t\t\tnumTicks = tmpMs \/ ms\n\t\t\t\tEndif\n\t\t\t\n\t\t\t\tlastTime = now\n\t\t\t\tlastNumTicks = numTicks\n\t\t\t\tFor Local i:Int = 1 To Floor(numTicks)\n\t\t\t\t\tUpdate(1)\n\t\t\t\tNext\n\t\t\t\t\n\t\t\t\tLocal re:Float = numTicks Mod 1\n\t\t\t\tIf re > 0 Then\n\t\t\t\t\tUpdate(re)\n\t\t\t\tEnd\n\t\t\tElse\n\t\t\t\tUpdate(0)\n\t\t\tEnd\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\t\n\t\tReturn 0\n\tEnd\n\t\n\tMethod OverrideUpdate:Void()\n\tEnd\n\n\tMethod Update:Void(fixedRateLogicDelta:Float)\n\t\tdt.UpdateDelta()\n\t\tIf useFixedRateLogic\n\t\t\tdt.delta = fixedRateLogicDelta\n\t\tEnd\n\n\t\tIf screenFade.active Then screenFade.Update()\n\t\tIf Not screenFade.active Or screenFade.allowScreenUpdate Then currentScreen.Update()\n\tEnd\n\n\t'summary: Draws debug information\n\tMethod DrawDebug:Void()\n\t\tSetColor 255, 255, 255\n\t\tFPSCounter.Draw(0,0)\n\t\tLocal y:Int = 10\n\t\tLocal gap:Int = 14\n\t\tDrawText \"Screen = \"+currentScreen.name, 0, y\n\t\ty += gap\n\t\tDrawText \"Delta = \"+FormatNumber(dt.delta, 2) , 0, y\n\t\ty += gap\n\t\tDrawText \"Frame Time = \"+dt.frametime , 0, y\t\t\n\t\ty += gap\n\t\tDrawText \"Screen Width = \"+SCREEN_WIDTH, 0, y\n\t\ty += gap\n\t\tDrawText \"Screen Height = \"+SCREEN_HEIGHT, 0, y\n\t\ty += gap\n\t\tDrawText \"VMouseX = \"+Self.mouseX, 0, y\n\t\ty += gap\n\t\tDrawText \"VMouseY = \"+Self.mouseY, 0, y\n\t\ty += gap\n\t\tDrawText \"MouseX = \"+MouseX(), 0, y\n\t\ty += gap\n\t\tDrawText \"MouseY = \"+MouseY(), 0, y\n\t\ty += gap\n\t\tDrawText \"Music File = \"+musicFile, 0, y\n\t\ty += gap\n\t\tDrawText \"MusicOkay = \"+musicOkay, 0, y\n\t\ty += gap\n\t\tDrawText \"Music State = \"+MusicState(), 0, y\n\t\ty += gap\n\t\tDrawText \"Music Volume = \"+Self.musicVolume, 0, y\n\t\ty += gap\n\t\tDrawText \"Mojo Music Volume = \"+Self.mojoMusicVolume, 0, y\n\t\ty += gap\n\t\tDrawText \"Sound Volume = \"+Self.soundVolume, 0, y\n\t\ty += gap\n\t\tDrawText \"Sound Channel = \"+SoundPlayer.channel, 0, y\n\t\ty += gap\n\t\tDrawText \"Back Screen Name = \"+currentScreen.backScreenName, 0, y\n\t\ty += gap\n\tEnd\n\t\n\t'summary: Draws current FPS at 0,0\n\tMethod DrawFPS:Void()\n\t\tDrawText FPSCounter.totalFPS, 0, 0\n\tEnd\n\t\n\t'summary: Wrapper for PlayMusic\n\tMethod MusicPlay:Void(file:String, flags:Int=1)\n\t\tmusicFile = file\n\t\t\n\t\tmusicOkay = PlayMusic(\"music\/\"+musicFile, flags)\n\t\tIf musicOkay = -1\n\t\t\tPrint \"Error Playing Music - Music must be in the data\\music folder\"\n\t\tEnd\n\tEnd\n\t\n\t'summary: Sets the Music volume\n\tMethod MusicSetVolume:Void(volume:Int)\n\t\tIf volume < 0 Then volume = 0\n\t\tIf volume > 100 Then volume = 100\n\t\tSelf.musicVolume = volume\n\t\tSetMojoMusicVolume(musicVolume\/100.0)\n\tEnd\n\t\n\tMethod SetMojoMusicVolume:Void(volume:Float)\n\t\tIf volume < 0 Then volume = 0\n\t\tIf volume > 1 Then volume = 1\n\t\tmojoMusicVolume = volume\n\t\tSetMusicVolume(mojoMusicVolume)\n\tEnd\n\t\n\tMethod SoundSetVolume:Void(volume:Int)\n\t\tIf volume < 0 Then volume = 0\n\t\tIf volume > 100 Then volume = 100\n\t\tSelf.soundVolume = volume\n\t\tFor Local i% = 0 To SoundPlayer.MAX_CHANNELS\n\t\t\tSetChannelVolume(i, diddyGame.soundVolume \/ 100.0)\n\t\tNext\n\tEnd\n\t\n\t'summary: returns an animation length in game frames\n\tMethod CalcAnimLength:Float(ms:Int)\n\t\tReturn ms \/ (1000.0 \/ FPS)\n\tEnd\n\t\n\tMethod UseFixedRateLogic:Bool() Property\n\t\tReturn Self.useFixedRateLogic\n\tEnd\n\t\n\tMethod UseFixedRateLogic:Void(useFrl:Bool) Property\n\t\tSelf.useFixedRateLogic = useFrl\n\t\tResetFixedRateLogic()\n\tEnd\n\t\n\tMethod ResetFixedRateLogic:Void()\n\t\tms = 1000 \/ frameRate\n\t\tnumTicks = 0\n\t\tlastNumTicks = 1\n\t\tlastTime = Millisecs()\n\t\tIf dt <> Null\n\t\t\tdt.delta = 1\n\t\tEnd\n\tEnd\n\t\n\t' convenience method that will trigger a fade in and call PreStart() on the screen (used for first screen)\n\tMethod Start:Void(firstScreen:Screen, autoFadeIn:Bool=True, fadeInTime:Float=defaultFadeTime, fadeSound:Bool=False, fadeMusic:Bool=False)\n\t\tfirstScreen.autoFadeIn = autoFadeIn\n\t\tIf autoFadeIn Then\n\t\t\tfirstScreen.autoFadeInTime = fadeInTime\n\t\t\tfirstScreen.autoFadeInSound = fadeSound\n\t\t\tfirstScreen.autoFadeInMusic = fadeMusic\n\t\tEnd\n\t\tfirstScreen.PreStart()\n\tEnd\n\t\n\tMethod OnSuspend:Int()\n\t\tTry\n\t\t\tcurrentScreen.Suspend()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\n\tMethod OnResume:Int()\n\t\tTry\n\t\t\tdt.currentticks = Millisecs()\n\t\t\tdt.lastticks = dt.currentticks\n\t\t\tcurrentScreen.Resume()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\tMethod OnBack:Int()\n\t\tTry\n\t\t\tcurrentScreen.Back()\n\t\tCatch e:DiddyException\n\t\t\tPrint(e.ToString(True))\n\t\t\tError(e.ToString(False))\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\t'summary: Loads in the diddydata xml file\n\tMethod LoadDiddyData:Void(filename:String=\"diddydata.xml\")\n\t\tautoCls = True\n\t\tdiddyData = New DiddyData(filename)\n\tEnd\nEnd\n\n\n'summary: Map to store the Screens\nClass Screens Extends StringMap\r\n\tMethod Set:Bool(key:String, value:Screen)\r\n\t\tReturn Super.Set(key.ToUpper(), value)\r\n\tEnd\r\n\t\n\tMethod Find:Screen(name:String)\n\t\tname = name.ToUpper()\n\n\t\t' debug: print all keys in the map\n\t\tIf diddyGame.debugOn\n\t\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\t\tPrint key + \" is stored in the Screens map.\"\n\t\t\tNext\n\t\tEnd\n\n\t\tLocal i:Screen = Self.Get(name)\n\t\tAssertNotNull(i, \"Screen '\" + name + \"' not found in the Screens map\")\n\t\tReturn i\n\tEnd\nEnd\n\n'summary: Simple screen fading\nClass ScreenFade\n\tField fadeTime:Float\n\tField fadeOut:Bool\n\tField ratio:Float = 0\n\tField active:Bool\n\tField counter:Float\n\tField fadeMusic:Bool\n\tField fadeSound:Bool\n\tField allowScreenUpdate:Bool\n\t\n\tMethod Start:Void(fadeTime:Float, fadeOut:Bool, fadeSound:Bool = False, fadeMusic:Bool = False, allowScreenUpdate:Bool = True)\n\t\tIf active Then Return\n\t\tactive = True\n\t\tSelf.fadeTime = diddyGame.CalcAnimLength(fadeTime)\n\t\tSelf.fadeOut = fadeOut\n\t\tSelf.fadeMusic = fadeMusic\n\t\tSelf.fadeSound = fadeSound\n\t\tSelf.allowScreenUpdate = allowScreenUpdate\n\t\tIf fadeOut Then\n\t\t\tratio = 1\n\t\tElse\n\t\t\tratio = 0\n\t\t\t' set the music volume to zero if fading in the music\n\t\t\tIf Self.fadeMusic\n\t\t\t\tdiddyGame.SetMojoMusicVolume(0)\n\t\t\tEnd\t\t\t\n\t\tEnd\n\t\tcounter = 0\n\tEnd\n\n\tMethod Update:Void()\n\t\tIf Not active Return\n\t\tcounter += dt.delta\n\t\tCalcRatio()\n\t\tIf fadeSound Then\n\t\t\tFor Local i% = 0 To SoundPlayer.MAX_CHANNELS\n\t\t\t\tSetChannelVolume(i, (ratio) * (diddyGame.soundVolume \/ 100.0))\n\t\t\tNext\n\t\tEnd\n\t\tIf fadeMusic Then\n\t\t\tdiddyGame.SetMojoMusicVolume((ratio) * (diddyGame.musicVolume \/ 100.0))\n\t\tEnd\n\t\tIf counter > fadeTime\n\t\t\tactive = False\n\t\t\tIf fadeOut\t\t\t\n\t\t\t\tdiddyGame.currentScreen.PostFadeOut()\n\t\t\tElse\n\t\t\t\tdiddyGame.currentScreen.PostFadeIn()\n\t\t\tEnd\n\t\tEnd\n\tEnd\n\t\t\n\tMethod CalcRatio:Void()\n\t\tratio = counter\/fadeTime\n\t\tIf ratio < 0\n\t\t\tratio = 0\n\t\t\tIf fadeMusic\n\t\t\t\tdiddyGame.SetMojoMusicVolume(0)\n\t\t\tEnd\n\t\tEnd\n\t\tIf ratio > 1\n\t\t\tratio = 1\n\t\t\tIf fadeMusic\n\t\t\t\tdiddyGame.SetMojoMusicVolume(diddyGame.musicVolume \/ 100.0)\n\t\t\tEnd\n\t\tEnd\n\t\tIf fadeOut Then\n\t\t\tratio = 1 - ratio\n\t\tEnd\n\tEnd\n\t\n\tMethod Render:Void()\n\t\tIf Not active Return\n\t\tSetAlpha 1 - ratio\n\t\tSetColor 0, 0, 0\n\t\tDrawRect 0, 0, DEVICE_WIDTH, DEVICE_HEIGHT\n\t\tSetAlpha 1\n\t\tSetColor 255, 255, 255\n\tEnd\n\t\nEnd\n\n'summary: Screen to exit the application\nClass ExitScreen Extends Screen\n\tMethod New()\n\t\tSuper.New(\"exit\")\n\tEnd\n\t\n\tMethod Start:Void()\n\t\tExitApp()\n\tEnd\n\t\n\tMethod Render:Void()\n\tEnd \n\t\n\tMethod Update:Void()\n\tEnd\nEnd\n\n'summary: Abstract Screen class\nClass Screen Abstract\nPrivate\n\tField autoFadeIn:Bool = False\n\tField autoFadeInTime:Float = 50\n\tField autoFadeInSound:Bool = False\n\tField autoFadeInMusic:Bool = False\n\tField musicPath:String\n\tField musicFlag:Int\n\nPublic\n\tField name:String = \"\"\n\tField backScreenName:String = \"\"\n\tField layers:DiddyDataLayers\n\t\n\tMethod New(name:String=\"\")\n\t\tSelf.name = name\n\tEnd\n\t\n\tMethod PreStart:Void()\n\t\tdiddyGame.screens.Set(name, Self)\n\t\tdiddyGame.currentScreen = Self\n\t\tIf autoFadeIn Then\n\t\t\tautoFadeIn = False\n\t\t\tdiddyGame.screenFade.Start(autoFadeInTime, False, autoFadeInSound, autoFadeInMusic)\n\t\tEnd\n\t\t\n\t\t' load screens graphics\n\t\tLocal tmpImage:Image\n\t\tFor Local key:String = EachIn diddyGame.images.Keys()\n\t\t\tLocal i:GameImage = diddyGame.images.Get(key)\n\t\t\tIf i.preLoad And i.screenName.ToUpper() = name.ToUpper()\n\t\t\t\tIf i.frames > 1\n\t\t\t\t\ti.LoadAnim(i.path, i.w, i.h, i.frames, tmpImage, i.midhandle, i.readPixels, i.maskRed, i.maskGreen, i.maskBlue, False, i.screenName)\n\t\t\t\tElse\n\t\t\t\t\ti.Load(i.path, i.midhandle, i.readPixels, i.maskRed, i.maskGreen, i.maskBlue, False, i.screenName)\n\t\t\t\tEnd\n\t\t\tEnd\n\t\tNext\n\t\t\n\t\t' load screens sounds\n\t\tFor Local key:String = EachIn diddyGame.sounds.Keys()\n\t\t\tLocal i:GameSound = diddyGame.sounds.Get(key)\n\t\t\tIf i.preLoad And i.screenName.ToUpper() = name.ToUpper()\n\t\t\t\ti.Load(i.path, False, i.screenName)\n\t\t\tEnd\n\t\tNext\n\t\t\n\t\t' play the screen's music if its set\n\t\tIf musicPath <> \"\" Then diddyGame.MusicPlay(musicPath, musicFlag)\n\t\t\n\t\tStart()\n\tEnd\n\t\n\tMethod RenderBackgroundLayers:Void()\n\t\tIf layers Then\n\t\t\tFor Local layer:DiddyDataLayer = Eachin layers\n\t\t\t\tIf layer.index >= 0 Then Return\n\t\t\t\tlayer.Render()\n\t\t\tNext\n\t\tEnd\n\tEnd\n\t\n\tMethod RenderForegroundLayers:Void()\n\t\tIf layers Then\n\t\t\tFor Local layer:DiddyDataLayer = Eachin layers\n\t\t\t\tIf layer.index >= 0 Then\n\t\t\t\t\tlayer.Render()\n\t\t\t\tEnd\n\t\t\tNext\n\t\tEnd\n\tEnd\n\t\n\tMethod Start:Void() Abstract\n\t\n\tMethod Render:Void() Abstract\n\t\n\tMethod Update:Void() Abstract\n\t\n\tMethod Back:Void()\n\t\tIf backScreenName=\"exit\" Then\n\t\t\tFadeToScreen(Null)\n\t\tElseIf backScreenName Then\n\t\t\tLocal scr:Screen = diddyGame.screens.Find(backScreenName)\n\t\t\tIf scr Then FadeToScreen(scr)\n\t\tEnd\n\tEnd\n\t\n\tMethod Suspend:Void()\n\tEnd\n\n\tMethod Resume:Void()\n\tEnd\n\n\tMethod PostFadeOut:Void()\n\t\tKill()\n\t\tdiddyGame.nextScreen.PreStart()\n\tEnd\n\t\n\tMethod Kill:Void()\n\tEnd\n\t\n\tMethod PostFadeIn:Void()\n\tEnd\n\t\n\tMethod ExtraRender:Void()\n\tEnd\n\t\n\tMethod DebugRender:Void()\n\tEnd\n\t\n\t' fired when you first touch the screen\n\tMethod OnTouchHit:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n\t\n\t' fired when you release a finger from the screen\n\tMethod OnTouchReleased:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n\t\n\t' fired when one of your fingers drags along the screen\n\tMethod OnTouchDragged:Void(x:Int, y:Int, dx:Int, dy:Int, pointer:Int)\n\tEnd\n\t\n\tMethod OnTouchClick:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n \n\t' fired if you touch the screen and hold the finger in the same position for one second (configurable using game.inputCache.LongPressTime)\n\t' this is checked at a specific time after touching the screen, so if you move your finger around and then\n\t' hold it still, it won't fire\n\tMethod OnTouchLongPress:Void(x:Int, y:Int, pointer:Int)\n\tEnd\n\n\t' fired after you release a finger from the screen, if it was moving fast enough (configurable using game.inputCache.FlingThreshold)\n\t' velocityx\/y\/speed is in pixels per second, but speed is taken from the entire vector, by pythagoras\n\t' ie. velocitySpeed = Sqrt(velocityX*velocityX + velocityY*velocityY) in pixels per second\n\tMethod OnTouchFling:Void(releaseX:Int, releaseY:Int, velocityX:Float, velocityY:Float, velocitySpeed:Float, pointer:Int)\n\tEnd\n\t\n\t' fired once if any key was hit (before OnKeyHit)\n\tMethod OnAnyKeyHit:Void()\n\tEnd\n\t\n\t' fired for each key that was hit\n\tMethod OnKeyHit:Void(key:Int)\n\tEnd\n\t\n\t' fired once if any key is down (before OnKeyDown)\n\tMethod OnAnyKeyDown:Void()\n\tEnd\n\t\n\t' fired for each key that is down\n\tMethod OnKeyDown:Void(key:Int)\n\tEnd\n\t\n\t' fired once if any key was released (before OnKeyReleased)\n\tMethod OnAnyKeyReleased:Void()\n\tEnd\n\t\n\t' fired for each key that was released\n\tMethod OnKeyReleased:Void(key:Int)\n\tEnd\n\t\n\tMethod OnMouseHit:Void(x:Int, y:Int, button:Int)\n\tEnd\n\t\n\tMethod OnMouseDown:Void(x:Int, y:Int, button:Int)\n\tEnd\n\t\n\tMethod OnMouseReleased:Void(x:Int, y:Int, button:Int)\n\tEnd\n\t\n\t'summary: convenience method\n\tMethod FadeToScreen:Void(screen:Screen, fadeTime:Float = defaultFadeTime, fadeSound:Bool = False, fadeMusic:Bool = False, allowScreenUpdate:Bool = True)\n\t\t' don't try to fade twice\n\t\tIf diddyGame.screenFade.active Then Return\n\t\t\n\t\t' if the screen is null, assume we're exiting\n\t\tIf Not screen Then screen = diddyGame.exitScreen\n\t\t\n\t\t' configure the autofade values\n\t\tscreen.autoFadeIn = True\n\t\tscreen.autoFadeInTime = fadeTime\n\t\tscreen.autoFadeInSound = fadeSound\n\t\tscreen.autoFadeInMusic = fadeMusic\n\t\t\n\t\t' trigger the fade out\n\t\tdiddyGame.nextScreen = screen\n\t\tdiddyGame.screenFade.Start(fadeTime, True, fadeSound, fadeMusic, allowScreenUpdate)\n\tEnd\n\t\n\t'summary: sets the screen's music which autoplays when the screen starts\n\tMethod SetMusic:Void(path:String, flag:Int = 0)\n\t\tSelf.musicPath = path\n\t\tSelf.musicFlag = flag\n\tEnd\nEnd\n\n'summary: Simple Frames per second counter\nClass FPSCounter Abstract\n\tGlobal fpsCount:Int\n\tGlobal startTime:Int\n\tGlobal totalFPS:Int\n\n\tFunction Update:Void()\n\t\tIf Millisecs() - startTime >= 1000\n\t\t\ttotalFPS = fpsCount\n\t\t\tfpsCount = 0\n\t\t\tstartTime = Millisecs()\n\t\tElse\n\t\t\tfpsCount+=1\n\t\tEnd\n\tEnd\n\n\tFunction Draw:Void(x% = 0, y% = 0, ax# = 0, ay# = 0)\n\t\tDrawText(\"FPS: \" + totalFPS, x, y, ax, ay)\n\tEnd\nEnd\n\n'summary: DeltaTimer by James Boyd\nClass DeltaTimer\n\tField targetfps:Float = 60\n\tField currentticks:Float\n\tField lastticks:Float\n\tField frametime:Float\n\tField delta:Float\n\t\n\tMethod New (fps:Float)\n\t\ttargetfps = fps\n\t\tlastticks = Millisecs()\n\tEnd\n\t\n\tMethod UpdateDelta:Void()\n\t\tcurrentticks = Millisecs()\n\t\tframetime = currentticks - lastticks\n\t\tdelta = frametime \/ (1000.0 \/ targetfps)\n\t\tlastticks = currentticks\n\tEnd\nEnd\n\n'summary: Image resource bank\n'Images must be stored in graphics folder\nClass ImageBank Extends StringMap\n\tConst ATLAS_PREFIX:String = \"_diddyAtlas_\"\n\tConst SPARROW_ATLAS:Int = 0\n\tConst LIBGDX_ATLAS:Int = 1\n\t\n\tField path:String = \"graphics\/\"\n\t\n\tMethod LoadAtlas:Void(fileName:String, format:Int = SPARROW_ATLAS, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tIf format = SPARROW_ATLAS\n\t\t\tLoadSparrowAtlas(fileName, midHandle, readPixels, maskRed, maskGreen, maskBlue)\n\t\tElseif format = LIBGDX_ATLAS\n\t\t\tLoadLibGdxAtlas(fileName, midHandle, readPixels, maskRed, maskGreen, maskBlue)\n\t\tElse\n\t\t\tError \"Invalid atlas format\"\n\t\tEnd\n\tEnd\n\t\n\tMethod LoadAtlasString:String(fileName:String)\n\t\tLocal str:String = LoadString(path + fileName)\n\t\t' check to see if the file is valid\n\t\tAssertNotEqualInt(str.Length(), 0, \"Error loading Atlas \"+ path + fileName)\n\t\tReturn str\t\t\n\tEnd\n\t\n\tMethod SaveAtlasToBank:String(pointer:Image, fileName:String)\n\t\t' save the whole atlas with prefix\n\t\tLocal atlasGameImage:GameImage = New GameImage\n\t\tatlasGameImage.name = ATLAS_PREFIX + StripAll(fileName).ToUpper()\n\t\tatlasGameImage.image = pointer\n\t\tatlasGameImage.CalcSize()\n\t\tSelf.Set(atlasGameImage.name, atlasGameImage)\n\t\tReturn atlasGameImage.name\n\tEnd\n\t\n\tMethod LoadLibGdxAtlas:Void(fileName:String, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tLocal str:String = LoadAtlasString(fileName)\n\t\tLocal all:String[] = str.Split(\"~n\")\n\t\tLocal spriteFileName:String = all[0].Trim()\n\t\tLocal pointer:Image = LoadImage(path + spriteFileName)\n\t\tAssertNotNull(pointer, \"Error loading bitmap atlas \"+ path + spriteFileName)\n\t\tLocal atlasGameImageName:String = SaveAtlasToBank(pointer, fileName)\n\t\t\n\t\tLocal line:String = \"\"\n\t\tLocal i:Int = 4\n\t\tLocal xy:String[] =[\"\",\"\"]\n\t\tLocal debug:Bool = False\n\t\tWhile True\n\t\t\t' name of the image\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"name = \"+line\n\t\t\tIf line = \"\" Then Exit\n\t\t\tLocal name:String = line\n\t\t\t'rotate\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"rotate = \"+line\n\t\t\tLocal rotate:String = line\n\t\t\t' x and y\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"x and y = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal x:Int = Int(xy[0].Trim())\n\t\t\tLocal y:Int = Int(xy[1].Trim())\n\t\t\t' width and height\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"width and height = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal width:Int = Int(xy[0].Trim())\n\t\t\tLocal height:Int = Int(xy[1].Trim())\n\t\t\t' origX and origY\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"origX and origY = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal origX:Int = Int(xy[0].Trim())\n\t\t\tLocal origY:Int = Int(xy[1].Trim())\n\t\t\t' offsets\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"offsets = \"+line\n\t\t\txy = line[ (line.FindLast(\":\")+1)..].Split(\",\")\n\t\t\tLocal offsetX:Int = Int(xy[0].Trim())\n\t\t\tLocal offsetY:Int = Int(xy[1].Trim())\n\t\t\t'index\n\t\t\ti+=1\n\t\t\tline = all[i].Trim()\n\t\t\tIf debug Then Print \"index = \"+line\n\t\t\tLocal index:Int = Int(line[ (line.FindLast(\":\") + 1) ..].Trim())\n\t\t\ti+=1\n\t\t\tLocal gi:GameImage = New GameImage\n\t\t\tIf index > - 1\n\t\t\t\tname += index\n\t\t\tEnd\n\t\t\tIf debug\n\t\t\t\tPrint \"name = \" + name\n\t\t\t\tPrint \"x = \" + x\n\t\t\t\tPrint \"y = \" + y\n\t\t\t\tPrint \"width = \" + width\n\t\t\t\tPrint \"height = \" + height\n\t\t\t\tPrint \"origX = \" + origX\n\t\t\t\tPrint \"origY = \" + origY\n\t\t\t\tPrint \"offsetX = \" + offsetX\n\t\t\t\tPrint \"offsetY = \" + offsetY\n\t\t\t\tPrint \"index = \" + index\n\t\t\tEnd\n\t\t\t\n\t\t\tgi.name = name.ToUpper()\n\t\t\tgi.image = pointer.GrabImage(x, y, width, height)\n\t\t\tgi.CalcSize()\n\t\t\tgi.MidHandle(midHandle)\n\t\t\t\n\t\t\tgi.atlasName = atlasGameImageName\n\t\t\tgi.subX = x\n\t\t\tgi.subY = y\n\t\t\tgi.readPixels = readPixels\n\t\t\tgi.SetMaskColor(maskRed, maskGreen, maskBlue)\n\t\t\t\n\t\t\tSelf.Set(gi.name, gi)\n\t\tWend\n\t\t\n\tEnd\n\t\n\tMethod LoadSparrowAtlas:Void(fileName:String, midHandle:Bool=True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tLocal str:String = LoadAtlasString(fileName)\n\t\t' parse the xml\n\t\tLocal parser:XMLParser = New XMLParser\n\t\tLocal doc:XMLDocument = parser.ParseString(str)\n\t\tLocal rootElement:XMLElement = doc.Root\n\t\tLocal spriteFileName:String = rootElement.GetAttribute(\"imagePath\")\n\t\t\n\t\tLocal pointer:Image = LoadImage(path + spriteFileName)\n\t\tAssertNotNull(pointer, \"Error loading bitmap atlas \"+ path + spriteFileName)\n\t\t\n\t\tLocal atlasGameImageName:String = SaveAtlasToBank(pointer, fileName)\n\t\t\n\t\tFor Local node:XMLElement = Eachin rootElement.GetChildrenByName(\"SubTexture\")\n\t\t\tLocal x:Int = Int(node.GetAttribute(\"x\").Trim())\n\t\t\tLocal y:Int = Int(node.GetAttribute(\"y\").Trim())\n\t\t\tLocal width:Int = Int(node.GetAttribute(\"width\").Trim())\n\t\t\tLocal height:Int = Int(node.GetAttribute(\"height\").Trim())\n\t\t\tLocal name:String = node.GetAttribute(\"name\").Trim()\n\n\t\t\tLocal gi:GameImage = New GameImage\n\t\t\tgi.name = name.ToUpper()\n\t\t\tgi.image = pointer.GrabImage(x, y, width, height)\n\t\t\tgi.CalcSize()\n\t\t\tgi.MidHandle(midHandle)\n\t\t\t\n\t\t\tgi.atlasName = atlasGameImageName\n\t\t\tgi.subX = x\n\t\t\tgi.subY = y\n\t\t\tgi.readPixels = readPixels\n\t\t\tgi.SetMaskColor(maskRed, maskGreen, maskBlue)\n\t\t\tSelf.Set(gi.name, gi)\n\t\tNext\n\tEnd\n\t\n\tMethod Load:GameImage(name:String, nameoverride:String = \"\", midhandle:Bool = True, ignoreCache:Bool = False, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\t' check if we already have the image in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old image if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).image.Discard()\n\t\tLocal i:GameImage = New GameImage\n\t\ti.Load(path + name, midhandle, readPixels, maskRed, maskGreen, maskBlue, preLoad, screenName)\n\t\ti.name = storeKey\n\t\tSelf.Set(i.name, i)\n\t\tReturn i\n\tEnd\n\t\n\tMethod LoadAnim:GameImage(name:String, w:Int, h:Int, total:Int, tmpImage:Image, midhandle:Bool = True, ignoreCache:Bool = False, nameoverride:String = \"\", readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\t' check if we already have the image in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old image if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).image.Discard()\n\n\t\tLocal i:GameImage = New GameImage\n\t\ti.LoadAnim(path + name, w, h, total, tmpImage, midhandle, readPixels, maskRed, maskGreen, maskBlue, preLoad, screenName)\n\t\ti.name = storeKey\n\t\tSelf.Set(i.name, i)\n\t\tReturn i\n\tEnd\n \n\tMethod LoadTileset:GameImage(name:String, tileWidth%, tileHeight%, tileMargin% = 0, tileSpacing% = 0, nameoverride:String = \"\", midhandle:Bool=False, ignoreCache:Bool=False, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\t' check if we already have the image in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old image if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).image.Discard()\n\t\t\n\t\t' load the new one\n\t\tLocal i:GameImage = New GameImage\n\t\ti.LoadTileset(path + name, tileWidth, tileHeight, tileMargin, tileSpacing, midhandle, readPixels, maskRed, maskGreen, maskBlue)\n\t\ti.name = storeKey\n\t\tSelf.Set(i.name, i)\n\t\tReturn i\n\tEnd\n\t\n\tMethod Find:GameImage(name:String)\n\t\tname = name.ToUpper()\n\n\t\t' debug: print all keys in the map\n\t\tIf diddyGame.debugOn\n\t\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\t\tLocal i:GameImage = Self.Get(key)\n\t\t\t\tif Not i.preLoad Then\n\t\t\t\t\tPrint key + \" is stored in the image map.\"\n\t\t\t\tEnd\n\t\t\tNext\n\t\tEnd\n\t\tLocal i:GameImage = Self.Get(name)\n\t\tAssertNotNull(i, \"Image '\" + name + \"' not found in the ImageBank\")\n\t\tIf i.preLoad and i.image = null Then AssertError(\"Image '\" + name + \"' not found in the ImageBank\")\n\t\tReturn i\n\tEnd\n\t\n\t'summary: This returns an animation gameimage from an previous loaded Atas and adds it to the image bank.\n\t'So you get then just use Find to return the animation gameimage later.\n\t'name: The first image in the atlas\n\t'w,h: The width and height of the frames\n\t'frames: The number of frames to capture from the atlas\n\t'midhandle: Sets the midhandle of the image\n\t'nameoverride: If supplied, changes the stored name in the image bank\n\tMethod FindSet:GameImage(name:String, w:Int, h:Int, frames:Int=0, midhandle:Bool = True, nameoverride:String = \"\")\n\t\tname = name.ToUpper()\n\t\tLocal subImage:GameImage = Self.Get(name)\n\t\tAssertNotNull(subImage, \"Image '\" + name + \"' not found in the ImageBank\")\n\t\tLocal atlasGameImage:GameImage = Self.Get(subImage.atlasName)\n\t\tAssertNotNull(atlasGameImage, \"Atlas Image '\" + name + \"' not found in the ImageBank\")\n\t\tLocal image:Image = atlasGameImage.image.GrabImage(subImage.subX, subImage.subY, w, h, frames)\n\t\t\n\t\tLocal gi:GameImage = New GameImage\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = name.ToUpper()\n\t\tgi.name = storeKey\n\t\tgi.image = image\n\t\tgi.CalcSize()\n\t\tgi.MidHandle(midhandle)\n\t\tReturn gi\n\tEnd\n\t\n\tMethod PreCache:Void()\n\t\tLocal gi:GameImage\n\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\tgi = Self.Get(key)\n\t\t\tgi.PreCache()\n\t\tNext\n\tEnd\n\t\n\tMethod ReadPixelsArray:Void()\n\t\tLocal gi:GameImage\n\t\tFor Local key:String = Eachin Self.Keys()\n\t\t\tgi = Self.Get(key)\n\t\t\tgi.ReadPixelsArray()\n\t\tNext\n\tEnd\nEnd\n\n'summary: GameImage Class\nClass GameImage\n\nPrivate\n\tField pixels:Int[]\n\tField maskRed:Int = 0\n\tField maskGreen:Int = 0\n\tField maskBlue:Int = 0\n\tField preLoad:Bool = False\n\tField path:String\n\tField midhandle:Bool\n\tField screenName:String\nPublic\n\tField name:String\n\tField image:Image\n\tField w:Int\n\tField h:Int\n\tField w2:Float\n\tField h2:Float\n\tField midhandled:Int = 0\n\tField frames:Int\n\t\n\tField leftMargin:Int = 0\n\tField rightMargin:Int = 0\n\tField topMargin:Int = 0\n\tField bottomMargin:Int = 0\n\t\n\tField tileWidth:Int, tileHeight:Int\n\tField tileCountX:Int, tileCountY:Int\n\tField tileCount:Int\n\tField tileSpacing:Int, tileMargin:Int\n\t\n\tField subX:Int\n\tField subY:Int\n\tField atlasName:String\n\n\tField readPixels:Bool\n\tField readPixelsComplete:Bool = False\n\n\tMethod Pixels:Int[]() Property\n\t\tIf readPixels Then\n\t\t\tIf Not readPixelsComplete Then\n\t\t\t#If CONFIG=\"debug\"\n\t\t\t\tPrint \"Read Pixels have not been completed, please use ReadPixels on GameImage \"+name\n\t\t\t#End\n\t\t\tEnd\n\t\tEnd\n\t\tReturn pixels\n\tEnd\n\t\n\tMethod SetMaskColor:Void(r:Int, g:Int, b:Int)\n\t\tmaskRed = r\n\t\tmaskGreen = g\n\t\tmaskBlue = b\n\tEnd\n\t\n\tMethod Load:Void(file:String, midhandle:Bool = True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\tname = StripAll(file.ToUpper())\n\t\tpath = file\n\t\tSelf.midhandle = midhandle\n\t\tSelf.preLoad = preLoad\n\t\tSelf.screenName = screenName.ToUpper()\n\t\tIf Not preLoad Then\n\t\t\timage = LoadBitmap(file)\n\t\t\tCalcSize()\n\t\t\tMidHandle(midhandle)\n\t\t\tpixels = New Int[image.Width() * image.Height()]\n\t\t\tSelf.readPixels = readPixels\n\t\tEnd\n\t\tSetMaskColor(maskRed, maskGreen, maskBlue)\n\tEnd\n\t\n\tMethod LoadAnim:Void(file:String, w:Int, h:Int, total:Int, tmpImage:Image, midhandle:Bool = True, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\tname = StripAll(file.ToUpper())\n\t\tpath = file\n\t\tSelf.midhandle = midhandle\n\t\tSelf.preLoad = preLoad\n\t\tSelf.screenName = screenName.ToUpper()\n\t\tSelf.w = w\n\t\tSelf.h = h\n\t\tSelf.frames = total\n\t\tIf not preLoad Then\n\t\t\timage = LoadAnimBitmap(file, w, h, total, tmpImage)\n\t\t\tCalcSize()\n\t\t\tMidHandle(midhandle)\n\t\t\tpixels = New Int[image.Width() * image.Height()]\n\t\t\tSelf.readPixels = readPixels\n\t\tEnd\n\t\tSetMaskColor(maskRed, maskGreen, maskBlue)\n\tEnd\n\t\n\tMethod LoadTileset:Void(file:String, tileWidth:Int, tileHeight:Int, tileMargin:Int = 0, tileSpacing:Int = 0, midhandle:Bool=False, readPixels:Bool = False, maskRed:Int = 0, maskGreen:Int = 0, maskBlue:Int = 0)\n\t\tLoad(file, midhandle)\n\t\tSelf.tileWidth = tileWidth\n\t\tSelf.tileHeight = tileHeight\n\t\tSelf.tileMargin = tileMargin\n\t\tSelf.tileSpacing = tileSpacing\n\t\ttileCountX = (w - tileMargin) \/ (tileWidth + tileSpacing)\n\t\ttileCountY = (h - tileMargin) \/ (tileHeight + tileSpacing)\n\t\ttileCount = tileCountX * tileCountY\n\t\tpixels = New Int[image.Width() * image.Height()]\n\t\tSelf.readPixels = readPixels\n\t\tSetMaskColor(maskRed, maskGreen, maskBlue)\n\tEnd\n\t\n\tMethod CalcSize:Void()\n\t\tIf image <> Null Then\n\t\t\tw = image.Width()\n\t\t\th = image.Height()\n\t\t\tw2 = w\/2\n\t\t\th2 = h\/2\n\t\tEnd\n\tEnd\n\t\n\tMethod MidHandle:Void(midhandle:Bool) Property\n\t\tIf midhandle Then\n\t\t\timage.SetHandle(w2, h2)\n\t\t\tSelf.midhandled=1\n\t\tElse\n\t\t\timage.SetHandle(0, 0)\n\t\t\tSelf.midhandled=0\n\t\tEnd \n\tEnd\n\t\n\tMethod SetHandle:Void(handleX:Float, handleY:Float)\n\t\timage.SetHandle(handleX, handleY)\n\tEnd\n\t\n\tMethod MidHandle:Bool() Property\n\t\tReturn Self.midhandled = 1\n\tEnd\n\t\n\tMethod Draw:Void(x:Float, y:Float, rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\tDrawImage(Self.image, x, y, rotation, scaleX, scaleY, frame)\n\tEnd\n\t\n\tMethod DrawSubImage:Void(destX:Float, destY:Float, srcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int, rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\tDrawImageRect(Self.image, destX, destY, srcX, srcY, srcWidth, srcHeight, rotation, scaleX, scaleY, frame)\n\tEnd\n\t\n\tMethod DrawTile:Void(x:Float, y:Float, tile:Int = 0, rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1)\n\t\tLocal srcX% = tileMargin + (tileWidth + tileSpacing) * (tile Mod tileCountX)\n\t\tLocal srcY% = tileMargin + (tileHeight + tileSpacing) * (tile \/ tileCountX)\n\t\tDrawImageRect(Self.image, x, y, srcX, srcY, tileWidth, tileHeight, rotation, scaleX, scaleY)\n\tEnd\n\t\n\tMethod DrawStretched:Void(destX:Float, destY:Float, destWidth:Float, destHeight:Float,\n\t\t\trotation:Float = 0)', scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\t' scales for stretching\n\t\tLocal stretchScaleX:Float = destWidth \/ w\n\t\tLocal stretchScaleY:Float = destHeight \/ h\n\t\tDrawImage(Self.image, destX, destY, rotation, stretchScaleX, stretchScaleY)', frame)\n\tEnd\n\t\n\tMethod DrawGrid:Void(x:Float, y:Float, rw:Float, rh:Float, frame:Int = 0)\n\t\t' draw top left corner\n\t\tDrawImageRect(Self.image, x, y, 0, 0, leftMargin, topMargin, frame)\n\t\t' draw top right corner\n\t\tDrawImageRect(Self.image, x+rw-rightMargin, y, w-rightMargin, 0, rightMargin, topMargin, frame)\n\t\t' draw bottom left corner\n\t\tDrawImageRect(Self.image, x, y+rh-bottomMargin, 0, h-bottomMargin, leftMargin, bottomMargin, frame)\n\t\t' draw bottom right corner\n\t\tDrawImageRect(Self.image, x+rw-rightMargin, y+rh-bottomMargin, w-rightMargin, h-bottomMargin, rightMargin, bottomMargin, frame)\n\t\t\n\t\t' work out how many horizontal and vertical tiles\n\t\tLocal tileWidth% = (w-leftMargin-rightMargin)\n\t\tLocal tileHeight% = (h-topMargin-bottomMargin)\n\t\tLocal tileXCount% = (rw-leftMargin-rightMargin) \/ tileWidth\n\t\tLocal tileYCount% = (rh-topMargin-bottomMargin) \/ tileHeight\n\t\tLocal tileXOverflow% = (rw-leftMargin-rightMargin) Mod tileWidth\n\t\tLocal tileYOverflow% = (rh-topMargin-bottomMargin) Mod tileHeight\n\t\t\n\t\t' tile top and bottom edges\n\t\tFor Local i% = 0 Until tileXCount\n\t\t\tDrawImageRect(Self.image, leftMargin+i*tileWidth,0,leftMargin,0,tileWidth,topMargin,frame)\n\t\t\tDrawImageRect(Self.image, leftMargin+i*tileWidth,rh-bottomMargin,leftMargin,h-bottomMargin,tileWidth,bottomMargin,frame)\n\t\tNext\n\t\tIf tileXOverflow > 0 Then\n\t\t\tDrawImageRect(Self.image, leftMargin+tileXCount*tileWidth,0,leftMargin,0,tileXOverflow,topMargin,frame)\n\t\t\tDrawImageRect(Self.image, leftMargin+tileXCount*tileWidth,rh-bottomMargin,leftMargin,h-bottomMargin,tileXOverflow,bottomMargin,frame)\n\t\tEnd\n\t\t\n\t\t' tile left and right edges\n\t\tFor Local i% = 0 Until tileYCount\n\t\t\tDrawImageRect(Self.image, 0, topMargin+i*tileHeight,0,topMargin,leftMargin,tileHeight,frame)\n\t\t\tDrawImageRect(Self.image, rw-rightMargin,topMargin+i*tileHeight,w-rightMargin,topMargin,rightMargin,tileHeight,frame)\n\t\tNext\n\t\tIf tileYOverflow > 0 Then\n\t\t\tDrawImageRect(Self.image, 0, topMargin+tileYCount*tileHeight,0,topMargin,leftMargin,tileYOverflow,frame)\n\t\t\tDrawImageRect(Self.image, rw-rightMargin,topMargin+tileYCount*tileHeight,w-rightMargin,topMargin,rightMargin,tileYOverflow,frame)\n\t\tEnd\n\t\t\n\t\t' tile centre\n\t\t' TODO\n\tEnd\n\t\n\tMethod DrawSubStretched:Void(destX:Float, destY:Float, destWidth:Float, destHeight:Float, srcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int,\n\t\t\trotation:Float = 0)', scaleX:Float = 1, scaleY:Float = 1, frame:Int = 0)\n\t\t' scales for stretching\n\t\tLocal stretchScaleX:Float = destWidth \/ srcWidth\n\t\tLocal stretchScaleY:Float = destHeight \/ srcHeight\n\t\tDrawImageRect(Self.image, destX, destY, srcX, srcY, srcWidth, srcHeight, rotation, stretchScaleX, stretchScaleY)', frame)\n\tEnd\n\t\n\t' Yes, a crapload of parameters. Thankfully most of them are optional, and this will usually only be called internally by the GUI.\n\t' TODO: apply scale to parameters\n\tMethod DrawSubGrid:Void(x:Float, y:Float, width:Float, height:Float,\n\t\t\tsrcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int,\n\t\t\tleftMargin:Int, rightMargin:Int, topMargin:Int, bottomMargin:Int,\n\t\t\t'rotation:Float = 0, scaleX:Float = 1, scaleY:Float = 1,\n\t\t\tdrawTopLeft:Bool = True, drawTop:Bool = True, drawTopRight:Bool = True,\n\t\t\tdrawLeft:Bool = True, drawCenter:Bool = True, drawRight:Bool = True,\n\t\t\tdrawBottomLeft:Bool = True, drawBottom:Bool = True, drawBottomRight:Bool = True)\n\t\t' draw the corners\n\t\tIf drawTopLeft Then DrawImageRect(Self.image,\n\t\t\t\tx, y, srcX, srcY,\n\t\t\t\tleftMargin, topMargin)', rotation, scaleX, scaleY)\n\t\tIf drawTopRight Then DrawImageRect(Self.image,\n\t\t\t\tx+width-rightMargin, y, srcX+srcWidth-rightMargin, srcY,\n\t\t\t\trightMargin, topMargin)', rotation, scaleX, scaleY)\n\t\tIf drawBottomLeft Then DrawImageRect(Self.image,\n\t\t\t\tx, y+height-bottomMargin, srcX, srcY+srcHeight-bottomMargin,\n\t\t\t\tleftMargin, bottomMargin)', rotation, scaleX, scaleY)\n\t\tIf drawBottomRight Then DrawImageRect(Self.image,\n\t\t\t\tx+width-rightMargin, y+height-bottomMargin, srcX+srcWidth-rightMargin, srcY+srcHeight-bottomMargin,\n\t\t\t\trightMargin, bottomMargin)', rotation, scaleX, scaleY)\n\t\t\n\t\t' scales for stretching\n\t\tLocal stretchScaleX:Float = (width-leftMargin-rightMargin) \/ (srcWidth-leftMargin-rightMargin)\n\t\tLocal stretchScaleY:Float = (height-topMargin-bottomMargin) \/ (srcHeight-topMargin-bottomMargin)\n\t\t\n\t\t' draw edges\n\t\tIf drawLeft Then DrawImageRect(Self.image,\n\t\t\t\tx, y+topMargin, srcX, srcY+topMargin,\n\t\t\t\tleftMargin, srcHeight-topMargin-bottomMargin,\n\t\t\t\t0, 1, stretchScaleY)\n\t\tIf drawRight Then DrawImageRect(Self.image,\n\t\t\t\tx+width-rightMargin, y+topMargin, srcX+srcWidth-rightMargin, srcY+topMargin,\n\t\t\t\trightMargin, srcHeight-topMargin-bottomMargin,\n\t\t\t\t0, 1, stretchScaleY)\n\t\tIf drawTop Then DrawImageRect(Self.image,\n\t\t\t\tx+leftMargin, y, srcX+leftMargin, srcY,\n\t\t\t\tsrcWidth-leftMargin-rightMargin, topMargin,\n\t\t\t\t0, stretchScaleX, 1)\n\t\tIf drawBottom Then DrawImageRect(Self.image,\n\t\t\t\tx+leftMargin, y+height-bottomMargin, srcX+leftMargin, srcY+srcHeight-bottomMargin,\n\t\t\t\tsrcWidth-leftMargin-rightMargin, bottomMargin,\n\t\t\t\t0, stretchScaleX, 1)\n\t\t\n\t\t' draw center\n\t\tIf drawCenter Then DrawImageRect(Self.image,\n\t\t\t\tx+leftMargin, y+topMargin, srcX+leftMargin, srcY+topMargin,\n\t\t\t\tsrcWidth-leftMargin-rightMargin, srcHeight-topMargin-bottomMargin,\n\t\t\t\t0, stretchScaleX, stretchScaleY)\n\tEnd\n\t\n\tMethod PreCache:Void()\n\t\tDrawImage Self.image, -Self.w-50, -Self.h-50\n\tEnd\n\t\n\tMethod ReadPixelsArray:Void()\n\t\tCls 0, 0, 0\n\t\tLocal posX:Int = SCREEN_WIDTH2\n\t\tLocal posY:Int = SCREEN_HEIGHT2\n\t\tDrawImage Self.image, posX, posY\n\t\tIf readPixels\n\t\t\tReadPixels(pixels, posX - image.HandleX(), posY - image.HandleY(), image.Width(), image.Height())\n\t\t\treadPixelsComplete = True\n\t\t\tPixelArrayMask(pixels, maskRed, maskGreen, maskBlue)\t\t\n\t\tEnd\t\n\tEnd\n\t\nEnd\n\n'summary: Sound resource bank\n'Images must be stored in sounds folder\nClass SoundBank Extends StringMap\n\t\n\tGlobal path$ = \"sounds\/\"\n\t\n\tMethod Load:GameSound(name:String, nameoverride:String = \"\", ignoreCache:Bool = False, soundDelay:Int = 0, preLoad:Bool = False, screenName:String = \"\")\n\t\t' check if we already have the sound in the bank!\n\t\tLocal storeKey:String = nameoverride.ToUpper()\n\t\tIf storeKey = \"\" Then storeKey = StripAll(name.ToUpper())\n\t\tIf Not ignoreCache And Self.Contains(storeKey) Then Return Self.Get(storeKey)\n\t\t\n\t\t' discard the old sound if it's there\n\t\tIf Self.Contains(storeKey) Then Self.Get(storeKey).sound.Discard()\n\t\t\n\t\tLocal s:GameSound = New GameSound\n\t\ts.Load(name, preLoad, screenName)\n\t\ts.name = storeKey\n\t\ts.soundDelay = soundDelay\n\t\tSelf.Set(s.name, s)\n\t\tReturn s\n\tEnd\n\t \n\tMethod Find:GameSound(name:String)\n\t\tname = name.ToUpper()\n\n\t\t' debug: print all keys in the map\n\t\tIf diddyGame.debugOn\n\t\t\tFor Local key:String = EachIn Self.Keys()\n\t\t\t\tLocal i:GameSound = Self.Get(key)\n\t\t\t\tIf Not i.preLoad Then Print key + \" is stored in the sound map.\"\n\t\t\tNext\n\t\tEnd\n\t\t\n\t\tLocal i:GameSound = Self.Get(name)\n\t\tLocal err:String = \"Sound '\" + name + \"' not found in the SoundBank\"\n\t\tIf i.preLoad and i.sound = null Then AssertError(err)\n\t\tAssertNotNull(i, err)\n\t\tReturn i\n\tEnd\nEnd\n\n'summary: GameSound Class\nClass GameSound\n\tField name:String\n\tField sound:Sound\n\tField rate:Float = 1\n\tField pan:Float = 0\n\tField volume:Float = 1\n\tField loop:Int = 0\n\tField channel:Int\n\tField loopChannelList:IntArrayList = New IntArrayList\n\tField soundAvailableMillis:Int\n\tField soundDelay:Int\n\tField stopChannelBeforePlaying:Bool = true\n\tField screenName:String\n\tField preLoad:Bool\n\tField path:String\n\t\n\tMethod Load:Void(file:String, preLoad:Bool = False, screenName:String = \"\")\n\t\tSelf.path = file\n\t\tSelf.preLoad = preLoad\n\t\tSelf.screenName = screenName\n\t\tIf Not preLoad\n\t\t\tIf file.Contains(\".wav\") Or file.Contains(\".ogg\") Or file.Contains(\".mp3\") Or file.Contains(\".m4a\") Or file.Contains(\".wma\") Then\n\t\t\t\tsound = LoadSoundSample(SoundBank.path + file)\n\t\t\tElse\n\t\t\t\t#if TARGET=\"flash\"\n\t\t\t\t\tsound = LoadSoundSample(SoundBank.path + file +\".mp3\")\n\t\t\t\t#else If TARGET=\"android\"\n\t\t\t\t\tsound = LoadSoundSample(SoundBank.path + file +\".ogg\")\n\t\t\t\t#else\n\t\t\t\t\tsound = LoadSoundSample(SoundBank.path + file +\".wav\")\n\t\t\t\t#endif\n\t\t\tEnd\n\t\tEnd\n\t\tname = StripAll(file.ToUpper())\n\tEnd\n\t\n\tMethod Play:Bool(playChannel:Int = -1, force:Bool=False)\n\t\tIf force Or soundDelay = 0 Or soundAvailableMillis < dt.currentticks\n\t\t\tif stopChannelBeforePlaying And Self.IsPlaying()\n\t\t\t\tSelf.Stop()\n\t\t\tEnd\n\t\t\tchannel = SoundPlayer.PlayFx(sound, pan, rate, volume * (diddyGame.soundVolume \/ 100.0), loop, playChannel)\n\t\t\tIf loop = 1\n\t\t\t\tloopChannelList.Add(channel)\n\t\t\tEnd\n\t\t\tsoundAvailableMillis = dt.currentticks + soundDelay\n\t\t\tReturn True\n\t\tEnd\n\t\tReturn False\n\tEnd\n\t\n\tMethod Stop:Void()\n\t\tSoundPlayer.PlayerStopChannel(channel)\n\t\tIf loopChannelList.Size > 0\n\t\t\tLocal ch:Int\n\t\t\tFor Local i:Int = 0 Until loopChannelList.Size\n\t\t\t\tch = loopChannelList.GetInt(i)\n\t\t\t\tSoundPlayer.PlayerStopChannel(ch)\n\t\t\tNext\n\t\t\tloopChannelList.Clear()\n\t\tEnd\n\tEnd\n\n\tMethod IsPlaying:Int()\n\t\t#if TARGET=\"flash\"\n\t\t\tReturn 0\n\t\t#end\n\t\tReturn(ChannelState(channel))\n\tEnd\n\t\n\tMethod Pause:Void()\n\t\tIf IsPlaying() Then\n\t\t\tPauseChannel(channel)\n\t\tEnd\n\tEnd\n\n\tMethod Resume:Void()\n\t\tIf IsPlaying() Then\n\t\t\tResumeChannel(channel)\n\t\tEnd\n\tEnd\nEnd\n\n'summary: SoundPlayer Class\nClass SoundPlayer\n\tGlobal channel:Int\n\tConst MAX_CHANNELS:Int = 31\n\tGlobal playerChannelState:Int[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ' 32 indexes - (0 to 31)\n\t\n\tFunction StopChannels:Void()\n\t\tFor Local i:Int = 0 To MAX_CHANNELS\n\t\t\tStopChannel(i)\n\t\t\tplayerChannelState[i] = 0\n\t\tNext\n\tEnd\n\t\n\tFunction PlayerStopChannel:Void(playerChannel:Int)\n\t\tStopChannel(playerChannel)\n\t\tplayerChannelState[playerChannel] = 0\n\tEnd\n\t\n\tFunction PlayFx:Int(s:Sound, pan:Float=0, rate:Float=1, volume:Float=1, loop:Int = 0, playChannel:Int = -1)\n\t\tIf playChannel = -1 Then\n\t\t\tLocal cnt:Int = 0\n\t\t\tchannel += 1\n\t\t\tIf (channel > MAX_CHANNELS) Then channel = 0\n\t\t\tWhile playerChannelState[channel] = 1 ' channel State doesnt work with Flash\n\t\t\t\tchannel += 1\n\t\t\t\tIf (channel > MAX_CHANNELS) Then channel = 0\n\t\t\t\tcnt=+1\n\t\t\t\tIf cnt > MAX_CHANNELS * 2 Then Exit ' stop infinite loop if case all channels are playing\n\t\t\tEnd\n\t\tElse\n\t\t\tchannel = playChannel\n\t\t\tplayerChannelState[playChannel] = 0\n\t\tEnd\n\n\t\tStopChannel(channel)\n\t\tPlaySound(s, channel, loop)\n\t\tSetChannelPan(channel, pan)\n\t\tSetChannelRate(channel, rate)\n\t\tSetChannelVolume(channel, volume)\n\t\tIf loop Then playerChannelState[channel] = 1\t\t\n\t\tReturn channel\n\tEnd\n\t\nEnd\n\n'summary: Sprite Class\nClass Sprite\n\tField name:String\n\tField visible:Bool = True\n\tField x:Float, y:Float\n\tField ox:Float, oy:Float\n\tField dx:Float, dy:Float\n\tField speedX:Float, speedY:Float, speed:Float\n\tField maxXSpeed:Float, maxYSpeed:Float\n\tField image:GameImage\n\tField scaleX:Float = 1, scaleY:Float = 1\n\n\tField red:Int = 255, green:Int = 255, blue:Int = 255, alpha:Float = 1\n\tField hitBox:HitBox\n\n\t' Animation\n\tField frame:Int\n\tField frameTimer:Int\n\tField frameStart:Int\n\tField frameEnd:Int\n\tField frameSpeed:Int = 0 \n\tField reverse:Bool = False\n\tField pingPong:Bool = False\n\tField loop:Bool = True\n\tField ping:Int\n\t\n\t' Scale\n\tField scaleCounter:Float = 0\n\tField scaleXSpeed:Float = 0.1\n\tField scaleYSpeed:Float = 0.1\n\tField ygravity:Float\n\tField maxFrame:Int\n\t\n\t' Rotation\n\tField rotationCounter:Float = 0\n\tField rotationLength:Int = 1000\n\tField rotationLoop:Int = 0\n\tField rotation:Float\n\tField rotationSpeed:Float = 1\n\t\n\tMethod New(img:GameImage, x:Float, y:Float)\n\t\tSelf.image = img\n\t\tSelf.x = x\n\t\tSelf.y = y\n\t\tSelf.alpha = 1\n\t\tSelf.SetHitBox(-img.image.HandleX(), -img.image.HandleY(), img.w, img.h)\n\t\tSelf.visible = True\n\tEnd\n\t\n\tMethod SetImage:Void(gi:GameImage)\n\t\timage = gi\n\t\tGetSize()\n\tEnd\n\t\n\tMethod GetSize:Void()\n\t\t'Sets w and h based on the current image.\n\t\tIf image <> Null Then\n\t\t\timage.w = image.image.Width()\n\t\t\timage.h = image.image.Height()\n\t\t\timage.w2 = image.w\/2\n\t\t\timage.h2 = image.h\/2\n\t\tEnd\t\n\tEnd\n\t\n\tMethod Precache:Void()\n\t\tDrawImage image.image, -image.w-50, -image.h-50\t\t\n\tEnd\n\t\n\tMethod SetRGB:Void(r:Int, g:Int ,b:Int)\n\t\tSelf.red = r\n\t\tSelf.green = g\n\t\tSelf.blue = b\n\tEnd\n\t\n\tMethod SetScaleXY:Void(sx:Float, sy:Float)\n\t\tSelf.scaleX = sx\n\t\tSelf.scaleY = sy\n\tEnd\n\t\n\tMethod Move:Void()\n\t\tSelf.x+=Self.dx * dt.delta\n\t\tSelf.y+=Self.dy * dt.delta\n\t\t\n\t\tIf ygravity > 0 Then dy += ygravity * dt.delta\n\tEnd\n\t\n\tMethod ManageScale:Void()\n\t\tIf scaleCounter>0 Then\n\t\t\tscaleCounter-=1*dt.delta\n\t\t\tscaleX+=scaleXSpeed*dt.delta\n\t\t\tscaleY+=scaleYSpeed*dt.delta\n\t\tEnd\n\tEnd\n\t\n\tMethod ManageRotation:Void()\n\t\tIf rotationLoop Then\n\t\t\trotation+=rotationSpeed*dt.delta\n\t\t\tIf rotation >= 360 Then rotation-=360\n\t\t\tIf rotation <0 Then rotation+=360\n\t\tElse\n\t\t\tIf rotationCounter>0 Then\n\t\t\t\trotationCounter-=1 * dt.delta\n\t\t\t\trotation+=rotationSpeed * dt.delta\n\t\t\tEnd\n\t\tEnd\n\tEnd\n\t\n\tMethod MoveForward:Void()\n\t\tdx = -Sin(rotation) * speed\n\t\tdy = -Cos(rotation) * speed\n\n\t\tMove()\n\tEnd\n\n\tMethod SetFrame:Void(startFrame:Int=0, endFrame:Int=0, speed:Int=125, pingPong:Bool = False, loop:Bool = True)\n\t\tframe = startFrame\n\t\tframeStart = startFrame\n\t\tframeEnd = endFrame\n\t\tIf startFrame > endFrame\n\t\t\treverse = True\n\t\tElse\n\t\t\treverse = False\n\t\tEnd\n\t\tSelf.pingPong = pingPong\n\t\tSelf.loop = loop\n\t\tframeSpeed = speed\n\t\tframeTimer = Millisecs()\n\t\tping = 0\n\tEnd\n\t\n\t'summary: Animation process, deals with changing frames. Returns 1 if the animation has finished (only for non looping animations).\n\tMethod UpdateAnimation:Int()\n\t\tLocal rv:Int = 0\n\t\tIf frameSpeed > 0\n\t\t\tIf Millisecs() > frameTimer + frameSpeed\n\t\t\t\tIf Not reverse\n\t\t\t\t\tframe+=1\n\t\t\t\t\tIf frame > frameEnd\n\t\t\t\t\t\trv = ResetAnim()\n\t\t\t\t\tEnd\n\t\t\t\tElse\n\t\t\t\t\tframe-=1\n\t\t\t\t\tIf frame < frameEnd\n\t\t\t\t\t\trv = ResetAnim()\n\t\t\t\t\tEnd\t\t\t\n\t\t\t\tEnd\n\t\t\t\tframeTimer = Millisecs()\n\t\t\tEnd\t\n\t\tEnd\n\t\tReturn rv\n\tEnd\n\t\n\tMethod ResetAnim:Int()\n\t\tIf loop Then\n\t\t\tIf pingPong\n\t\t\t\treverse = Not reverse\n\t\t\t\tframe = frameEnd\n\t\t\t\tLocal ts% = frameStart\n\t\t\t\tframeStart = frameEnd\n\t\t\t\tframeEnd = ts\n\t\t\tElse\n\t\t\t\tframe = frameStart\n\t\t\tEnd\n\t\tElse\n\t\t\tIf pingPong And ping <1\n\t\t\t\treverse = Not reverse\n\t\t\t\tframe = frameEnd\n\t\t\t\tLocal ts% = frameStart\n\t\t\t\tframeStart = frameEnd\n\t\t\t\tframeEnd = ts\n\t\t\t\tping+=1\n\t\t\tElse\n\t\t\t\tframe = frameEnd\n\t\t\t\tReturn 1\n\t\t\tEnd\n\t\tEnd\n\t\tReturn 0\n\tEnd\n\t\n\tMethod Draw:Void()\n\t\tDraw(0,0)\n\tEnd\n\t\n\tMethod Draw:Void(rounded:Bool)\n\t\tDraw(0,0, rounded)\n\tEnd\n\t\n\tMethod Draw:Void(offsetx:Float, offsety:Float, rounded:Bool = False)\n\t\tIf Not visible Then Return\n\t\t\n\t\tIf x - offsetx + (image.w * scaleX) + (image.h * scaleY) < 0 Or\n\t\t\tx - offsetx - (image.w * scaleX) - (image.h * scaleY) >= SCREEN_WIDTH Or\n\t\t\ty - offsety + (image.h * scaleY) + (image.w * scaleX) < 0 Or \n\t\t\ty - offsety - (image.h * scaleY) - (image.w * scaleX) >= SCREEN_HEIGHT Then Return\n\n\t\tIf Self.alpha > 1 Then Self.alpha = 1\n\t\tIf Self.alpha < 0 Then Self.alpha = 0\n\t\t\n\t\tSetAlpha Self.alpha\n\t\tSetColor red, green, blue\n\t\tIf rounded\n\t\t\tDrawImage(image.image, Floor(x - offsetx + 0.5), Floor(y- offsety + 0.5), rotation, scaleX, scaleY, frame)\n\t\tElse\n\t\t\tDrawImage(image.image, x - offsetx, y - offsety, rotation, scaleX, scaleY, frame)\n\t\tEnd\n\t\t\n\t\tSetColor 255, 255, 255\n\t\tSetAlpha 1\n\tEnd\n\t\n\tMethod DrawHitBox:Void(offsetx:Float = 0, offsety:Float = 0)\n\t\tIf Not visible Then Return\n\t\t' Draw the midhandle\n\t\tDrawRect x - 1 - offsetx, y - 1 - offsety, 2, 2\n\t\t' Draw the hit box\n\t\tDrawRectOutline(x + hitBox.x - offsetx, y + hitBox.y - offsety, hitBox.w, hitBox.h)\n\tEnd\n\n\tMethod SetupRotation:Void(rotationSpeed:Float, length:Int, loop:Bool = False, rndPosition:Bool = False)\t\n\t\tSelf.rotationSpeed = rotationSpeed\n\t\tIf loop Then\n\t\t\trotationLoop = 1\n\t\t\tIf rndPosition Then rotation = Rnd(0,360)\n\t\tElse\n\t\t\trotationLength = length\n\t\t\trotationCounter = rotationLength \t\n\t\tEnd\n\tEnd\n\t\n\tMethod Collide:Int(sprite:Sprite)\n\t\tReturn RectsOverlap(x + hitBox.x, y + hitBox.y, hitBox.w, hitBox.h,\n\t\t\t\t\t\t\tsprite.x +sprite.hitBox.x, sprite.y + sprite.hitBox.y, sprite.hitBox.w, sprite.hitBox.h)\n\tEnd\n\t\t\n\tMethod SetHitBox:Void(hitX:Int, hitY:Int, hitWidth:Int, hitHeight:Int)\n\t\thitBox = New HitBox(hitX, hitY, hitWidth, hitHeight)\n\tEnd\nEnd\n\n'summary: Simple HitBox class\nClass HitBox\n\tField x:Float, y:Float\n\tField w:Float, h:Float\n\t\n\tMethod New(x:Float, y:Float, w:Float, h:Float)\n\t\tSelf.x = x\n\t\tSelf.y = y\n\t\tSelf.w = w\n\t\tSelf.h = h\n\tEnd\nEnd\n\n'summary: Particle Class\nClass Particle Extends Sprite\n\tGlobal MAX_PARTICLES:Int = 800\n\tGlobal particles:Particle[MAX_PARTICLES]\n\tGlobal lastDeath:Int = 0\n\tGlobal maxIndex:Int = -1\n\tGlobal minIndex:Int = -1\n\tGlobal particleCount:Int = 0\n\tField lifeCounter:Float = 0\n\tField fadeIn:Float = 0\n\tField fadeCounter:Float\n\tField fadeInLength:Float = 0\n\tField fadeLength:Float = 0\n\tField active:Int = 0\n\t\n\tFunction Cache:Void()\n\t\tFor Local i:Int = 0 To MAX_PARTICLES - 1\n\t\t\tparticles[i] = New Particle()\n\t\tNext\n\tEnd\n\t\n\tFunction Create:Particle(gi:GameImage, x:Float, y:Float, dx:Float = 0, dy:Float = 0, gravity:Float = 0, fadeLength:Float = 0, lifeCounter:Int = 0)\n\t\tLocal i%=lastDeath\n\t\tRepeat\n\t\t\tIf particles[i] = Null Then particles[i] = New Particle()\n\t\t\tIf Not particles[i].active Then\n\t\t\t\tparticles[i].SetImage(gi)\n\t\t\t\tparticles[i].x = x\n\t\t\t\tparticles[i].y = y\n\t\t\t\tparticles[i].dx = dx\n\t\t\t\tparticles[i].dy = dy\n\n\t\t\t\tparticles[i].ygravity = gravity\n\t\t\t\tparticles[i].fadeLength = fadeLength \/ 10\n\t\t\t\tparticles[i].fadeCounter = particles[i].fadeLength\n\t\t\t\tIf lifeCounter>0 Then particles[i].lifeCounter = lifeCounter \/ 10\n\t\t\t\tparticles[i].active = 1\n\t\t\t\tIf maxIndex < 0 Or i > maxIndex Then maxIndex = i\n\t\t\t\tIf minIndex < 0 Or i < minIndex Then minIndex = i\n\t\t\t\tparticleCount += 1\n\t\t\t\tReturn particles[i]\n\t\t\tEnd\n\t\t\ti += 1\n\t\t\tIf i >= MAX_PARTICLES Then i = 0\n\t\tUntil i = lastDeath\n\t\tReturn Null\n\tEnd\n\t\n\tFunction Clear:Void()\n\t\tFor Local i:Int = 0 To MAX_PARTICLES - 1\n\t\t\tparticles[i].alpha = 0\n\t\t\tparticles[i].active = False\n\t\tNext\n\t\tminIndex = -1\n\t\tmaxIndex = -1\n\t\tparticleCount = 0\n\t\tlastDeath = 0\n\tEnd\n\t\n\tFunction DrawAll:Void(offsetx:Float = 0, offsety:Float = 0)\n\t\tIf minIndex < 0 Or maxIndex < 0 Then Return\n\t\tFor Local i% = minIndex To maxIndex\n\t\t\tIf particles[i] <> Null And particles[i].image <> Null\n\t\t\t\tIf particles[i].fadeCounter > 0 And particles[i].active Then\n\t\t\t\t\tIf particles[i].fadeIn Then\n\t\t\t\t\t\tparticles[i].alpha = particles[i].fadeCounter\/particles[i].fadeInLength\n\t\t\t\t\tElse\n\t\t\t\t\t\tparticles[i].alpha = particles[i].fadeCounter\/particles[i].fadeLength\n\t\t\t\t\tEnd\n\t\t\t\tEnd\n\t\t\t\tparticles[i].Draw(offsetx, offsety)\n\t\t\tEnd\n\t\tNext\n\tEnd\n\t\n\tFunction UpdateAll:Void()\n\t\tIf minIndex < 0 Or maxIndex < 0 Then Return\n\t\tLocal newMinIndex:Int = -1\n\t\tLocal newMaxIndex:Int = -1\n\t\tFor Local i:Int = minIndex To maxIndex\n\t\t\tIf particles[i] <> Null And particles[i].image <> Null\n\t\t\t\tIf particles[i].active\n\t\t\t\t\tparticles[i].Update()\n\t\t\t\t\tIf particles[i].active Then\n\t\t\t\t\t\tIf newMinIndex < 0 Then newMinIndex = i\n\t\t\t\t\t\tnewMaxIndex = i\n\t\t\t\t\tElse\n\t\t\t\t\t\tlastDeath = i\n\t\t\t\t\t\tparticleCount -= 1\n\t\t\t\t\tEnd\n\t\t\t\tEnd\n\t\t\tEnd\n\t\tNext\n\t\tminIndex = newMinIndex\n\t\tmaxIndex = newMaxIndex\n\tEnd\t\n\t\n\tMethod Update:Void()\n\t\tSuper.Move()\n\n\t\tIf fadeIn Then\n\t\t\tfadeCounter+=dt.delta\n\n\t\t\tIf fadeCounter >= fadeInLength Then\n\t\t\t\tfadeCounter = fadeLength\n\t\t\t\tfadeIn = 0\n\t\t\t\talpha = 1\n\t\t\tEnd\n\t\tElseif fadeCounter>0 Then\n\t\t\tfadeCounter-=dt.delta\n\t\t\tIf fadeCounter <= 0 Then\n\t\t\t\talpha = 0\n\t\t\t\tactive = 0\n\t\t\tEnd \n\t\tEnd\n\tEnd\nEnd\n\n'summary: Simple Mouse functions class\nClass DiddyMouse\n\tField lastX:Int\n\tField lastY:Int\n\n\tMethod New()\n\t\tMouseZInit()\n\tEnd\n\t\n\t'summary: Returns the MouseX speed\n\tMethod MouseXSpeed:Int()\n\t\tReturn diddyGame.mouseX - lastX\n\tEnd\n\t\n\t'summary: Returns the MouseY speed\n\tMethod MouseYSpeed:Int()\n\t\tReturn diddyGame.mouseY - lastY\n\tEnd\n\t\n\t'summary: Updates the last positions\n\tMethod Update:Void()\n\t\tlastX = diddyGame.mouseX\n\t\tlastY = diddyGame.mouseY\n\tEnd\nEnd\n\n'summary: Wrapper function for MouseXSpeed\nFunction MouseXSpeed:Int()\n\tReturn diddyGame.diddyMouse.MouseXSpeed()\nEnd\n\n'summary: Wrapper function for MouseYSpeed\nFunction MouseYSpeed:Int()\n\tReturn diddyGame.diddyMouse.MouseYSpeed()\nEnd\n","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"4c7f78d104f5e94a030908bee157c038517b92bf","subject":"Forgot to give 'InvalidWrapperStream' a debug-string.","message":"Forgot to give 'InvalidWrapperStream' a debug-string.\n","repos":"Regal-Internet-Brothers\/ioutil,Regal-Internet-Brothers\/ioutil","old_file":"wrapperstream.monkey","new_file":"wrapperstream.monkey","new_contents":"#Rem\n\tTHIS MODULE IS CURRENTLY EXPERIMENTAL; USE AT YOUR OWN RISK.\n#End\n\nStrict\n\nPublic\n\n' Preprocessor related:\n'#REGAL_IOUTIL_WRAPPERSTREAM_SAFE = True\n\n' Imports (Public):\nImport brl.stream\n\n' Imports (Private):\nPrivate\n\nImport brl.databuffer\n\nPublic\n\n' Classes:\nClass WrapperStream Extends Stream\n\t' Constructor(s):\n\tMethod New(S:StreamType, ThrowOnInvalid:Bool=True)\n\t\tIf (ThrowOnInvalid) Then\n\t\t\tIf (S = Null) Then\n\t\t\t\tThrow New InvalidWrapperStream(Self, S)\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tSelf.InternalStream = S\n\tEnd\n\t\n\t' Destructor(s):\n\tMethod Close:Void()\n\t\tInternalStream.Close()\n\t\t\n\t\tReturn\n\tEnd\n\n\t' Methods (Public):\n\tMethod Read:Int(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tReturn InternalStream.Read(Buffer, Offset, Count)\n\tEnd\n\t\n\tMethod Write:Int(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tReturn InternalStream.Write(Buffer, Offset, Count)\n\tEnd\n\t\n\tMethod ReadAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tInternalStream.ReadAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod ReadAll:DataBuffer()\n\t\tReturn InternalStream.ReadAll()\n\tEnd\n\t\n\tMethod WriteAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tInternalStream.WriteAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod ReadString:String(Count:Int, Encoding:String=\"utf8\")\n\t\tReturn InternalStream.ReadString(Count, Encoding)\n\tEnd\n\t\n\tMethod ReadString:String(Encoding:String=\"utf8\")\n\t\tReturn InternalStream.ReadString(Encoding)\n\tEnd\n\t\n\tMethod ReadLine:String()\n\t\tReturn InternalStream.ReadLine()\n\tEnd\n\t\n\tMethod ReadByte:Int()\n\t\tReturn InternalStream.ReadByte()\n\tEnd\n\t\n\tMethod ReadShort:Int()\n\t\tReturn InternalStream.ReadShort()\n\tEnd\n\t\n\tMethod ReadInt:Int()\n\t\tReturn InternalStream.ReadInt()\n\tEnd\n\t\n\tMethod ReadFloat:Float()\n\t\tReturn InternalStream.ReadFloat()\n\tEnd\n\t\n\tMethod WriteByte:Void(Value:Int)\n\t\tInternalStream.WriteByte(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteShort:Void(Value:Int)\n\t\tInternalStream.WriteShort(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteInt:Void(Value:Int)\n\t\tInternalStream.WriteInt(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteFloat:Void(Value:Float)\n\t\tInternalStream.WriteFloat(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteString:Void(Value:String, Encoding:String=\"utf8\")\n\t\tInternalStream.WriteString(Value, Encoding)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteLine:Void(Str:String)\n\t\tInternalStream.WriteLine(Str)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod Seek:Int(Position:Int)\n\t\tReturn InternalStream.Seek(Position)\n\tEnd\n\t\n\tMethod Skip:Void(Count:Int)\n\t\tInternalStream.Skip(Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t' Methods (Protected):\n\tProtected\n\t\n\tMethod InternalReadAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\t' Call the super-class's implementation.\n\t\tSuper.ReadAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod InternalReadAll:DataBuffer()\n\t\t' Call the super-class's implementation.\n\t\tReturn Super.ReadAll()\n\tEnd\n\t\n\tMethod InternalWriteAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\t' Call the super-class's implementation.\n\t\tSuper.WriteAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tPublic\n\t\n\t' Properties:\n\tMethod Eof:Int() Property\n\t\tReturn InternalStream.Eof\n\tEnd\n\t\n\tMethod Length:Int() Property\n\t\tReturn InternalStream.Length\n\tEnd\n\t\n\tMethod Position:Int() Property\n\t\tReturn InternalStream.Position\n\tEnd\n\t\n\tMethod Stream:StreamType() Property\n\t\tReturn Self.InternalStream\n\tEnd\n\t\n\t' Fields (Public):\n\t' Nothing so far.\n\t\n\t' Fields (Protected):\n\tProtected\n\t\n\tField InternalStream:StreamType\n\t\n\tPublic\nEnd\n\n' Exceptions:\nClass InvalidWrapperStream Extends StreamError\n\t' Constructor(s):\n\tMethod New(Instance:Stream, WrappedStream:Stream=Null)\n\t\tSuper.New(Instance)\n\t\t\n\t\tSelf.WrappedStream = WrappedStream\n\tEnd\n\t\n\t' Methods:\n\tMethod ToString:String()\n\t\tReturn \"An invalid stream was given to a 'WrapperStream' object.\"\n\tEnd\n\t\n\t' Fields (Protected):\n\tProtected\n\t\n\tField WrappedStream:Stream\n\t\n\tPublic\nEnd","old_contents":"#Rem\n\tTHIS MODULE IS CURRENTLY EXPERIMENTAL; USE AT YOUR OWN RISK.\n#End\n\nStrict\n\nPublic\n\n' Preprocessor related:\n'#REGAL_IOUTIL_WRAPPERSTREAM_SAFE = True\n\n' Imports (Public):\nImport brl.stream\n\n' Imports (Private):\nPrivate\n\nImport brl.databuffer\n\nPublic\n\n' Classes:\nClass WrapperStream Extends Stream\n\t' Constructor(s):\n\tMethod New(S:StreamType, ThrowOnInvalid:Bool=True)\n\t\tIf (ThrowOnInvalid) Then\n\t\t\tIf (S = Null) Then\n\t\t\t\tThrow New InvalidWrapperStream(Self, S)\n\t\t\tEndif\n\t\tEndif\n\t\t\n\t\tSelf.InternalStream = S\n\tEnd\n\t\n\t' Destructor(s):\n\tMethod Close:Void()\n\t\tInternalStream.Close()\n\t\t\n\t\tReturn\n\tEnd\n\n\t' Methods (Public):\n\tMethod Read:Int(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tReturn InternalStream.Read(Buffer, Offset, Count)\n\tEnd\n\t\n\tMethod Write:Int(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tReturn InternalStream.Write(Buffer, Offset, Count)\n\tEnd\n\t\n\tMethod ReadAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tInternalStream.ReadAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod ReadAll:DataBuffer()\n\t\tReturn InternalStream.ReadAll()\n\tEnd\n\t\n\tMethod WriteAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\tInternalStream.WriteAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod ReadString:String(Count:Int, Encoding:String=\"utf8\")\n\t\tReturn InternalStream.ReadString(Count, Encoding)\n\tEnd\n\t\n\tMethod ReadString:String(Encoding:String=\"utf8\")\n\t\tReturn InternalStream.ReadString(Encoding)\n\tEnd\n\t\n\tMethod ReadLine:String()\n\t\tReturn InternalStream.ReadLine()\n\tEnd\n\t\n\tMethod ReadByte:Int()\n\t\tReturn InternalStream.ReadByte()\n\tEnd\n\t\n\tMethod ReadShort:Int()\n\t\tReturn InternalStream.ReadShort()\n\tEnd\n\t\n\tMethod ReadInt:Int()\n\t\tReturn InternalStream.ReadInt()\n\tEnd\n\t\n\tMethod ReadFloat:Float()\n\t\tReturn InternalStream.ReadFloat()\n\tEnd\n\t\n\tMethod WriteByte:Void(Value:Int)\n\t\tInternalStream.WriteByte(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteShort:Void(Value:Int)\n\t\tInternalStream.WriteShort(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteInt:Void(Value:Int)\n\t\tInternalStream.WriteInt(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteFloat:Void(Value:Float)\n\t\tInternalStream.WriteFloat(Value)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteString:Void(Value:String, Encoding:String=\"utf8\")\n\t\tInternalStream.WriteString(Value, Encoding)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod WriteLine:Void(Str:String)\n\t\tInternalStream.WriteLine(Str)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod Seek:Int(Position:Int)\n\t\tReturn InternalStream.Seek(Position)\n\tEnd\n\t\n\tMethod Skip:Void(Count:Int)\n\t\tInternalStream.Skip(Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\t' Methods (Protected):\n\tProtected\n\t\n\tMethod InternalReadAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\t' Call the super-class's implementation.\n\t\tSuper.ReadAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tMethod InternalReadAll:DataBuffer()\n\t\t' Call the super-class's implementation.\n\t\tReturn Super.ReadAll()\n\tEnd\n\t\n\tMethod InternalWriteAll:Void(Buffer:DataBuffer, Offset:Int, Count:Int)\n\t\t' Call the super-class's implementation.\n\t\tSuper.WriteAll(Buffer, Offset, Count)\n\t\t\n\t\tReturn\n\tEnd\n\t\n\tPublic\n\t\n\t' Properties:\n\tMethod Eof:Int() Property\n\t\tReturn InternalStream.Eof\n\tEnd\n\t\n\tMethod Length:Int() Property\n\t\tReturn InternalStream.Length\n\tEnd\n\t\n\tMethod Position:Int() Property\n\t\tReturn InternalStream.Position\n\tEnd\n\t\n\tMethod Stream:StreamType() Property\n\t\tReturn Self.InternalStream\n\tEnd\n\t\n\t' Fields (Public):\n\t' Nothing so far.\n\t\n\t' Fields (Protected):\n\tProtected\n\t\n\tField InternalStream:StreamType\n\t\n\tPublic\nEnd\n\n' Exceptions:\nClass InvalidWrapperStream Extends StreamError\n\t' Constructor(s):\n\tMethod New(Instance:Stream, WrappedStream:Stream=Null)\n\t\tSuper.New(Instance)\n\t\t\n\t\tSelf.WrappedStream = WrappedStream\n\tEnd\n\t\n\t' Fields (Protected):\n\tProtected\n\t\n\tField WrappedStream:Stream\n\t\n\tPublic\nEnd","returncode":0,"stderr":"","license":"mit","lang":"Monkey"} {"commit":"106b082e6d437880102fe1d44947a6f5c263d2b2","subject":"Changed to use game.mouseX\/Y rather than raw Mojo calls.","message":"Changed to use game.mouseX\/Y rather than raw Mojo calls.\n","repos":"swoolcock\/diddy,swoolcock\/diddy,swoolcock\/diddy,swoolcock\/diddy,swoolcock\/diddy","old_file":"src\/diddy\/gui.monkey","new_file":"src\/diddy\/gui.monkey","new_contents":"Import mojo\r\nImport diddy\r\n\r\nConst ACTION_CLICKED$ = \"clicked\"\r\nConst ACTION_VALUE_CHANGED$ = \"changed\"\r\n\r\nClass Rectangle\r\n\tField x#, y#, w#, h#\r\n\tField empty? = False\r\n\t\r\n\tMethod New(x#, y#, w#, h#)\r\n\t\tSet(x, y, w, h)\r\n\tEnd\r\n\t\r\n\tMethod Set:Void(x#, y#, w#, h#)\r\n\t\tSelf.x = x\r\n\t\tSelf.y = y\r\n\t\tSelf.w = w\r\n\t\tSelf.h = h\r\n\t\tSelf.empty = Self.w <= 0 Or Self.h <= 0\r\n\tEnd\r\n\t\r\n\tMethod Set:Void(srcRect:Rectangle)\r\n\t\tSelf.x = srcRect.x\r\n\t\tSelf.y = srcRect.y\r\n\t\tSelf.w = srcRect.w\r\n\t\tSelf.h = srcRect.h\r\n\t\tSelf.empty = Self.w <= 0 Or Self.h <= 0\r\n\tEnd\r\n\t\r\n\tMethod Clear:Void()\r\n\t\tSelf.w = -1\r\n\t\tSelf.h = -1\r\n\t\tSelf.empty = True\r\n\tEnd\r\n\t\r\n\tMethod Intersect:Void(x#, y#, w#, h#)\r\n\t\tIf x >= Self.x + Self.w Or y >= Self.y + Self.h Or Self.x >= x + w Or Self.y >= y + h Then\r\n\t\t\tClear()\r\n\t\t\tReturn\r\n\t\tEnd\r\n\t\t\r\n\t\tLocal r% = Self.x + Self.w\r\n\t\tLocal b% = Self.y + Self.h\r\n\t\tIf Self.x < x Then Self.x = x\r\n\t\tIf Self.y < y Then Self.y = y\r\n\t\tIf r > x + w Then r = x + w\r\n\t\tIf b > y + h Then b = y + h\r\n\t\tSelf.w = r - Self.x\r\n\t\tSelf.h = b - Self.y\r\n\tEnd\r\nEnd\r\n\r\nClass GUI\r\n\tField desktop:Desktop\r\n\tField scissors:Rectangle[] = New Rectangle[128]\r\n\tField scissorDepth:Int = 0\r\n\t\r\n\tField mouseDown:Bool[3]\r\n\tField mouseDownX:Float[3]\r\n\tField mouseDownY:Float[3]\r\n\tField mouseDownComponent:Component[3]\r\n\t\r\n\tField mouseLastX:Float\r\n\tField mouseLastY:Float\r\n\tField mouseLastComponent:Component\r\n\tField mouseThisX:Float\r\n\tField mouseThisY:Float\r\n\tField mouseThisComponent:Component\r\n\t\r\n\tMethod New()\r\n\t\tdesktop = New Desktop(Self)\r\n\t\tdesktop.SetBounds(0, 0, DeviceWidth(), DeviceHeight())\r\n\t\tFor Local i% = 0 Until scissors.Length\r\n\t\t\tscissors[i] = New Rectangle\r\n\t\tNext\r\n\tEnd\r\n\t\r\n\tMethod PushScissor:Void(x#, y#, w#, h#)\r\n\t\t' don't use assert, for speed on android (one less method call)\r\n\t\tIf scissorDepth >= scissors.Length Then Error(\"GUI.PushScissor: Out of space for scissors.\")\r\n\t\tIf scissorDepth = 0 Then\r\n\t\t\tscissors[0].Set(x, y, w, h)\r\n\t\tElse\r\n\t\t\tscissors[scissorDepth].Set(scissors[scissorDepth-1])\r\n\t\t\tscissors[scissorDepth].Intersect(x, y, w, h)\r\n\t\tEnd\r\n\t\tscissorDepth += 1\r\n\t\tUpdateScissor()\r\n\tEnd\r\n\t\r\n\tMethod PopScissor:Void()\r\n\t\tIf scissorDepth > 0 Then\r\n\t\t\tscissorDepth -= 1\r\n\t\t\tscissors[scissorDepth].Clear()\r\n\t\tEnd\r\n\t\tUpdateScissor()\r\n\tEnd\r\n\t\r\n\tMethod UpdateScissor:Void()\r\n\t\tIf scissorDepth > 0 Then\r\n\t\t\tIf Not EmptyScissor() Then\r\n\t\t\t\tSetScissor(scissors[scissorDepth-1].x, scissors[scissorDepth-1].y, scissors[scissorDepth-1].w, scissors[scissorDepth-1].h)\r\n\t\t\tEnd\r\n\t\tElse\r\n\t\t\tSetScissor(0, 0, DeviceWidth(), DeviceHeight())\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod EmptyScissor:Bool()\r\n\t\tIf scissorDepth <= 0 Then Return False\r\n\t\tReturn scissors[scissorDepth-1].empty\r\n\tEnd\r\n\t\r\n\tMethod Draw()\r\n\t\tdesktop.Draw(Self)\r\n\t\tscissorDepth = 0\r\n\t\tSetScissor(0, 0, DeviceWidth(), DeviceHeight())\r\n\tEnd\r\n\t\r\n\tMethod ComponentAtPoint:Component(x#, y#, parent:Component=Null)\r\n\t\t' if no parent, it's the desktop\r\n\t\tIf parent = Null Then parent = desktop\r\n\t\t' if the mouse is outside the component, return null\r\n\t\tIf x<0 Or y<0 Or x >= parent.w Or y >= parent.h Then Return Null\r\n\t\t' check if it's inside a child\r\n\t\tLocal rv:Component = Null\r\n\t\tFor Local i% = 0 Until parent.children.Size\r\n\t\t\tLocal c:Component = parent.children.Get(i)\r\n\t\t\trv = ComponentAtPoint(x-c.x, y-c.y, c)\r\n\t\t\tIf rv <> Null Then Return rv\r\n\t\tNext\r\n\t\t' not inside a child, so it's this one\r\n\t\tReturn parent\r\n\tEnd\r\n\t\r\n\tMethod GetAbsoluteX:Float(comp:Component)\r\n\t\tLocal rv# = comp.x\r\n\t\tWhile comp.parent <> Null\r\n\t\t\tcomp = comp.parent\r\n\t\t\trv += comp.x\r\n\t\tWend\r\n\t\tReturn rv\r\n\tEnd\r\n\t\r\n\tMethod GetAbsoluteY:Float(comp:Component)\r\n\t\tLocal rv# = comp.y\r\n\t\tWhile comp.parent <> Null\r\n\t\t\tcomp = comp.parent\r\n\t\t\trv += comp.y\r\n\t\tWend\r\n\t\tReturn rv\r\n\tEnd\r\n\t\r\n\tMethod Update:Void()\r\n\t\tmouseLastX = mouseThisX\r\n\t\tmouseLastY = mouseThisY\r\n\t\tmouseLastComponent = mouseThisComponent\r\n\t\tmouseThisX = game.mouseX\r\n\t\tmouseThisY = game.mouseY\r\n\t\tmouseThisComponent = ComponentAtPoint(mouseThisX, mouseThisY)\r\n\t\tDoMouse(MOUSE_LEFT)\r\n\t\tDoMouse(MOUSE_MIDDLE)\r\n\t\tDoMouse(MOUSE_RIGHT)\r\n\tEnd\r\n\t\r\n\tMethod DoMouse:Void(button%)\r\n\t\tLocal absX#, absY#\r\n\t\tIf MouseHit(button) Then\r\n\t\t\tmouseDown[button] = True\r\n\t\t\tmouseDownX[button] = mouseThisX\r\n\t\t\tmouseDownY[button] = mouseThisY\r\n\t\t\tmouseDownComponent[button] = mouseThisComponent\r\n\t\t\t\r\n\t\t\t' fire pressed on mouseThisComponent\r\n\t\t\tIf mouseThisComponent.mouseAdapter <> Null Then\r\n\t\t\t\tabsX = GetAbsoluteX(mouseThisComponent)\r\n\t\t\t\tabsY = GetAbsoluteY(mouseThisComponent)\r\n\t\t\t\tmouseThisComponent.mouseAdapter.MousePressed(mouseThisX-absX, mouseThisY-absY, button)\r\n\t\t\tEnd\r\n\t\t\t\r\n\t\t\t' set mouseDown\r\n\t\t\tmouseThisComponent.mouseDown = True\r\n\t\t\t\r\n\t\tElseIf mouseDown[button] Then\r\n\t\t\t' if we released the button\r\n\t\t\tIf Not MouseDown(button) Then\r\n\t\t\t\tmouseDown[button] = False\r\n\t\t\t\tLocal comp:Component = mouseDownComponent[button]\r\n\t\t\t\tmouseDownComponent[button] = Null \r\n\t\t\t\t\r\n\t\t\t\t' fire mouse released on comp\r\n\t\t\t\tIf comp.mouseAdapter <> Null Then\r\n\t\t\t\t\tabsX = GetAbsoluteX(comp)\r\n\t\t\t\t\tabsY = GetAbsoluteY(comp)\r\n\t\t\t\t\tcomp.mouseAdapter.MouseReleased(mouseThisX-absX, mouseThisY-absY, button)\r\n\t\t\t\tEnd\r\n\t\t\t\t\r\n\t\t\t\t' clear mouseDown\r\n\t\t\t\tcomp.mouseDown = False\r\n\t\t\t\t\r\n\t\t\t\t' if we released on the same component, fire mouse clicked\r\n\t\t\t\tIf mouseThisComponent = comp Then\r\n\t\t\t\t\tIf comp.mouseAdapter <> Null Then comp.mouseAdapter.MouseClicked(mouseThisX-absX, mouseThisY-absY, button)\r\n\t\t\t\tEnd\r\n\t\t\t\t\r\n\t\t\tElseIf mouseLastX <> mouseThisX Or mouseLastY <> mouseThisY Then\r\n\t\t\t\t' fire mouse dragged on mouseDownComponent\r\n\t\t\t\tIf mouseDownComponent[button].mouseMotionAdapter <> Null Then\r\n\t\t\t\t\tabsX = GetAbsoluteX(mouseDownComponent[button])\r\n\t\t\t\t\tabsY = GetAbsoluteY(mouseDownComponent[button])\r\n\t\t\t\t\tmouseDownComponent[button].mouseMotionAdapter.MouseDragged(mouseThisX-absX, mouseThisY-absY, button)\r\n\t\t\t\tEnd\r\n\t\t\t\t\r\n\t\t\t\t' if the component changed, fire exit\/enter\r\n\t\t\t\tIf mouseThisComponent <> mouseLastComponent Then\r\n\t\t\t\t\t' fire mouse exited on mouseLastComponent\r\n\t\t\t\t\tIf mouseLastComponent.mouseAdapter <> Null Then\r\n\t\t\t\t\t\tabsX = GetAbsoluteX(mouseLastComponent)\r\n\t\t\t\t\t\tabsY = GetAbsoluteY(mouseLastComponent)\r\n\t\t\t\t\t\tmouseLastComponent.mouseAdapter.MouseExited(mouseThisX-absX, mouseThisY-absY, mouseThisComponent)\r\n\t\t\t\t\tEnd\r\n\t\t\t\t\t\r\n\t\t\t\t\t' clear mouseHover\r\n\t\t\t\t\tmouseLastComponent.mouseHover = False\r\n\t\t\t\t\t\r\n\t\t\t\t\t' fire mouse entered on mouseThisComponent\r\n\t\t\t\t\tIf mouseThisComponent.mouseAdapter <> Null Then\r\n\t\t\t\t\t\tabsX = GetAbsoluteX(mouseThisComponent)\r\n\t\t\t\t\t\tabsY = GetAbsoluteY(mouseThisComponent)\r\n\t\t\t\t\t\tmouseThisComponent.mouseAdapter.MouseEntered(mouseThisX-absX, mouseThisY-absY, mouseLastComponent)\r\n\t\t\t\t\tEnd\r\n\t\t\t\t\t\r\n\t\t\t\t\t' set the STATE_HOVER bit\r\n\t\t\t\t\tmouseThisComponent.mouseHover = True\r\n\t\t\t\tEnd\r\n\t\t\tEnd\r\n\t\tElse\r\n\t\t\tIf mouseLastX <> mouseThisX Or mouseLastY <> mouseThisY Then\r\n\t\t\t\t' fire mouse moved on mouseThisComponent\r\n\t\t\t\tIf mouseThisComponent <> Null And mouseThisComponent.mouseMotionAdapter <> Null Then\r\n\t\t\t\t\tabsX = GetAbsoluteX(mouseThisComponent)\r\n\t\t\t\t\tabsY = GetAbsoluteY(mouseThisComponent)\r\n\t\t\t\t\tmouseThisComponent.mouseMotionAdapter.MouseMoved(mouseThisX-absX, mouseThisY-absY)\r\n\t\t\t\tEnd\r\n\t\t\t\t\r\n\t\t\t\t' if the component changed, fire exit\/enter\r\n\t\t\t\tIf mouseThisComponent <> mouseLastComponent Then\r\n\t\t\t\t\t' fire mouse exited on mouseLastComponent\r\n\t\t\t\t\tIf mouseLastComponent <> Null Then\r\n\t\t\t\t\t\tIf mouseLastComponent.mouseAdapter <> Null Then\r\n\t\t\t\t\t\t\tabsX = GetAbsoluteX(mouseLastComponent)\r\n\t\t\t\t\t\t\tabsY = GetAbsoluteY(mouseLastComponent)\r\n\t\t\t\t\t\t\tmouseLastComponent.mouseAdapter.MouseExited(mouseThisX-absX, mouseThisY-absY, mouseThisComponent)\r\n\t\t\t\t\t\tEnd\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t' clear mouseHover\r\n\t\t\t\t\t\tmouseLastComponent.mouseHover = False\r\n\t\t\t\t\tEnd\r\n\t\t\t\t\t\r\n\t\t\t\t\t' fire mouse entered on mouseThisComponent\r\n\t\t\t\t\tIf mouseThisComponent <> Null Then\r\n\t\t\t\t\t\tIf mouseThisComponent.mouseAdapter <> Null Then\r\n\t\t\t\t\t\t\tabsX = GetAbsoluteX(mouseThisComponent)\r\n\t\t\t\t\t\t\tabsY = GetAbsoluteY(mouseThisComponent)\r\n\t\t\t\t\t\t\tmouseThisComponent.mouseAdapter.MouseEntered(mouseThisX-absX, mouseThisY-absY, mouseLastComponent)\r\n\t\t\t\t\t\tEnd\r\n\t\t\t\t\t\t' set mouseHover\r\n\t\t\t\t\t\tmouseThisComponent.mouseHover = True\r\n\t\t\t\t\tEnd\r\n\t\t\t\tEnd\r\n\t\t\tEnd\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod ActionPerformed:Void(source:Component, action:String)\r\n\tEnd\r\nEnd\r\n\r\nClass AbstractMouseAdapter Abstract\r\n\tMethod MousePressed:Void(x#, y#, button%)\r\n\tEnd\r\n\tMethod MouseReleased:Void(x#, y#, button%)\r\n\tEnd\r\n\tMethod MouseClicked:Void(x#, y#, button%)\r\n\tEnd\r\n\tMethod MouseEntered:Void(x#, y#, exitedComp:Component)\r\n\tEnd\r\n\tMethod MouseExited:Void(x#, y#, enteredComp:Component)\r\n\tEnd\r\nEnd\r\n\r\nClass AbstractMouseMotionAdapter Abstract\r\n\tMethod MouseMoved:Void(x#, y#)\r\n\tEnd\r\n\tMethod MouseDragged:Void(x#, y#, button%)\r\n\tEnd\r\nEnd\r\n\r\nClass Desktop Extends Component\r\n\tField restrictWindows:Bool = True\r\n\tField parentGUI:GUI\r\n\tMethod New(parentGUI:GUI)\r\n\t\tSuper.New(Null)\r\n\t\tSelf.parentGUI = parentGUI\r\n\tEnd\r\n\t\r\n\tMethod ActionPerformed:Void(source:Component, action:String)\r\n\t\tparentGUI.ActionPerformed(source, action)\r\n\tEnd\r\nEnd\r\n\r\nClass Component\r\nPrivate\r\n\tField alpha# = 1\r\n\tField children:ArrayList = New ArrayList\r\n\tField mouseAdapter:AbstractMouseAdapter\r\n\tField mouseMotionAdapter:AbstractMouseMotionAdapter\r\n\tField forwardAction:Component = Null\r\n\tField mouseHover:Bool = False\r\n\tField mouseDown:Bool = False\r\n\t\r\n\tField styleNormal:ComponentStyle = Null\r\n\t\r\nPublic\r\n\tField parent:Component\r\n\t\r\n\tField x#, y#\r\n\tField w#, h#\r\n\tField visible:Bool = True\r\n\t\r\n\tMethod MouseAdapter:Void(mouseAdapter:AbstractMouseAdapter) Property\r\n\t\tSelf.mouseAdapter = mouseAdapter\r\n\tEnd\r\n\tMethod MouseAdapter:AbstractMouseAdapter() Property\r\n\t\tReturn Self.mouseAdapter\r\n\tEnd\r\n\tMethod MouseMotionAdapter:Void(mouseMotionAdapter:AbstractMouseMotionAdapter) Property\r\n\t\tSelf.mouseMotionAdapter = mouseMotionAdapter\r\n\tEnd\r\n\tMethod MouseMotionAdapter:AbstractMouseMotionAdapter() Property\r\n\t\tReturn Self.mouseMotionAdapter\r\n\tEnd\r\n\t\r\n\tMethod StyleNormal:ComponentStyle() Property\r\n\t\tIf styleNormal = Null Then styleNormal = New ComponentStyle\r\n\t\tReturn styleNormal\r\n\tEnd\r\n\tMethod StyleNormal:Void(style:ComponentStyle) Property\r\n\t\tAssertNotNull(style, \"StyleNormal may not be null.\")\r\n\t\tstyleNormal = style\r\n\tEnd\r\n\t\r\n\tMethod New(parent:Component)\r\n\t\tstyleNormal = New ComponentStyle\r\n\t\t' if this isn't the desktop, it must have a parent\r\n\t\tIf Not Desktop(Self) Then\r\n\t\t\tAssertNotNull(parent, \"Components must have a parent.\")\r\n\t\t\tSelf.parent = parent\r\n\t\t\tparent.children.Add(Self)\r\n\t\tElse\r\n\t\t\tstyleNormal.drawBackground = False\r\n\t\tEnd\r\n\t\tAddNotify()\r\n\tEnd\r\n\t\r\n\tMethod Alpha#() Property\r\n\t\tReturn alpha\r\n\tEnd\r\n\t\r\n\tMethod Alpha:Void(alpha#) Property\r\n\t\tSelf.alpha = alpha\r\n\t\tIf Self.alpha < 0 Then Self.alpha = 0\r\n\t\tIf Self.alpha > 1 Then Self.alpha = 1\r\n\tEnd\r\n\t\r\n\tMethod SetBackground:Void(red#, green#, blue#)\r\n\t\tIf red < 0 Then red = 0\r\n\t\tIf red > 255 Then red = 255\r\n\t\tIf green < 0 Then green = 0\r\n\t\tIf green > 255 Then green = 255\r\n\t\tIf blue < 0 Then blue = 0\r\n\t\tIf blue > 255 Then blue = 255\r\n\t\tstyleNormal.red = red\r\n\t\tstyleNormal.green = green\r\n\t\tstyleNormal.blue = blue\r\n\t\tstyleNormal.drawBackground = True\r\n\tEnd\r\n\t\r\n\tMethod SetBackground:Void(drawBackground:Bool)\r\n\t\tstyleNormal.drawBackground = drawBackground\r\n\tEnd\r\n\t\r\n\tMethod SetLocation:Void(x#, y#)\r\n\t\tSelf.x = x\r\n\t\tSelf.y = y\r\n\t\tLayout()\r\n\tEnd\r\n\t\r\n\tMethod SetSize:Void(w#, h#)\r\n\t\tSelf.w = w\r\n\t\tSelf.h = h\r\n\t\tLayout()\r\n\tEnd\r\n\t\r\n\tMethod SetBounds:Void(x#, y#, w#, h#)\r\n\t\tSelf.x = x\r\n\t\tSelf.y = y\r\n\t\tSelf.w = w\r\n\t\tSelf.h = h\r\n\t\tLayout()\r\n\tEnd\r\n\t\r\n\tMethod Draw:Void(parentGui:GUI, alpha# = 1, absx# = 0, absy# = 0)\r\n\t\tIf visible Then\r\n\t\t\tparentGui.PushScissor(absx, absy, w, h)\r\n\t\t\tIf Not parentGui.EmptyScissor() Then\r\n\t\t\t\tSetAlpha(alpha)\r\n\t\t\t\tDrawComponent()\r\n\t\t\t\tDrawChildren(parentGui, alpha, absx, absy)\r\n\t\t\tEnd\r\n\t\t\tparentGui.PopScissor()\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod DrawChildren:Void(parentGui:GUI, alpha# = 1, absx#, absy#)\r\n\t\tFor Local c:Component = EachIn children\r\n\t\t\tPushMatrix()\r\n\t\t\tTranslate(c.x, c.y)\r\n\t\t\tc.Draw(parentGui, c.alpha * alpha, absx + c.x, absy + c.y)\r\n\t\t\tPopMatrix()\r\n\t\tNext\r\n\tEnd\r\n\t\r\n\tMethod DrawComponent:Void()\r\n\t\tLocal style:ComponentStyle = GetCurrentStyle()\r\n\t\tIf style <> Null Then\r\n\t\t\t' background colour first\r\n\t\t\tIf style.drawBackground Then\r\n\t\t\t\tSetColor(style.red, style.green, style.blue)\r\n\t\t\t\tSetAlpha(alpha)\r\n\t\t\t\tDrawRect(0, 0, w, h)\r\n\t\t\tEnd\r\n\t\t\t\r\n\t\t\t' image next, priority = down, hover, normal\r\n\t\t\tIf mouseDown And style.downImage <> Null Then\r\n\t\t\t\tSetColor(255,255,255)\r\n\t\t\t\tSetAlpha(alpha)\r\n\t\t\t\tIf style.downImageMode = ComponentStyle.IMAGE_GRID Then\r\n\t\t\t\t\tstyle.downImage.DrawGrid(0, 0, w, h, style.downImageFrame)\r\n\t\t\t\tElseIf style.downImageMode = ComponentStyle.IMAGE_NORMAL Then\r\n\t\t\t\t\tstyle.downImage.Draw(0, 0, 0, 1, 1, style.downImageFrame)\r\n\t\t\t\tEnd\r\n\t\t\tElseIf mouseHover And style.hoverImage <> Null Then\r\n\t\t\t\tSetColor(255,255,255)\r\n\t\t\t\tSetAlpha(alpha)\r\n\t\t\t\tIf style.hoverImageMode = ComponentStyle.IMAGE_GRID Then\r\n\t\t\t\t\tstyle.hoverImage.DrawGrid(0, 0, w, h, style.hoverImageFrame)\r\n\t\t\t\tElseIf style.hoverImageMode = ComponentStyle.IMAGE_NORMAL Then\r\n\t\t\t\t\tstyle.hoverImage.Draw(0, 0, 0, 1, 1, style.hoverImageFrame)\r\n\t\t\t\tEnd\r\n\t\t\tElseIf style.image <> Null Then\r\n\t\t\t\tSetColor(255,255,255)\r\n\t\t\t\tSetAlpha(alpha)\r\n\t\t\t\tIf style.imageMode = ComponentStyle.IMAGE_GRID Then\r\n\t\t\t\t\tstyle.image.DrawGrid(0, 0, w, h, style.imageFrame)\r\n\t\t\t\tElseIf style.imageMode = ComponentStyle.IMAGE_NORMAL Then\r\n\t\t\t\t\tstyle.image.Draw(0, 0, 0, 1, 1, style.imageFrame)\r\n\t\t\t\tEnd\r\n\t\t\tEnd\r\n\t\t\t\r\n\t\t\t' reset stuff\r\n\t\t\tSetColor(255,255,255)\r\n\t\t\tSetAlpha(1)\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod GetCurrentStyle:ComponentStyle()\r\n\t\tReturn styleNormal\r\n\tEnd\r\n\t\r\n\tMethod Dispose:Void(recursing:Bool = False)\r\n\t\t' we do an empty check first to save creating an enumerator object\r\n\t\tIf Not children.IsEmpty() Then\r\n\t\t\tLocal enum:AbstractEnumerator = children.Enumerator()\r\n\t\t\tWhile enum.HasNext()\r\n\t\t\t\tLocal c:Component = enum.NextObject()\r\n\t\t\t\tc.Dispose(True)\r\n\t\t\t\tenum.Remove()\r\n\t\t\tEnd\r\n\t\tEnd\r\n\t\tDisposeNotify()\r\n\t\tLocal p:Component = Self.parent\r\n\t\tSelf.parent = Null\r\n\t\tIf Not recursing Then p.children.Remove(Self)\r\n\tEnd\r\n\t\r\n\tMethod AddNotify:Void()\r\n\tEnd\r\n\t\r\n\tMethod DisposeNotify:Void()\r\n\tEnd\r\n\t\r\n\tMethod Layout:Void()\r\n\tEnd\r\n\t\r\n\tMethod ActionPerformed:Void(source:Component, action:String)\r\n\t\tIf forwardAction <> Null Then\r\n\t\t\tforwardAction.ActionPerformed(source, action)\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod FindActionTarget:Component()\r\n\t\t' if this is a window or desktop, return itself\r\n\t\tIf Window(Self) <> Null Or Desktop(Self) <> Null Then Return Self\r\n\t\t' traverse up the hierarchy and find the closest Window or Desktop to receive the actions\r\n\t\tLocal comp:Component = Self\r\n\t\tWhile Window(Self) = Null And Desktop(Self) = Null And comp.parent <> Null\r\n\t\t\tcomp = comp.parent\r\n\t\tEnd\r\n\t\tReturn comp\r\n\tEnd\r\nEnd\r\n\r\nClass ComponentStyle\r\n\tGlobal IMAGE_NORMAL% = 0\r\n\tGlobal IMAGE_TILE% = 1\r\n\tGlobal IMAGE_STRETCH% = 2\r\n\tGlobal IMAGE_GRID% = 3\r\n\t\r\n\tField drawBackground:Bool = True\r\n\tField red:Int = 255\r\n\tField green:Int = 255\r\n\tField blue:Int = 255\r\n\tField image:GameImage = Null\r\n\tField imageFrame:Int = 0\r\n\tField imageMode:Int = IMAGE_NORMAL\r\n\tField imageAlignX:Float = 0\r\n\tField imageAlignY:Float = 0\r\n\tField hoverImage:GameImage = Null\r\n\tField hoverImageFrame:Int = 0\r\n\tField hoverImageMode:Int = IMAGE_NORMAL\r\n\tField hoverImageAlignX:Float = 0\r\n\tField hoverImageAlignY:Float = 0\r\n\tField downImage:GameImage = Null\r\n\tField downImageFrame:Int = 0\r\n\tField downImageMode:Int = IMAGE_NORMAL\r\n\tField downImageAlignX:Float = 0\r\n\tField downImageAlignY:Float = 0\r\nEnd\r\n\r\nClass Panel Extends Component\r\n\tMethod New(parent:Component)\r\n\t\tSuper.New(parent)\r\n\tEnd\r\nEnd\r\n\r\nClass Window Extends Component\r\nPrivate\r\n\tField contentPane:Panel\r\n\tField titlePane:Panel\r\n\tField buttonPane:Panel\r\n\t\r\n\tField closeButton:WindowButtonPanelButton\r\n\t\r\n\tField titleHeight:Int = 22\r\n\tField buttonWidth:Int = 15\r\n\t\r\n\t' note: a window can be all three of these states at once!\r\n\t' priority is: minimised, maximised, shaded\r\n\tField maximised:Bool = False\r\n\tField minimised:Bool = False\r\n\tField shaded:Bool = False\r\n\tField dragX#, dragY#, originalX#, originalY#\r\n\tField dragging:Bool = False\r\n\t\r\n\tField normalX#, normalY#, normalWidth#, normalHeight#\r\n\r\n\tMethod CreateButtonPane:Void()\r\n\t\tbuttonPane = New Panel(Self)\r\n\t\tbuttonPane.w = buttonWidth*3\r\n\t\tbuttonPane.StyleNormal.drawBackground = False\r\n\t\t'closeButton = New WindowButtonPanelButton(buttonPane, WindowButtonPanelButton.CLOSE_BUTTON)\r\n\t\t'closeButton.StyleNormal.red = 255\r\n\t\t'closeButton.StyleNormal.green = 255\r\n\t\t'closeButton.StyleNormal.blue = 255\r\n\t\t'closeButton.SetBounds(0, 0, buttonWidth, buttonWidth)\r\n\tEnd\r\n\t\r\n\tMethod CreateContentPane:Void()\r\n\t\tcontentPane = New Panel(Self)\r\n\t\tcontentPane.StyleNormal.drawBackground = False\r\n\tEnd\r\n\t\r\n\tMethod CreateTitlePane:Void()\r\n\t\ttitlePane = New Panel(Self)\r\n\t\ttitlePane.StyleNormal.drawBackground = False\r\n\t\ttitlePane.mouseAdapter = New WindowTitlePaneMouseAdapter(Self)\r\n\t\ttitlePane.mouseMotionAdapter = New WindowTitlePaneMouseMotionAdapter(Self)\r\n\tEnd\r\nPublic\r\n\tMethod ContentPane:Panel() Property\r\n\t\tReturn contentPane\r\n\tEnd\r\n\t\r\n\tMethod ContentPane:Void(contentPane:Panel) Property\r\n\t\tIf self.contentPane <> Null Then self.contentPane.Dispose()\r\n\t\tSelf.contentPane = contentPane\r\n\tEnd\r\n\t\r\n\tMethod TitlePane:Panel() Property\r\n\t\tReturn titlePane\r\n\tEnd\r\n\t\r\n\tMethod ButtonPane:Panel() Property\r\n\t\tReturn buttonPane\r\n\tEnd\r\n\t\r\n\tMethod Maximised:Void(maximised:Bool) Property\r\n\t\tStoreWindowSize()\r\n\t\tSelf.maximised = maximised\r\n\t\tUpdateWindowSize()\r\n\tEnd\r\n\t\r\n\tMethod Maximised:Bool() Property\r\n\t\tReturn maximised\r\n\tEnd\r\n\t\r\n\tMethod Minimised:Void(minimised:Bool) Property\r\n\t\tStoreWindowSize()\r\n\t\tSelf.minimised = minimised\r\n\t\tUpdateWindowSize()\r\n\tEnd\r\n\t\r\n\tMethod Minimised:Bool() Property\r\n\t\tReturn minimised\r\n\tEnd\r\n\t\r\n\tMethod Shaded:Void(shaded:Bool) Property\r\n\t\tStoreWindowSize()\r\n\t\tSelf.shaded = shaded\r\n\t\tUpdateWindowSize()\r\n\tEnd\r\n\t\r\n\tMethod Shaded:Bool() Property\r\n\t\tReturn shaded\r\n\tEnd\r\n\t\r\n\tMethod StoreWindowSize:Void()\r\n\t\tIf maximised Or minimised Then Return\r\n\t\tnormalX = x\r\n\t\tnormalY = y\r\n\t\tIf Not shaded Then\r\n\t\t\tnormalWidth = w\r\n\t\t\tnormalHeight = h\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod UpdateWindowSize:Void()\r\n\t\tIf Not maximised And Not minimised And Not shaded Then\r\n\t\t\tSetBounds(normalX, normalY, normalWidth, normalHeight)\r\n\t\tElseIf minimised Then\r\n\t\t\tSetBounds(0, 0, 50, titleHeight)\r\n\t\tElseIf maximised Then\r\n\t\t\tSetBounds(0, 0, parent.w, parent.h)\r\n\t\tElseIf shaded Then\r\n\t\t\tSetBounds(normalX, normalY, normalWidth, titleHeight)\r\n\t\tEnd\r\n\tEnd\r\n\t\r\n\tMethod New(parent:Component)\r\n\t\tSuper.New(parent)\r\n\t\tCreateButtonPane()\r\n\t\tCreateContentPane()\r\n\t\tCreateTitlePane()\r\n\tEnd\r\n\t\r\n\tMethod Layout:Void()\r\n\t\tIf minimised Or shaded Then\r\n\t\t\tIf contentPane <> Null Then contentPane.visible = False\r\n\t\tElse\r\n\t\t\tIf contentPane <> Null Then\r\n\t\t\t\tcontentPane.visible = True\r\n\t\t\t\tcontentPane.SetBounds(4, titleHeight, w-8, h-titleHeight-4)\r\n\t\t\tEnd\r\n\t\tEnd\r\n\t\tbuttonPane.SetBounds(w-buttonPane.w-4, 0, buttonPane.w, titleHeight)\r\n\t\ttitlePane.SetBounds(4, 0, buttonPane.x-4, titleHeight)\r\n\tEnd\r\n\t\r\n\t\r\nEnd\r\n\r\nClass WindowTitlePaneMouseAdapter Extends AbstractMouseAdapter\r\n\tField window:Window\r\n\tMethod New(window:Window)\r\n\t\tSelf.window = window\r\n\tEnd\r\n\tMethod MousePressed:Void(x#, y#, button%)\r\n\t\tIf window.dragging Then Return\r\n\t\tIf window.maximised Or window.minimised Then Return\r\n\t\twindow.dragging = True\r\n\t\twindow.dragX = x\r\n\t\twindow.dragY = y\r\n\t\twindow.originalX = window.x\r\n\t\twindow.originalY = window.y\r\n\tEnd\r\n\tMethod MouseReleased:Void(x#, y#, button%)\r\n\t\twindow.dragging = False\r\n\tEnd\r\nEnd\r\n\t\r\nClass WindowTitlePaneMouseMotionAdapter Extends AbstractMouseMotionAdapter\r\n\tField window:Window\r\n\tMethod New(window:Window)\r\n\t\tSelf.window = window\r\n\tEnd\r\n\tMethod MouseDragged:Void(x#, y#, button%)\r\n\t\tIf window.maximised Or window.minimised Then window.dragging = False\r\n\t\tIf Not window.dragging Then Return\r\n\t\tLocal dx# = x-window.dragX, dy# = y-window.dragY\r\n\t\tLocal newX# = window.originalX + dx, newY# = window.originalY + dy\r\n\t\t\r\n\t\tIf Desktop(window.parent) <> Null And Desktop(window.parent).restrictWindows Then\r\n\t\t\tIf newX + window.w > window.parent.w Then newX = window.parent.w - window.w\r\n\t\t\tIf newY + window.h > window.parent.h Then newY = window.parent.h - window.h\r\n\t\t\tIf newX < 0 Then newX = 0\r\n\t\t\tIf newY < 0 Then newY = 0\r\n\t\tEnd\r\n\t\twindow.SetLocation(newX, newY)\r\n\tEnd\r\nEnd\r\n\r\nClass WindowButtonPanelButton Extends Button\r\n\tConst CLOSE_BUTTON% = 0\r\n\tConst MAXIMISE_BUTTON% = 1\r\n\tConst MINIMISE_BUTTON% = 2\r\n\tConst SHADE_BUTTON% = 3\r\n\tField buttonType%\r\n\t\r\n\tMethod New(parent:Component, buttonType%)\r\n\t\tSuper.New(parent)\r\n\t\tSelf.buttonType = buttonType\r\n\tEnd\r\n\t\r\n\tMethod ButtonClicked:Void()\r\n\t\tLocal window:Window = Window(parent)\r\n\t\tAssertNotNull(window, \"WindowButtonPanelButton.ButtonClicked: window was null\")\r\n\t\tSelect buttonType\r\n\t\t\tCase CLOSE_BUTTON\r\n\t\t\t\twindow.Dispose()\r\n\t\tEnd\r\n\tEnd\r\nEnd\r\n\r\nClass Label Extends Component\r\n\tField text:String\r\n\tField textRed%, textGreen%, textBlue%\r\n\tField textXOffset# = 0\r\n\tField textYOffset# = 0\r\n\tField textXAlign# = 0\r\n\tField textYAlign# = 0\r\n\t\r\n\tMethod New(parent:Component)\r\n\t\tSuper.New(parent)\r\n\tEnd\r\n\t\r\n\tMethod DrawComponent:Void()\r\n\t\tSuper.DrawComponent()\r\n\t\t' TODO: draw text\r\n\tEnd\r\nEnd\r\n\r\nClass Button Extends Label\r\nPrivate\r\n\tField styleSelected:ComponentStyle = Null\r\n\t\r\nPublic\r\n\tField selected:Bool\r\n\tField toggle:Bool\r\n\tField radioGroup:RadioGroup\r\n\tField radioValue$\r\n\t\r\n\tMethod New(parent:Component)\r\n\t\tSuper.New(parent)\r\n\t\tSelf.forwardAction = FindActionTarget()\r\n\t\tmouseAdapter = New ButtonMouseAdapter(Self)\r\n\tEnd\r\n\t\r\n\tMethod New(parent:Component, forwardAction:Component)\r\n\t\tSuper.New(parent)\r\n\t\tSelf.forwardAction = forwardAction\r\n\t\tmouseAdapter = New ButtonMouseAdapter(Self)\r\n\tEnd\r\n\t\r\n\tMethod StyleSelected:ComponentStyle() Property\r\n\t\tIf styleSelected = Null Then styleSelected = New ComponentStyle\r\n\t\tReturn styleSelected\r\n\tEnd\r\n\tMethod StyleSelected:Void(style:ComponentStyle) Property\r\n\t\tstyleSelected = style\r\n\tEnd\r\n\t\r\n\tMethod GetCurrentStyle:ComponentStyle()\r\n\t\tIf selected And styleSelected <> Null Then Return styleSelected\r\n\t\tReturn Super.GetCurrentStyle()\r\n\tEnd\r\nEnd\r\n\r\nClass ButtonMouseAdapter Extends AbstractMouseAdapter\r\n\tField button:Button\r\n\tMethod New(button:Button)\r\n\t\tSelf.button = button\r\n\tEnd\r\n\tMethod MouseClicked:Void(x#, y#, button%)\r\n\t\t' is it a radio button?\r\n\t\tIf Self.button.radioGroup <> Null Then\r\n\t\t\tSelf.button.radioGroup.SelectButton(Self.button)\r\n\t\t' is it a toggle button?\r\n\t\tElseIf Self.button.toggle Then\r\n\t\t\tSelf.button.selected = Not Self.button.selected\r\n\t\tEnd\r\n\t\tSelf.button.ActionPerformed(Self.button, ACTION_CLICKED)\r\n\tEnd\r\nEnd\r\n\r\nClass RadioGroup\r\n\tField buttons:ArrayList