Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Array.au3>
- #include "JSON.au3"
- #Include <File.au3>
- #Include <color.au3>
- Dim $ThemeColors[1][2] = [[$_JSONNull,'JSONObject']]
- Dim $ThemeImages[1][2] = [[$_JSONNull,'JSONObject']]
- Dim $ThemeTints[1][2] = [[$_JSONNull,'JSONObject']]
- Dim $ThemeProperties[1][2] = [[$_JSONNull,'JSONObject']]
- Dim $ThemeTheme[1][2] = [[$_JSONNull,'JSONObject']]
- Dim $ThemeName = ""
- Dim $ThemeVersion = 1
- Dim $LoadedManifestPath = ""
- Dim $SavedManifestPath = ""
- Func _LoadManifest($path)
- Local $file = FileOpen($path, 0)
- If $file = -1 Then
- MsgBox(0, "Error", "Unable to open file for loading.")
- Exit
- EndIf
- Local $manifest = FileRead($file)
- FileClose($file)
- _ProcessManifest($manifest)
- $LoadedManifestPath = $path
- EndFunc
- Func _SaveManifest($path)
- Local $manifest = _MakeManifest()
- Local $file = FileOpen($path, 2)
- If $file = -1 Then
- MsgBox(0, "Error", "Unable to open save file.")
- Exit
- EndIf
- FileWrite ($file, $manifest )
- FileClose($file)
- $SavedManifestPath = $path
- EndFunc
- func _ProcessManifest ($string)
- local $Theme = _JSONDecode($string)
- $ThemeName = _GetKey($Theme,'name')
- $ThemeVersion = Number(_GetKey($Theme,'version'))
- $Theme = _GetKey($Theme,'theme')
- $ThemeColors = _GetKey($Theme,'colors')
- $ThemeImages = _GetKey($Theme,'images')
- $ThemeTints = _GetKey($Theme,'tints')
- $ThemeProperties = _GetKey($Theme,'properties')
- EndFunc
- func _ProcessManifestArray ($Theme)
- $ThemeName = _GetKey($Theme,'name')
- $ThemeVersion = Number(_GetKey($Theme,'version'))
- $Theme = _GetKey($Theme,'theme')
- $ThemeColors = _GetKey($Theme,'colors')
- $ThemeImages = _GetKey($Theme,'images')
- $ThemeTints = _GetKey($Theme,'tints')
- $ThemeProperties = _GetKey($Theme,'properties')
- EndFunc
- func _NewManifest($name,$version)
- ReDim $ThemeColors[1][2]
- ReDim $ThemeImages[1][2]
- ReDim $ThemeTints[1][2]
- ReDim $ThemeProperties[1][2]
- ReDim $ThemeTheme[1][2]
- $ThemeName = $name
- $ThemeVersion = $version
- endfunc
- func _MakeManifest()
- Local $Manifest[1][2] = [[$_JSONNull,'JSONObject']]
- Local $Theme[1][2] = [[$_JSONNull,'JSONObject']]
- _KeyAdd($Manifest,'name',$ThemeName)
- _KeyAdd($Manifest,'version',_FloatString($ThemeVersion))
- _KeyAdd($Theme,'colors',$ThemeColors)
- _KeyAdd($Theme,'images',$ThemeImages)
- _KeyAdd($Theme,'tints',$ThemeTints)
- _KeyAdd($Theme,'properties',$ThemeProperties)
- _KeyAdd($Manifest,'theme',$Theme)
- Return _JSONEncode($Manifest,'',True)
- EndFunc
- func _MakeManifestArray()
- Local $Manifest[1][2] = [[$_JSONNull,'JSONObject']]
- Local $Theme[1][2] = [[$_JSONNull,'JSONObject']]
- _KeyAdd($Manifest,'name',$ThemeName)
- _KeyAdd($Manifest,'version',_FloatString($ThemeVersion))
- _KeyAdd($Theme,'colors',$ThemeColors)
- _KeyAdd($Theme,'images',$ThemeImages)
- _KeyAdd($Theme,'tints',$ThemeTints)
- _KeyAdd($Theme,'properties',$ThemeProperties)
- _KeyAdd($Manifest,'theme',$Theme)
- Return $Manifest
- EndFunc
- func _Tint($hue,$sat,$lum,$alpha=false)
- Dim $ra[3]=[$hue,$sat,$lum]
- if $alpha Then
- _ArrayAdd($ra,$alpha)
- EndIf
- Return ($ra)
- EndFunc
- ; Colour spelt the American way because they whinge more than anybody ;)
- func _Color($red,$green,$blue,$alpha=false)
- Local $ra[3]=[$red,$green,$blue]
- if $alpha Then
- _ArrayAdd($ra,$alpha)
- EndIf
- Return ($ra)
- EndFunc
- func _FloatString($num)
- if Int($num)=$num Then
- Return(String($num) & '.0')
- Else
- Return(String($num))
- EndIf
- EndFunc
- func _KeyAdd(ByRef $object, $key, $value)
- ReDim $object[UBound($object)+1][2]
- $object[UBound($object)-1][0]=$key
- $object[UBound($object)-1][1]=$value
- EndFunc
- Func _KeyDelete(ByRef $object, $key)
- local $Index = _ArraySearch($object, $key, 0, 0, 0, 1)
- if $Index >-1 Then
- _ArrayDelete($object,$Index)
- EndIf
- EndFunc
- Func _SetKey(ByRef $object, $key, $value='')
- local $Index = _ArraySearch($object, $key, 0, 0, 0, 1)
- if $Index >-1 Then
- If $value<>'' Then
- $object[$Index][0]=$key
- $object[$Index][1]=$value
- Else
- _KeyDelete($object, $key)
- EndIf
- Else
- If $value<>'' Then
- _KeyAdd($object, $key, $value)
- EndIf
- EndIf
- EndFunc
- Func _GetKey(ByRef $object, $key)
- local $Index = _ArraySearch($object, $key, 0, 0, 0, 1)
- if $Index >-1 Then
- Return $object[$Index][1]
- Else
- Return ''
- EndIf
- EndFunc
- ; Set the color ussing an array that may or may not contain an alpha [red,green,blue,alpha]
- Func _SetColor ($key, $value='')
- _SetKey($ThemeColors, $key, $value)
- EndFunc
- ;Returns an array of [red,green,blue,alpha] if there is no alpha it will return [red,green,blue]
- Func _GetColor ($key)
- Return _GetKey($ThemeColors, $key)
- EndFunc
- ; Set a color using something like 0xFFFFFF
- Func _SetColorRGB ($key, $value='')
- $value = _ColorSetRGB($value)
- _SetKey($ThemeColors, $key, $value)
- EndFunc
- ; Returns a color, such as 0xFFFFFF
- Func _GetColorRGB ($key)
- Local $temp = _GetKey($ThemeColors, $key)
- If $temp <> '' Then
- ReDim $temp[3]
- Return _ColorSetRGB($temp)
- Else
- Return ''
- EndIf
- EndFunc
- Func _SetTint ($key, $value='')
- _SetKey($ThemeTints, $key, $value)
- EndFunc
- Func _GetTint ($key)
- Return _GetKey($ThemeTints, $key)
- EndFunc
- Func _SetPropety ($key, $value='')
- _SetKey($ThemeProperties, $key, $value)
- EndFunc
- Func _GetProperty ($key)
- Return _GetKey($ThemeProperties, $key)
- EndFunc
- Func _SetImage ($key, $value='')
- _SetKey($ThemeImages, $key, $value)
- EndFunc
- Func _GetImage ($key)
- Return _GetKey($ThemeImages, $key)
- EndFunc
- Func _GetFullImagePath($image, $basepath)
- $image = _GetImage($image)
- if $image <> '' Then
- Return _PathFull($basepath &'\' & $image)
- Else
- Return ''
- EndIf
- EndFunc
- Func _SetImageFromPath($key, $imagedirectory, $path)
- Dim $szDrive, $szDir, $szFName, $szExt
- _PathSplit($path, $szDrive, $szDir, $szFName, $szExt)
- _SetKey($ThemeImages, $key, $imagedirectory & '/' & $szFName & $szExt)
- EndFunc
- Func _GetName()
- Return $ThemeName
- EndFunc
- Func _GetVersion()
- Return Number($ThemeVersion)
- EndFunc
- Func _SetName($value)
- $ThemeName = $value
- EndFunc
- Func _SetVersion($value)
- $ThemeVersion = _FloatString($value)
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement