Exemplo n.º 1
0
	void Console::SendCharacter(char32_t character)
	{
		switch (character)
		{
			case '\b':
			{
				Nz::String input = m_inputDrawer.GetText();
				if (input.GetLength() <= s_inputPrefixSize) // Prevent removal of the input prefix
					return; // Ignore if no user character is there

				input.Resize(-1, Nz::String::HandleUtf8);
				m_inputDrawer.SetText(input);
				break;
			}

			case '\r':
			case '\n':
				ExecuteInput();
				break;

			default:
			{
				if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control)
					return;

				m_inputDrawer.AppendText(Nz::String::Unicode(character));
				break;
			}
		}

		m_inputTextSprite->Update(m_inputDrawer);
	}
Exemplo n.º 2
0
void KeyState::ManageInput(KeyStatus isKeyPressed, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm)
{
	if (key.code == Nz::Keyboard::Key::M && key.shift)
		fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
	else if (key.code == Nz::Keyboard::Key::N && key.shift)
	{
		if (m_keyStatus == KeyStatus::Pressed)
			m_keyStatus = KeyStatus::Released;
		else
			m_keyStatus = KeyStatus::Pressed;
	}
	else 
	{
		Nz::String content;
		if (m_keyStatus == KeyStatus::Pressed)
			content = "Pressed: ";
		else
			content = "Released: ";

		Nz::String keyName = Nz::Keyboard::GetKeyName(key.code);
		if (keyName.IsEmpty())
		{
			m_text.SetContent("Unknown\nM for Menu");
		}
		else
		{
			content += keyName;
			if (key.alt)
				content += " alt";
			if (key.control)
				content += " control";
			if (key.repeated)
				content += " repeated";
			if (key.shift)
				content += " shift";
			if (key.system)
				content += " system";
			
			m_text.SetContent(content + "\nM for Menu");
		}
	}
}
Exemplo n.º 3
0
#include <Nazara/Core/String.hpp>
#include <Catch/catch.hpp>

SCENARIO("String", "[CORE][STRING]")
{
	GIVEN("One string 'a'")
	{
		Nz::String aDefaultString(1, 'a');

		WHEN("We add information")
		{
			aDefaultString.Append("Default");
			aDefaultString.Insert(aDefaultString.GetSize(), "String");

			THEN("The result should be 'aDefaultString'")
			{
				REQUIRE(aDefaultString == "aDefaultString");
				REQUIRE(aDefaultString.GetSize() == 14);
				REQUIRE(aDefaultString.GetCapacity() >= 14);
			}

			AND_WHEN("We test Contains and Find")
			{
				THEN("These results are expected")
				{
					CHECK(aDefaultString.Contains('D'));
					CHECK(aDefaultString.Contains("String", 3));
					CHECK(aDefaultString.Contains(Nz::String("sTRING"), 3, Nz::String::CaseInsensitive));
					REQUIRE(aDefaultString.FindLast('g') == aDefaultString.GetSize() - 1);
					CHECK(aDefaultString.EndsWith('G', Nz::String::CaseInsensitive));
					aDefaultString.Append(" ng bla");
Exemplo n.º 4
0
	void LuaAPI::Register_Audio(Nz::LuaInstance& instance)
	{
		/*********************************** Nz::SoundBuffer **********************************/
		Nz::LuaClass<Nz::SoundBufferRef> soundBuffer("SoundBuffer");

		soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
		{
			return new Nz::SoundBufferRef(new Nz::SoundBuffer);
		});

		soundBuffer.SetMethod("Destroy", &Nz::SoundBuffer::Destroy);
		soundBuffer.SetMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
		soundBuffer.SetMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
		soundBuffer.SetMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
		soundBuffer.SetMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
		soundBuffer.SetMethod("IsValid", &Nz::SoundBuffer::IsValid);
		soundBuffer.SetMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());

		soundBuffer.SetStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);

		// Manual
		soundBuffer.SetMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
		{
			int index = 1;
			Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
			unsigned int sampleCount = lua.Check<unsigned int>(&index);
			unsigned int sampleRate = lua.Check<unsigned int>(&index);

			std::size_t bufferSize = 0;
			const char* buffer = lua.CheckString(index, &bufferSize);
			lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");

			lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
			return 1;
		});

		soundBuffer.SetMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
		{
			lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
			return 1;
		});

		soundBuffer.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
		{
			Nz::StringStream stream("SoundBuffer(");
			if (soundBuffer->IsValid())
			{
				Nz::String filePath = soundBuffer->GetFilePath();
				if (!filePath.IsEmpty())
					stream << "File: " << filePath << ", ";
				
				stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s";
			}
			stream << ')';

			lua.PushString(stream);
			return 1;
		});

		soundBuffer.Register(instance);

		/*********************************** Nz::SoundEmitter **********************************/
		Nz::LuaClass<Nz::SoundEmitter> soundEmitter("SoundEmitter");

		soundEmitter.SetMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
		soundEmitter.SetMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);
		soundEmitter.SetMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
		soundEmitter.SetMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
		soundEmitter.SetMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
		soundEmitter.SetMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
		soundEmitter.SetMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
		soundEmitter.SetMethod("GetPosition", &Nz::Sound::GetPosition);
		soundEmitter.SetMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
		soundEmitter.SetMethod("GetVelocity", &Nz::Sound::GetVelocity);
		soundEmitter.SetMethod("GetVolume", &Nz::SoundEmitter::GetVolume);
		soundEmitter.SetMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
		soundEmitter.SetMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
		soundEmitter.SetMethod("Pause", &Nz::SoundEmitter::Pause);
		soundEmitter.SetMethod("Play", &Nz::SoundEmitter::Play);
		soundEmitter.SetMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
		soundEmitter.SetMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
		soundEmitter.SetMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
		soundEmitter.SetMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
		soundEmitter.SetMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
		soundEmitter.SetMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
		soundEmitter.SetMethod("Stop", &Nz::SoundEmitter::Stop);

		soundEmitter.Register(instance);

		/*********************************** Nz::Sound **********************************/
		Nz::LuaClass<Nz::Sound> soundClass("Sound");
		soundClass.Inherit(soundEmitter);

		soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound*
		{
			return new Nz::Sound;
		});

		soundClass.SetMethod("GetBuffer", &Nz::Sound::GetBuffer);
		soundClass.SetMethod("IsPlayable", &Nz::Sound::IsPlayable);
		soundClass.SetMethod("IsPlaying", &Nz::Sound::IsPlaying);
		soundClass.SetMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
		soundClass.SetMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);

		// Manual
		soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int
		{
			Nz::StringStream stream("Sound(");
			if (const Nz::SoundBuffer* buffer = sound.GetBuffer())
				stream << buffer;

			stream << ')';

			lua.PushString(stream);
			return 1;
		});

		soundClass.Register(instance);
	}
