Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #32

Merged
merged 10 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,24 @@ on:
branches: ['main']

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Get dependencies
run: |
git clone https://github.com/google/googletest
cd ${{github.workspace}}/test/include
git clone https://github.com/gabime/spdlog
- uses: actions/checkout@v4
with:
submodules: true

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build build --config ${{env.BUILD_TYPE}} --parallel

- name: Create BP/RP Folders
working-directory: ${{github.workspace}}/build/test
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: mkdir BP RP

- name: Run Tests
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --rerun-failed --output-on-failure
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ compile_commands.json
CTestTestfile.cmake
_deps

# vscode
# Debug
.vscode
.vs

# Regolith
/build
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "adk/data/include/spdlog"]
path = adk/data/include/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "adk/data/third-party/spdlog"]
path = adk/data/third-party/spdlog
url = https://github.com/gabime/spdlog
44 changes: 29 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0074 NEW)

set(This adkhead)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

project(${This} C CXX)

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

enable_testing()

add_subdirectory(googletest)
set(PROJECT_NAME adk-test)
project(${PROJECT_NAME} VERSION 0.1)

set(Headers
Main.h
configure_file(
CMakeLists.txt.in
googletest-download/CMakeLists.txt
)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

set(Sources
Main.cpp
add_subdirectory(
${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
)

add_library(${This} STATIC ${Sources} ${Headers})
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}/include")
endif()

enable_testing()
add_subdirectory(test)

set(SOURCE_FILES Main.cpp)
add_library(${PROJECT_NAME} ${SOURCE_FILES})

# add_executable(manifest
# Manifest.cpp
# )
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8.2)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ This Add-on Development Kit allows you to create add-ons without writing JSON! I

## Installing ADK

- Install [Regolith](https://bedrock-oss.github.io/regolith/guide/installing)
- Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019)
- Install [CMake](https://cmake.org/install/)
- Run `regolith init` in your directory of choice
- Run `regolith install adk`
- Open the directory in your choice of IDE
- Install [Regolith](https://bedrock-oss.github.io/regolith/guide/installing)
- Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022)
- Install [CMake](https://cmake.org/install/)
- Run `regolith init` in your directory of choice
- Run `regolith install adk`
- Open the directory in your choice of IDE

\*Note, as of now, `manifest.json` needs to be created manually

Expand Down
34 changes: 22 additions & 12 deletions adk/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(adk VERSION 0.1 LANGUAGES CXX)
set(BIN_NAME adk)
set(LIB_NAME adk-lib)

find_package(spdlog REQUIRED)
project(${BIN_NAME} VERSION 0.1)

include_directories(include include/generator)
add_executable(adk
Main.cpp
Object.cpp
Data.cpp
Recipe.cpp
Language.cpp
GlobalRegistry.cpp
)
file(GLOB_RECURSE SRC_FILES *.cpp )
file(GLOB_RECURSE HEADER_FILES include/*.h include/*.hpp)
add_library(${LIB_NAME} STATIC ${SRC_FILES})
file(COPY assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(adk PRIVATE spdlog::spdlog)
add_subdirectory(third-party/spdlog)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

target_include_directories(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${LIB_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)

target_link_libraries(${LIB_NAME} spdlog)

add_executable(${BIN_NAME} Main.cpp)

target_link_libraries(${BIN_NAME} PRIVATE ${LIB_NAME})
target_include_directories(${BIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
2 changes: 1 addition & 1 deletion adk/data/compile.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cmake -S ./data/adk -B adk-build -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_TOOLCHAIN_FILE=%1
cmake -S ./data/adk -B adk-build -DCMAKE_BUILD_TYPE=Release
cmake --build adk-build --config Release --parallel
.\adk-build\Release\adk.exe
4 changes: 2 additions & 2 deletions adk/data/include/AxisBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class AxisBlock : public Block {
j = Block::output(mod_id, id);

// Properties
j["minecraft:block"]["description"]["properties"]
j["minecraft:block"]["description"]["states"]
[mod_id + ":rotation"] = json::array({0, 1, 2});

// Components
j["minecraft:block"]["components"]["minecraft:on_player_placing"]
["event"] = mod_id + ":set_rotation";
j["minecraft:block"]["events"][mod_id + ":set_direction"]
["set_block_property"][mod_id + ":cardinal"] =
["set_block_state"][mod_id + ":cardinal"] =
"math.floor(q.block_face/2.0)";

// Permutations
Expand Down
13 changes: 7 additions & 6 deletions adk/data/include/CandleBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CandleBlock : public Block {
j = Block::output(mod_id, id);

// Properties
j["minecraft:block"]["description"]["properties"][mod_id + ":count"]
j["minecraft:block"]["description"]["states"][mod_id + ":count"]
["values"] = {{"min", 1}, {"max", 4}};

// Components
Expand All @@ -57,16 +57,17 @@ class CandleBlock : public Block {
{"three", "q.block_state('" + mod_id + ":count') == 3"},
{"four", "q.block_state('" + mod_id + ":count') == 4"}};
j["minecraft:block"]["components"]["minecraft:on_interact"]
["condition"] = "q.is_item_name_any('slot.weapon.mainhand', '" + id +
"') && q.block_state('" + mod_id + ":count') != 4";
["condition"] =
"q.is_item_name_any('slot.weapon.mainhand', '" + mod_id + ":" +
id + "') && q.block_state('" + mod_id + ":count') != 4";
j["minecraft:block"]["components"]["minecraft:on_interact"]["event"] =
mod_id + ":add_candle";

// Events
j["minecraft:block"]["events"][mod_id + ":add_candle"]
["set_block_property"][mod_id + ":count"] =
"(q.block_state('" + mod_id +
":count') < 4) ? q.block_state('" + mod_id + ":count') + 1 : 4";
["set_block_state"][mod_id + ":count"] =
"(q.block_state('" + mod_id + ":count') < 4) ? q.block_state('" +
mod_id + ":count') + 1 : 4";
j["minecraft:block"]["events"][mod_id + ":add_candle"]
["decrement_stack"] = json::object();

Expand Down
21 changes: 12 additions & 9 deletions adk/data/include/HeadBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HeadBlock : public Block {
j = Block::output(mod_id, id);

// Properties
j["minecraft:block"]["description"]["properties"][mod_id + ":rotation"]
j["minecraft:block"]["description"]["states"][mod_id + ":rotation"]
["values"] = {{"min", 0}, {"max", 15}};

j["minecraft:block"]["description"]["traits"]
Expand Down Expand Up @@ -104,7 +104,7 @@ class HeadBlock : public Block {

// Events
j["minecraft:block"]["events"][mod_id + ":set_rotation"]
["set_block_property"][mod_id + ":rotation"] =
["set_block_state"][mod_id + ":rotation"] =
"q.block_face == 1 ? { t.positive_head_rot = q.head_y_rotation(0) "
"+ 360 * (q.head_y_rotation(0) != "
"Math.abs(q.head_y_rotation(0))); t.block_rotation = "
Expand All @@ -120,13 +120,6 @@ class HeadBlock : public Block {
temp["components"].update(
helper.rotation(std::vector<int>{0, -90, 0}, id));
j["minecraft:block"]["permutations"].push_back(temp);
temp = {{"condition",
"q.block_state('" + mod_id +
":rotation') >= 4 || "
"q.block_state('minecraft:block_face') == 'east'"}};
temp["components"].update(
helper.rotation(std::vector<int>{0, -90, 0}, id));
j["minecraft:block"]["permutations"].push_back(temp);
temp = {{"condition",
"q.block_state('" + mod_id +
":rotation') >= 8 || "
Expand All @@ -141,6 +134,16 @@ class HeadBlock : public Block {
temp["components"].update(
helper.rotation(std::vector<int>{0, 90, 0}, id));
j["minecraft:block"]["permutations"].push_back(temp);
temp = {{"condition", "q.block_state('minecraft:block_face') != 'up'"}};
temp["components"].update(
helper.selection(std::make_pair(std::vector<int>{-4, 4, 0},
std::vector<int>{8, 8, 8}),
id));
temp["components"].update(
helper.collision(std::make_pair(std::vector<int>{-4, 4, 0},
std::vector<int>{8, 8, 8}),
id));
j["minecraft:block"]["permutations"].push_back(temp);

return j;
};
Expand Down
37 changes: 6 additions & 31 deletions adk/data/include/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string>

//#include "ItemComponent.h"
#include "ItemProperty.h"
#include "json.hpp"

Expand All @@ -14,20 +15,8 @@
*/
class Item {
protected:
std::string _display_name;
std::string _icon;
int _stack;
std::string _block_placer;
std::vector<std::string> _block_placer_placement;
std::string _cooldown_category;
float _cooldown_time;
std::string _dye;
std::string _entity_placer;
std::vector<std::string> _entity_placer_placement;
std::vector<std::string> _entity_placer_dispense;
std::vector<double> _offset_main;
std::vector<double> _offset_offhand;
std::string _projectile_entity;
ItemProperty _internal;
//ItemComponent helper;

public:
using json = nlohmann::json;
Expand All @@ -40,21 +29,7 @@ class Item {
*
* @param property ItemProperty
*/
Item(ItemProperty property) {
_display_name = property.getName();
_icon = property.getIcon();
_stack = property.getStack();
_block_placer = property.getBlockPlacer();
_block_placer_placement = property.getBlockPlacerPlacement();
_cooldown_category = property.getCooldownCategory();
_cooldown_time = property.getCooldownTime();
_dye = property.getDyeProperty();
_entity_placer = property.getEntityPlacer();
_entity_placer_placement = property.getEntityPlacerPlacement();
_entity_placer_dispense = property.getEntityPlacerDispense();
_offset_main = property.getOffsetMain();
_offset_offhand = property.getOffsetOff();
}
Item(ItemProperty property) { _internal = property; }

/**
* @brief Generates the json object
Expand All @@ -64,7 +39,7 @@ class Item {
* @return json
*/
virtual json output(std::string mod_id, std::string id) {
j["format_version"] = "1.20.40";
/*j["format_version"] = "1.20.40";
j["minecraft:item"]["description"]["identifier"] = mod_id + ":" + id;

if (!_display_name.empty())
Expand Down Expand Up @@ -122,7 +97,7 @@ class Item {

if (!_projectile_entity.empty())
j["minecraft:item"]["components"]["minecraft:projectile"]
["projectile_entity"] = _projectile_entity;
["projectile_entity"] = _projectile_entity;*/

return j;
}
Expand Down
Loading