using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using UnityEngine;
using System;

public class ActiveModule : DetectionModule {
	private Set<ClassType> detectable;

	public ActiveModule(JObject json) : base(json) {
		this.detectable = new Set<ClassType>();
		foreach (int classType in json["canDetect"]) {
			detectable.add((ClassType)(classType - 1));
		}

		sprite = Resources.Load("Sprites/Modules/Active/" + getUniqueName(), typeof(Sprite)) as Sprite;
	}

	override public bool canDetect(ClassType type) {
		return detectable.contains(type);
	}

	public static ActiveModule[] loadModules(string[] filenames) {
		Array.Sort(filenames);
		ActiveModule[] array = new ActiveModule[filenames.Length];

		for (int i = 0; i < filenames.Length; i++) {
			array[i] = new ActiveModule(jsonFromFile(filenames[i]));
		}

		return array;
	}

	override public void updateClasses() {
	}

	override public ModuleData getData(int parent, float angleOffset, Vector position) {
		return new ActiveModuleData(parent, this, angleOffset, position);
	}
}

public class ActiveModuleData : DetectionModuleData{
	public ActiveModuleData(int parent, Module template, float angleOffset, Vector position) : base(parent, template, angleOffset, position) {
	}
}