/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "ui/ui_item_script_event.h"
		#include "ui/ui_item_scripted_object.h"
		#include "ui/ui_item_script_unit.h"
		#include "ui/ui_item.h"
		#include "physic/physic_world.h"
		#include "script/script_engine_types.h"
		#include "script/script_variant.h"

		using namespace GS::Script;
		using namespace GS::S2D;


//------------------------------------------------------------------------------
void				ItemScriptEvent::OnSetup(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnSetup"))
			unit->DoFunctionCall();
}
void				ItemScriptEvent::OnSetupDone(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnSetupDone"))
			unit->DoFunctionCall();
}
void				ItemScriptEvent::OnReset(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnReset"))
			unit->DoFunctionCall();
}
void				ItemScriptEvent::OnActivate(Item *item, bool activate)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(((ItemScriptUnit *)unit)->activation_callback && unit->SetupFunctionCall("OnActivate", ((ItemScriptUnit *)unit)->activation_callback))
		{
			unit->PushFunctionCallArgument(activate);
			unit->DoFunctionCall();
		}
}
void				ItemScriptEvent::OnUpdate(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(((ItemScriptUnit *)unit)->update_callback && unit->SetupFunctionCall("OnUpdate", ((ItemScriptUnit *)unit)->update_callback))
			unit->DoFunctionCall();
}
void				ItemScriptEvent::OnPhysicStep(Item *item, bool step_taken)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(((ItemScriptUnit *)unit)->physic_callback && unit->SetupFunctionCall("OnPhysicStep", ((ItemScriptUnit *)unit)->physic_callback))
		{
			unit->PushFunctionCallArgument(step_taken);
			unit->DoFunctionCall();
		}
}

void				ItemScriptEvent::OnRenderDone(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnRenderDone"))
			unit->DoFunctionCall();
}
void				ItemScriptEvent::OnRenderUser(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(((ItemScriptUnit *)unit)->render_user_callback && unit->SetupFunctionCall("OnRenderUser", ((ItemScriptUnit *)unit)->render_user_callback))
			unit->DoFunctionCall();
}
void				ItemScriptEvent::OnDelete(Item *item)
{
	ListForeachPtr(Unit *, unit, item->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnDelete"))
			unit->DoFunctionCall();
}
//------------------------------------------------------------------------------
