/*
 * Verrückte Turing-Maschinen — A turing complete game
 * Copyright (C) 2016-2018 kcf <vidofnir@folksprak.org>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

namespace mod_vtm.mod_manifestation.mod_svg.mod_actuator
	{
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		export const shape_arrow_1 : string = (
			lib_svg.path_description
				(
					(
						[
							lib_vector.cartesian( 4,  0),
							lib_vector.cartesian( 0, +1),
							lib_vector.cartesian(-0,  0),
							lib_vector.cartesian( 0, -1),
						]
					),
					true
				)
		);
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		export const shape_arrow_2 : string = (
			lib_svg.path_description
				(
					[
						lib_vector.cartesian(+3,  0),
						lib_vector.cartesian( 0, +2),
						lib_vector.cartesian(+1,  0),
						lib_vector.cartesian( 0, -2),
					],
					true
				)
		);
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		export type signature_actuator =
			{
				view : (actuator : mod_vtm.mod_model.mod_actuator.type_actuator)=>Array<lib_xml.type_node>;
			}
		;
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		export var trait_actuator : lib_trait.type_trait<signature_actuator> = lib_trait.create<signature_actuator>();
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		export type type_actuator =
			{
				model : mod_vtm.mod_model.mod_actuator.type_actuator;
				spot : mod_vtm.mod_model.mod_spot.type_spot;
			}
		;
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		function create
			(
				model : mod_vtm.mod_model.mod_actuator.type_actuator,
				spot : mod_vtm.mod_model.mod_spot.type_spot
			)
			: type_actuator
			{
				return {
					"model": model,
					"spot": spot
				};
			}
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		export function create_extended
			(
				model : mod_vtm.mod_model.mod_actuator.type_actuator,
				spot : mod_vtm.mod_model.mod_spot.type_spot
			)
			: type_manifestation<mod_vtm.mod_model.mod_actuator.type_actuator>
			{
				return {
					"kind": "svg_actuator",
					"data": create(model, spot),
				};
			}
		
										
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		function view(actuator_ : type_actuator) : lib_xml.type_node
			{
				let actuator : mod_vtm.mod_model.mod_actuator.type_actuator = actuator_.model;
				let node_frame = function () : lib_xml.type_node
					{
						return (
							lib_svg.path
								(
									lib_list.sequence(6).map(i => lib_vector.polar(((i+0.5)/6) * (2*Math.PI), 0.5)),
									true,
									{
										"class": "frame"
									}
								)
						);
					}
				;
				let position : mod_position.type_position = mod_position.from_spot(actuator_.spot);
				let node_tile : lib_xml.type_node = (
					lib_svg.group
						(
							{
								"class": "tile",
								"rel": mod_vtm.mod_model.mod_spot.hash(actuator_.spot),
								"transform": lib_svg.translation(position.x, position.y),
							},
							(
								[node_frame()]
								.concat(lib_trait.deploy<signature_actuator>(trait_actuator, actuator.kind)["view"](actuator))
							)
						)
				);
				return node_tile;
			}
		
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		function bind(actuator : type_actuator) : void
			{
			}
			
		
		/**
		 * @author kcf <vidofnir@folksprak.org>
		 */
		lib_trait.attend<signature_manifestation<mod_vtm.mod_model.mod_actuator.type_actuator, lib_xml.type_node>>
			(
				trait_manifestation,
				"svg_actuator",
				{
					"view": (manifestation) => view(manifestation.data),
					"bind": (manifestation) => bind(manifestation.data),
				}
			)
		;
		
	}

