Skip to content

Commit

Permalink
Cross platform custom component create gui
Browse files Browse the repository at this point in the history
  • Loading branch information
goopey7 committed Jan 5, 2024
1 parent 1dd153f commit 6efe37b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
81 changes: 81 additions & 0 deletions components/createComponentLinux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 ClassName"
exit 1
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Get the directory of the script
CLASS_NAME="$1"
HEADER_FILE="${SCRIPT_DIR}/${CLASS_NAME}.h" # Define the header file path using the script's directory
CPP_FILE="${SCRIPT_DIR}/${CLASS_NAME}.cpp" # Define the cpp file path using the script's directory

echo "Creating C++ class: ${CLASS_NAME}..."

# Generate header file
cat <<EOF >"${HEADER_FILE}"
#pragma once
#include <goop/Components.h>
#include <imgui.h>
class ${CLASS_NAME} : public goop::CustomComponent
{
public:
${CLASS_NAME}(goop::Entity e) : goop::CustomComponent(e) {name = "${CLASS_NAME}";}
void init();
void update(float dt);
void gui();
private:
void onCollisionEnter(goop::Entity other) final;
void onCollisionExit(goop::Entity other) final;
};
EOF

echo "Created ${HEADER_FILE}"

# Generate cpp file
cat <<EOF >"${CPP_FILE}"
#include "${CLASS_NAME}.h"
// Gets called when the game starts
void ${CLASS_NAME}::init()
{
/* do not remove this line */
CustomComponent::init();
//...
}
// Gets called every frame
void ${CLASS_NAME}::update(float dt)
{
//...
}
// Collision callbacks
void ${CLASS_NAME}::onCollisionEnter(goop::Entity other)
{
// std::cout << "Player started colliding with " << other.getComponent<goop::TagComponent>().tag << std::endl;
//...
}
void ${CLASS_NAME}::onCollisionExit(goop::Entity other)
{
// std::cout << "Player stopped colliding with " << other.getComponent<goop::TagComponent>().tag << std::endl;
//...
}
// Editor GUI - Shown in inspector view
// Refer to ImGui documentation for more info
void ${CLASS_NAME}::gui()
{
// ImGui::Text("Hello from %s", name.c_str());
//...
}
EOF

echo "Created ${CPP_FILE}"
echo "C++ class '${CLASS_NAME}' created successfully!"

cd ../build
cmake ..
2 changes: 2 additions & 0 deletions components/createComponent.sh → components/createComponentWin.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ EOF
echo "Created ${CPP_FILE}"
echo "C++ class '${CLASS_NAME}' created successfully!"

cd ..
cmake .
6 changes: 5 additions & 1 deletion editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,11 @@ void EditorApp::gui()
if (ImGui::Button("Create"))
{
// execute components/createComponent.sh name
std::string cmd = "components/createComponent.sh ";
#ifdef _WIN32
std::string cmd = "start components/createComponentWin.sh ";
#else
std::string cmd = "components/createComponentLinux.sh ";
#endif
cmd += componentName;
system(cmd.c_str());
ImGui::CloseCurrentPopup();
Expand Down

0 comments on commit 6efe37b

Please sign in to comment.