#include "MW4Headers.hpp"

#include "StickyMover.hpp"
#include "MWTool.hpp"


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	StickyMover__GameModel::ConstructGameModel(Script *script)
{
	Check_Object(script);

	//
	//--------------
	// Set up stream
	//--------------
	//
	MemoryStream *model_stream = script->modelStream;
	Check_Object(model_stream);
	model_stream->AllocateBytes(sizeof(StickyMover__GameModel));
	WeaponMover__GameModel::ConstructGameModel(script);
	
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
bool
	StickyMover__GameModel::ReadAndVerify(
		StickyMover__GameModel *model,
		ModelAttributeEntry *attribute_entry, 
		const char *data,
		char **error,
		int error_buffer
	)
{
	Check_Object(attribute_entry);
	
	bool result = false;
	bool valid_data = (*data != '\0');

	//
	//----------------------------------------
	//Read in the values from the data entered
	//----------------------------------------
	//
	result = 
		WeaponMover__GameModel::ReadAndVerify(
			model, 
			attribute_entry, 
			data,
			error,
			error_buffer
		);
	//
	//---------------------------
	//Verify all the model values
	//---------------------------
	//
	switch(attribute_entry->attributeID)
	{
	case ActiveTimeAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 20.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if(model->activeTime <= 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]ActiveTime=%f}: value must be > 0!",
					model->activeTime
				);
				result = false;
			}
			break;
		}
	case IdleLoopResourceAttributeID:
		{
			if(!valid_data)
			{
				ResourceID value = ResourceID::Null;
				attribute_entry->SetValue(model, (void *)&value);
				result = true;
			}
			break;
		}
	}

	return result;
}