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

public class DetectionModule : Module {
	private Set<ClassType> detectable;
	private float range;
	private float power;

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

		this.range = (float)json["range"];
		this.power = (float)json["power"];

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

	public float getRange() {
		return range;
	}

	public float getPower() {
		return power;
	}

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

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

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

		return array;
	}

	override public void updateClasses() {
	}

	override public ModuleData getData(int parent) {
		return new DetectionModuleData(parent, this);
	}
}

public class DetectionModuleData : ModuleData{
	public DetectionModuleData(int parent, Module template) : base(parent, template) {
	}

	override public void deployUnit(int storedUnitID) {
		Debug.LogError("This module cannot deploy units");
	}
}