//===========================================================================//
// File: Tool.hpp                                                            //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 08/25/97  JMA  Infrastructure changes												  //
// 08/25/97  ECH	Infrastructure changes												  //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-97, Virtual World Entertainment, Inc.                  //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once

#include "Adept.hpp"
#include "Entity.hpp"
#include "EntityClassData.hpp"
#include <GameOS\ToolOS.hpp>
#include "Application.hpp"

namespace Adept {

	const char g_SkinSignal='@';

	//##########################################################################
	//########################    Tool    ###########################
	//##########################################################################

	class Tool
		#if defined(_ARMOR)
			: public Stuff::Signature
		#endif
	{
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Command line parsing
	//
	public:
		static Tool *Instance;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Construction, Destruction, Testing
	// 
	public:
		Tool();
		~Tool();

		void TestInstance();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// File Stream Support
	// 
	public:
		void PushFilePath(Stuff::NotationFile *file);
		void PushFilePath(Stuff::FileStream *file);
		void PopFilePath();
		int GetStackLevel()
			{Check_Object(this); return stackIndex;}

		const char* GetCurrentStackPath()
			{Check_Object(this); return filePathStack[stackIndex];}

		static const char* GetToolFileName(const char* file_name);

		static void __stdcall GetFileForGOS(
			const char* filename,
			BYTE** memory,
			DWORD* size
		);

		static bool __stdcall FindFileForGOS(const char* filename);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Resource Building
	// 
	public:
		Entity::ClassData* ConstructGameModel(
			Stuff::MemoryStream *model_stream,
			const char *model_class,
			Stuff::NotationFile *model_file
		);

		ResourceID MakeNewGameModel(
			const char *model_name,
			const char *model_class
		);

		Entity::ClassData* ConstructDataList(
			Resource *resource,
			const char* model_name
		);

		Entity::CreateMessage* ConstructCreateMessage(
			Stuff::MemoryStream *model_stream,
			Stuff::Page *instance_page,
			ReplicatorID *base_id
		);

		void ConstructCreateMessage(
			Resource *resource,
			Stuff::NotationFile *instance_file,
			ReplicatorID *base_id
		);

		Entity::CreateMessage* ConstructCreateMessage(
			Stuff::MemoryStream *model_stream,
			Stuff::NotationFile *instance_file,
			ReplicatorID *base_id
		);

		void BuildResources(
			Stuff::NotationFile *build_script,
			DWORD content_version,
			Stuff::FileDependencies *dependencies,
			short level=-1,
			__int64 build_age=0
		);

		bool ParseBuildFile(
			ResourceFile *res_file,
			Stuff::Page *resource_file_entry
		);

		virtual bool IsRegisterable(const char* entry_type);

		virtual void BuildResource(
			const char* entry_type,
			const char* entry_filename
		);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Resource Building
	//
	public:
		virtual void CreateRendererData(
			ResourceID *stream_resource,
			Entity::ClassData *class_data,
			Stuff::NotationFile *renderer_file,
			int renderer_type
		);

		virtual bool FindControlGroupAndElement(
			int *group,
			int *element,
			const char *control_name
		);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Protected Data
	//
	protected:
		char **filePathStack;
		int
			stackIndex,
			stackSize;
	};

}

