The purpose of this repository is to provide a way for people to create placeholder images quickly. https://www.craigoates.net/Software/project/11
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.7 KiB

module Validation
open System.Drawing
open SmoulderingBeachBall.Domain.DomainTypes
open System
let colourList =
[ "blue", Brushes.AliceBlue;
"brown", Brushes.Brown;
"black", Brushes.Black;
"gray", Brushes.Gray;
"green", Brushes.Green;
"purple", Brushes.Purple;
"red", Brushes.Red;
"white", Brushes.White;
"yellow", Brushes.Yellow;]
|> Map.ofList
let isColourValid (colour: string) =
colourList
|> Map.containsKey (colour.ToLower())
let parseColour colour =
match (isColourValid colour) with
| true ->
colourList
|> Map.find (colour.ToLower())
| false ->
invalidArg "Colour"
(String.Concat("[ERROR] The colour specifed is invalid.\n",
"Please use the 'list-colours' command to see what you can use."))
let getDesktopPath =
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
let parsePath (path: string) =
match path with
| path when ((path.ToLower()).Equals "desktop") -> getDesktopPath
| path when ((path.ToLower()).Equals "d") -> getDesktopPath
| _ -> path
let buildDefaultSpec iWidth iHeight =
let oSpec =
{ colour = Brushes.Black
overlayType = Full }
let spec =
{ width = iWidth
height = iHeight
colour = Brushes.AntiqueWhite
filePath = getDesktopPath
overlay = Some oSpec
}
spec
let parseOverlay (oType: string) =
match oType.ToLower() with
| "border" -> Border
| "b" -> Border
| "full" -> Full
| "f" -> Full
| _ -> invalidArg "Overlay Type" "The overlay type must be either 'border' or 'full'."
let buildOverlaySpec oColour (oType: string) =
let oSpec =
{ colour = parseColour oColour;
overlayType = parseOverlay oType }
oSpec
let buildMainSpec iWidth iHeight mainColour path oSpec =
let spec =
{ width = iWidth;
height = iHeight;
colour = parseColour mainColour
filePath = parsePath path
overlay = oSpec }
spec
let buildSpec iWidth iHeight mainColour oColour (oType: string) path =
let spec =
match oType.ToLower() with
| "none" | "n" -> buildMainSpec iWidth iHeight mainColour path option.None
| _ ->
let oSpec = buildOverlaySpec oColour oType
buildMainSpec iWidth iHeight mainColour path (Some oSpec)
spec