//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * ピクチャパス変更フィルタ実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Graphics/SceneFilter/ChangePicturePathFilter/\
ChangePicturePathFilter.h"
#include "Core/Utility/StringTokenizer.h"
#include "Graphics/Picture/PictureManager.h"
#include "Core/InputOutput/FilePath.h"

namespace Lamp{

//------------------------------------------------------------------------------
// コンストラクタ
ChangePicturePathFilter::ChangePicturePathFilter(Scene* scene) :
	SceneFilterInterface(scene){
}
//------------------------------------------------------------------------------
// デストラクタ
ChangePicturePathFilter::~ChangePicturePathFilter(){
}
//------------------------------------------------------------------------------
// フィルタ
bool ChangePicturePathFilter::filter(const String& command){
	StringTokenizer tokenizer_(command);
	if(!tokenizer_.hasMoreTokens()){
		ErrorOut("ChangePicturePathFilter::filter() Not found filter name");
		return false;
	}
	String filterName = tokenizer_.getNextToken();
	if(filterName != "ChangePicturePath"){
		ErrorOut("ChangePicturePathFilter::filter() Invalid filter name %s",
			filterName.getBytes());
		return false;
	}
	if(!tokenizer_.hasMoreTokens()){
		ErrorOut("ChangePicturePathFilter::filter() Not found change path");
		return false;
	}
	path_ = tokenizer_.getNextToken();
	return filterPicture();
}
//------------------------------------------------------------------------------
// ピクチャのフィルタ
bool ChangePicturePathFilter::filterPicture(){
	int count = pictureManager_->getCount();
	// 各ピクチャのチェック
	for(int i = 0; i < count; i++){
		Picture* picture = pictureManager_->get(i);
		FilePath filePath(picture->getPath());
		picture->setPath(path_ + filePath.getFileName());
	}
	return true;
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
