//===========================================================================//
// File:	Interface_Tool.cpp                                                  //
// Project: MUNGA           Brick: Interest Manager	                       //
// Contents: Interface specifications for interest manager						  //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  -----------------------------------------------------------//
// 08/25/97  JMA  Infrastructure changes.                                    //
// 08/25/97  ECH  Infrastructure changes.                                    //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc.                //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "AdeptHeaders.hpp"
#include "Interface.hpp"
#include "Tool.hpp"
#include "Controls.hpp"

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Interface__GameModel::ConstructGameModel(Script *script)
{

	Check_Object(script);
	#if defined(_ARMOR)
		int stack_level = Tool::Instance->GetStackLevel();
	#endif

	//
	//--------------
	// Set up stream
	//--------------
	//
	MemoryStream *model_stream = script->modelStream;
	Check_Object(model_stream);
	model_stream->AllocateBytes(sizeof(Interface__GameModel));
	Entity__GameModel::ConstructGameModel(script);
	Interface__GameModel *model =
		Cast_Pointer(Interface__GameModel*, model_stream->GetPointer());

	//
	//------------------------------
	// Set up the model file pointer
	//------------------------------
	//
	NotationFile *model_file = script->modelFile;
	Check_Object(model_file);

	//
	//-------------------------
	// Get the mappings to hold
	//-------------------------
	//

	model->mappingStreamResourceID = ResourceID::Null;
	Page *page = model_file->GetPage("GameData");
	Check_Object(page);
	NotationFile mapping_file;
	page->GetEntry("Mappings", &mapping_file, true);

	//
	//--------------------------------------
	// See if the resource needs to be built
	//--------------------------------------
	//

	Resource mapping_res1("content\\Interfaces\\Common\\freinterface.control");
	Resource mapping_res2("content\\Interfaces\\Common\\gerinterface.control");
	Resource mapping_res3("content\\Interfaces\\Common\\spainterface.control");
	Resource mapping_res4("content\\Interfaces\\Common\\japinterface.control");
	Resource mapping_res5("content\\Interfaces\\Common\\korinterface.control");
	Resource mapping_res6("content\\Interfaces\\Common\\chiinterface.control");
	Resource mapping_res7("content\\Interfaces\\Common\\itainterface.control");
	Resource mapping_res8("content\\Interfaces\\Common\\porinterface.control");
	Resource mapping_res9("content\\Interfaces\\Common\\daninterface.control");
	Resource mapping_res10("content\\Interfaces\\Common\\norinterface.control");
	Resource mapping_res11("content\\Interfaces\\Common\\sweinterface.control");
	Resource mapping_res12("content\\Interfaces\\Common\\fininterface.control");
	Resource mapping_res13("content\\Interfaces\\Common\\interface.control");
	
	CControlMappingList cont_list;
	
	cont_list.LoadList ("content\\Interfaces\\Common\\freinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream1;
	cont_list.SaveList (stream1);
	mapping_res1.Save (&stream1,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\gerinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream2;
	cont_list.SaveList (stream2);
	mapping_res2.Save (&stream2,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\spainterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream3;
	cont_list.SaveList (stream3);
	mapping_res3.Save (&stream3,NULL);

	cont_list.LoadList ("content\\Interfaces\\Common\\japinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream4;
	cont_list.SaveList (stream4);
	mapping_res4.Save (&stream4,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\korinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream5;
	cont_list.SaveList (stream5);
	mapping_res5.Save (&stream5,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\chiinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream6;
	cont_list.SaveList (stream6);
	mapping_res6.Save (&stream6,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\itainterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream7;
	cont_list.SaveList (stream7);
	mapping_res7.Save (&stream7,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\porinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream8;
	cont_list.SaveList (stream8);
	mapping_res8.Save (&stream8,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\daninterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream9;
	cont_list.SaveList (stream9);
	mapping_res9.Save (&stream9,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\norinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream10;
	cont_list.SaveList (stream10);
	mapping_res10.Save (&stream10,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\sweinterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream11;
	cont_list.SaveList (stream11);
	mapping_res11.Save (&stream11,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\fininterface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream12;
	cont_list.SaveList (stream12);
	mapping_res12.Save (&stream12,NULL);
	
	cont_list.LoadList ("content\\Interfaces\\Common\\interface.control",script->modelClassData);
    Stuff::DynamicMemoryStream stream13;
	cont_list.SaveList (stream13);
	mapping_res13.Save (&stream13,NULL);

	//
	//------------------------------------------
	// Get the custom mappings to hold, BRB etc.
	//------------------------------------------
	//

	Resource mapping_res(mapping_file.GetFileName());
	if (!mapping_res.DoesResourceExist() || !mapping_res.IsResourceUpToDate())
	{
		cont_list.LoadList (mapping_file.GetFileName(),script->modelClassData);
		Stuff::DynamicMemoryStream stream;
		cont_list.SaveList (stream);
		mapping_res.Save (&stream,mapping_file.GetFileDependencies());
	}
	else if (!mapping_res.IsRegistered())
		mapping_res.AddFileDependenciesTo(Resource::ParentFileDependencies);

	// Not sure if this is needed
	//model->mappingStreamResourceID = mapping_res.GetResourceID();

	Verify(stack_level == Tool::Instance->GetStackLevel());
}
