using UnityEngine;

namespace Cryville.Crtr.Skin.Components {
	public abstract class SectionalGameObject : MeshBase {
		protected Vector3? prevpt;
		protected Quaternion? prevrot;
		protected int vertCount = 0;
		Part part = Part.whole;
		enum Part {
			whole = 0,
			idle = 1,
			start = 2,
			end = 3,
		}

		public SectionalGameObject() {
			SubmitProperty("partial", new PropOp.Boolean(v => part = Part.idle));
			SubmitProperty("part", new PropOp.Enum<Part>(v => part = v, v => (Part)v), 2);
		}

		public override void Init() {
			UpdateZIndex();
			UpdateColor();
			Reset();
		}
		
		public void AppendPoint(Vector3 p) {
			AppendPoint(p, Quaternion.identity);
		}

		public void AppendPoint(Vector3 p, Quaternion r) {
			if (prevpt == p && prevrot == r || ((int)part & 1) == 1) return;
			AppendPointInternal(p, r);
			// if (!headGenerated) Logger.Log("main", 0, "Skin/Polysec", "{0}", r);
			prevpt = p;
			prevrot = r;
			vertCount++;
		}

		protected abstract void AppendPointInternal(Vector3 wp, Quaternion r);

		public abstract void Seal();

		public virtual void Reset() {
			vertCount = 0;
			prevpt = null;
			prevrot = null;
		}
	}
}
