#!/usr/bin/env bash

set -e

if [ "$#" -ne 1 ]; then
    echo "Usage: psemek-create-project <project-name>"
    exit 0
fi

#git init .
#git submodule add git@bitbucket.org:lisyarus/psemek.git
#git submodule update --init --recursive

mkdir -p source include/${1}

cat > .gitignore << EOF
.gitignore
build
package
CMakeLists.txt.user
EOF

cat > CMakeLists.txt << EOF
cmake_minimum_required(VERSION 3.16)
project(${1})

set(CMAKE_CXX_STANDARD 20)
set(PSEMEK_EXAMPLES OFF)

set(PSEMEK_PACKAGE_OUTPUT_PATH package)
set(PSEMEK_GRAPHICS_API OPENGL)

add_subdirectory(psemek)

file(GLOB_RECURSE ${1^^}_SOURCES LIST_DIRECTORIES FALSE "\${CMAKE_CURRENT_SOURCE_DIR}/source/*")
file(GLOB_RECURSE ${1^^}_HEADERS LIST_DIRECTORIES FALSE "\${CMAKE_CURRENT_SOURCE_DIR}/include/*")

psemek_add_application(${1} \${${1^^}_SOURCES} \${${1^^}_HEADERS})
EOF

cat > source/application.cpp << EOF
#include <psemek/app/default_application_factory.hpp>

namespace ${1}
{

	using namespace psemek;

	struct application
		: app::application
	{
		application(options const &, context const &)
		{

		}

		bool running() const override
		{
			return running_;
		}

		void stop() override
		{
			running_ = false;
		}

		void update() override
		{}

		void present() override
		{}

	private:
		bool running_ = true;
	};

}

namespace psemek::app
{

	std::unique_ptr<application::factory> make_application_factory()
	{
		application::options options
		{
			.name = "${1^}",
		};

		return default_application_factory<${1}::application>(options);
	}

}
EOF
