﻿/*
 * Copyright 2014 Mtzky
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrawingBitmap = System.Drawing.Bitmap;
using DrawingColor = System.Drawing.Color;
using DrawingGraphics = System.Drawing.Graphics;
using DrawingInterpolationMode = System.Drawing.Drawing2D.InterpolationMode;
using DrawingPixelFormat = System.Drawing.Imaging.PixelFormat;
using DrawingPoint = System.Drawing.Point;
using DrawingRectangle = System.Drawing.Rectangle;
using DrawingSize = System.Drawing.Size;
using System.Drawing.Drawing2D;

namespace Mobitap.Scripts
{
	class ScStVs : MobitapScriptBase
	{
		private static readonly ScStVs instance = new ScStVs() {
			new ExtractDef(0.37, 0.84, 0.26, 0.145) {
				new SendInputDef(SendInputActivity.Tap, new SendInputArgs(0.5, 0.92), (DrawingBitmap bmp, DrawingColor color) => 
				{
					return (
						(176 < color.R) &&
						(color.G <  64) &&
						(color.B <  64)
					);
				}),
			},
			new ExtractDef(0.35, 0.32, 0.14, 0.09) {
				new SendInputDef(SendInputActivity.Tap, new SendInputArgs(0.384, 0.304), (DrawingBitmap bmp, DrawingColor color) => 
				{
					return (
						(
							(240 < color.R) &&
							( 32 < color.G) && (color.G <  48) &&
							( 32 < color.B) && (color.B <  48)
						) || (
							(240 < color.R) &&
							(128 < color.G) && (color.G < 160) &&
							( 48 < color.B) && (color.B <  64)
						)
					);
				}),
			},
			new ExtractDef(0.58, 0.63, 0.12, 0.14) {
				new SendInputDef(SendInputActivity.Tap, new SendInputArgs(0.64, 0.7), (DrawingBitmap bmp, DrawingColor color) => 
				{
					return (
						(192 < color.R) &&
						( 48 < color.G) && (color.G <  64) &&
						( 48 < color.B) && (color.B <  64)
					);
				}),
			},
			new ExtractDef(0.57, 0.72, 0.12, 0.13) {
				new SendInputDef(SendInputActivity.Tap, new SendInputArgs(0.63, 0.785), (DrawingBitmap bmp, DrawingColor color) => 
				{
					return (
						(160 < color.R) && (color.R < 208) &&
						( 48 < color.G) && (color.G <  64) &&
						( 48 < color.B) && (color.B <  64)
					);
				}),
			},
			new ExtractDef(0.44, 0.63, 0.12, 0.14) {
				new SendInputDef(SendInputActivity.Tap, new SendInputArgs(0.5, 0.7), (DrawingBitmap bmp, DrawingColor color) => 
				{
					return (
						(192 < color.R) &&
						( 48 < color.G) && (color.G <  64) &&
						( 48 < color.B) && (color.B <  64)
					);
				}),
			},
			new ExtractDef(0.875, 0.945, 0.03, 0.02) {
				new SendInputDef(SendInputActivity.Tap, new SendInputArgs(0.88, 0.946), (DrawingBitmap bmp, DrawingColor color) => 
				{
					return (
						(144 < color.R) && (color.R < 160) &&
						(144 < color.G) && (color.G < 160) &&
						(144 < color.B) && (color.B < 160)
					);
				}),
			},
		};

		private static readonly SendInputArgs DefaultArgs = new SendInputArgs(0.5, 0.5);

		private ScStVs() { }
		public static ScStVs Instance { get { return instance; } }

		public override bool Execute(MobitapScriptSender sender, DrawingBitmap bmp)
		{
			if (base.Execute(sender, bmp))
			{
				return true;
			}
			SendInputActivity.Tap.SendInput(sender, DefaultArgs);
			return true;
		}
	}

}