Exemplo n.º 5
0
	LuaBinding_Audio::LuaBinding_Audio(LuaBinding& binding) :
	LuaBinding_Base(binding)
	{
		/*********************************** Nz::SoundEmitter **********************************/
		soundEmitter.Reset("SoundEmitter");
		{
			soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
			soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);

			soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
			soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
			soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
			soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
			soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
			soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition);
			soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
			soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity);
			soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume);

			soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
			soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);

			soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
			soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);

			soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
			soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
			soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
			soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
			soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
			soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);

			soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
		}

		/*********************************** Nz::Music **********************************/
		music.Reset("Music");
		{
			music.Inherit(soundEmitter);

			music.BindDefaultConstructor();

			//musicClass.SetMethod("Create", &Nz::Music::Create);
			//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);

			music.BindMethod("EnableLooping", &Nz::Music::EnableLooping);

			music.BindMethod("GetDuration", &Nz::Music::GetDuration);
			music.BindMethod("GetFormat", &Nz::Music::GetFormat);
			music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
			music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
			music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
			music.BindMethod("GetStatus", &Nz::Music::GetStatus);

			music.BindMethod("IsLooping", &Nz::Music::IsLooping);

			music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());

			music.BindMethod("Pause", &Nz::Music::Pause);
			music.BindMethod("Play", &Nz::Music::Play);

			music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);

			music.BindMethod("Stop", &Nz::Music::Stop);

			// Manual
			music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int
			{
				Nz::StringStream ss("Music(");
				ss << instance.GetFilePath() << ')';

				lua.PushString(ss);
				return 1;
			});
		}

		/*********************************** Nz::Sound **********************************/
		sound.Reset("Sound");
		{
			sound.Inherit(soundEmitter);

			sound.BindDefaultConstructor();

			sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);

			sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
			sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);

			sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());

			sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);

			// Manual
			sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int
			{
				Nz::StringStream ss("Sound(");
				if (const Nz::SoundBuffer* buffer = instance.GetBuffer())
					ss << buffer;

				ss << ')';

				lua.PushString(ss);
				return 1;
			});
		}

		/*********************************** Nz::SoundBuffer **********************************/
		soundBuffer.Reset("SoundBuffer");
		{
			soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount)
			{
				NazaraUnused(lua);
				NazaraUnused(argumentCount);

				Nz::PlacementNew(instance, Nz::SoundBuffer::New());
				return true;
			});

			soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);

			soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
			soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
			soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
			soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);

			soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);

			soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());

			soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);

			// Manual
			soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
			{
				int index = 2;
				Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
				unsigned int sampleCount = lua.Check<unsigned int>(&index);
				unsigned int sampleRate = lua.Check<unsigned int>(&index);

				std::size_t bufferSize = 0;
				const char* buffer = lua.CheckString(index, &bufferSize);
				lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");

				lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
				return 1;
			});

			soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
			{
				lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
				return 1;
			});

			soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
			{
				Nz::StringStream ss("SoundBuffer(");
				if (instance->IsValid())
				{
					Nz::String filePath = instance->GetFilePath();
					if (!filePath.IsEmpty())
						ss << "File: " << filePath << ", ";

					ss << "Duration: " << instance->GetDuration() / 1000.f << "s";
				}
				ss << ')';

				lua.PushString(ss);
				return 1;
			});
		}
	}