Initial commit
This commit is contained in:
1
src/CMakeLists.txt
Normal file
1
src/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory(jasper)
|
16
src/jasper/CMakeLists.txt
Normal file
16
src/jasper/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
#project packages
|
||||
|
||||
if(APPLE)
|
||||
set(JASPER_DIST_BIN JasperStudio.app/Contents/MacOS)
|
||||
set(JASPER_DIST_LIB JasperStudio.app/Contents/Library)
|
||||
set(JASPER_DIST_MODULE JasperStudio.app/Contents/Plugins)
|
||||
set(JASPER_DIST_RESOURCES JasperStudio.app/Contents/Resources)
|
||||
set(JASPER_DIST_MAC_APP_CONTENTS JasperStudio.app/Contents)
|
||||
endif()
|
||||
|
||||
add_subdirectory(modules)
|
||||
add_subdirectory(player)
|
||||
if(TURBINE_BUILD_TYPE STREQUAL "Native")
|
||||
add_subdirectory(tools)
|
||||
endif()
|
42
src/jasper/modules/CMakeLists.txt
Normal file
42
src/jasper/modules/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
||||
# module dir list
|
||||
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(world)
|
||||
|
||||
# module libraries
|
||||
|
||||
# Keel
|
||||
add_library(
|
||||
JasperKeelModules STATIC
|
||||
keelmodules.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
JasperKeelModules PUBLIC
|
||||
Keel
|
||||
NostalgiaKeelModules
|
||||
JasperCore-Keel
|
||||
JasperWorld-Keel
|
||||
)
|
||||
|
||||
# Studio
|
||||
if(TURBINE_BUILD_TYPE STREQUAL "Native")
|
||||
add_library(
|
||||
JasperStudioModules STATIC
|
||||
studiomodules.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
JasperStudioModules PUBLIC
|
||||
StudioAppLib
|
||||
NostalgiaStudioModules
|
||||
JasperWorld-Studio
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_library(JasperProfile INTERFACE)
|
||||
target_compile_definitions(
|
||||
JasperProfile INTERFACE
|
||||
OLYMPIC_PROJECT_NAME="Jasper"
|
||||
OLYMPIC_PROJECT_NAMESPACE=jasper
|
||||
OLYMPIC_PROJECT_DATADIR=".jasper"
|
||||
)
|
8
src/jasper/modules/core/CMakeLists.txt
Normal file
8
src/jasper/modules/core/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
add_subdirectory(src)
|
||||
|
||||
install(
|
||||
DIRECTORY
|
||||
include/jasper
|
||||
DESTINATION
|
||||
include
|
||||
)
|
27
src/jasper/modules/core/include/jasper/core/animpage.hpp
Normal file
27
src/jasper/modules/core/include/jasper/core/animpage.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
namespace jasper::core {
|
||||
|
||||
struct AnimPage {
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.core.AnimPage";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
ox::String tilesheetPath;
|
||||
ox::String subsheetPath;
|
||||
};
|
||||
|
||||
oxModelBegin(AnimPage)
|
||||
oxModelFieldRename(tilesheet_path, tilesheetPath)
|
||||
oxModelFieldRename(subsheet_path, subsheetPath)
|
||||
oxModelEnd()
|
||||
|
||||
|
||||
}
|
27
src/jasper/modules/core/include/jasper/core/bootfile.hpp
Normal file
27
src/jasper/modules/core/include/jasper/core/bootfile.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
namespace jasper::core {
|
||||
|
||||
struct Bootfile {
|
||||
static constexpr auto TypeName = "net.drinkingtea.jasper.core.Bootfile";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
static constexpr auto Preloadable = true;
|
||||
ox::String app;
|
||||
ox::Vector<ox::String> args;
|
||||
};
|
||||
|
||||
oxModelBegin(Bootfile)
|
||||
oxModelField(app)
|
||||
oxModelField(args)
|
||||
oxModelEnd()
|
||||
|
||||
|
||||
}
|
13
src/jasper/modules/core/include/jasper/core/keelmodule.hpp
Normal file
13
src/jasper/modules/core/include/jasper/core/keelmodule.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
namespace jasper::core {
|
||||
|
||||
keel::Module const*keelModule() noexcept;
|
||||
|
||||
}
|
22
src/jasper/modules/core/src/CMakeLists.txt
Normal file
22
src/jasper/modules/core/src/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
add_library(JasperCore INTERFACE)
|
||||
|
||||
target_include_directories(
|
||||
JasperCore INTERFACE
|
||||
../include
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
JasperCore INTERFACE
|
||||
NostalgiaCore
|
||||
)
|
||||
|
||||
add_subdirectory(keel)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
JasperCore
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
16
src/jasper/modules/core/src/keel/CMakeLists.txt
Normal file
16
src/jasper/modules/core/src/keel/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
add_library(
|
||||
JasperCore-Keel
|
||||
keelmodule.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
JasperCore-Keel PUBLIC
|
||||
Keel
|
||||
JasperCore
|
||||
)
|
||||
install(
|
||||
TARGETS
|
||||
JasperCore-Keel
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
46
src/jasper/modules/core/src/keel/keelmodule.cpp
Normal file
46
src/jasper/modules/core/src/keel/keelmodule.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include <jasper/core/bootfile.hpp>
|
||||
|
||||
namespace jasper::core {
|
||||
|
||||
class CoreModule: public keel::Module {
|
||||
private:
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
return ox::String("net.drinkingtea.jasper.core");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::TypeDescGenerator> types() const noexcept override {
|
||||
return {
|
||||
keel::generateTypeDesc<Bootfile>,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<const keel::BaseConverter*> converters() const noexcept override {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept override {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static const CoreModule mod;
|
||||
keel::Module const*keelModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
27
src/jasper/modules/keelmodules.cpp
Normal file
27
src/jasper/modules/keelmodules.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include <jasper/core/keelmodule.hpp>
|
||||
#include <jasper/world/keelmodule.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
void registerKeelModules() noexcept;
|
||||
}
|
||||
|
||||
namespace jasper {
|
||||
|
||||
static bool modulesRegistered = false;
|
||||
void registerKeelModules() noexcept {
|
||||
if (modulesRegistered) {
|
||||
return;
|
||||
}
|
||||
modulesRegistered = true;
|
||||
nostalgia::registerKeelModules();
|
||||
keel::registerModule(core::keelModule());
|
||||
keel::registerModule(world::keelModule());
|
||||
}
|
||||
|
||||
}
|
25
src/jasper/modules/studiomodules.cpp
Normal file
25
src/jasper/modules/studiomodules.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studioapp/studioapp.hpp>
|
||||
|
||||
#include <jasper/world/studiomodule.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
void registerStudioModules() noexcept;
|
||||
}
|
||||
|
||||
namespace jasper {
|
||||
|
||||
static bool modulesRegistered = false;
|
||||
void registerStudioModules() noexcept {
|
||||
if (modulesRegistered) {
|
||||
return;
|
||||
}
|
||||
modulesRegistered = true;
|
||||
nostalgia::registerStudioModules();
|
||||
studio::registerModule(world::studioModule());
|
||||
}
|
||||
|
||||
}
|
8
src/jasper/modules/world/CMakeLists.txt
Normal file
8
src/jasper/modules/world/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
add_subdirectory(src)
|
||||
|
||||
install(
|
||||
DIRECTORY
|
||||
include/jasper
|
||||
DESTINATION
|
||||
include
|
||||
)
|
14
src/jasper/modules/world/include/jasper/world/consts.hpp
Normal file
14
src/jasper/modules/world/include/jasper/world/consts.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/stringliteral.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
inline constexpr ox::StringLiteral FileExt_jwob("jwob");
|
||||
inline constexpr ox::StringLiteral FileExt_jwld("jwld");
|
||||
|
||||
}
|
13
src/jasper/modules/world/include/jasper/world/keelmodule.hpp
Normal file
13
src/jasper/modules/world/include/jasper/world/keelmodule.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
keel::Module const*keelModule() noexcept;
|
||||
|
||||
}
|
35
src/jasper/modules/world/include/jasper/world/prefab.hpp
Normal file
35
src/jasper/modules/world/include/jasper/world/prefab.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
#include <nostalgia/core/core.hpp>
|
||||
|
||||
#include <jasper/core/animpage.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
struct PrefabDoc {
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.world.PrefabDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
ox::Size footprint;
|
||||
ox::Size visibleSz;
|
||||
ox::String tilesheetPath;
|
||||
ox::String subsheetPath;
|
||||
};
|
||||
|
||||
oxModelBegin(PrefabDoc)
|
||||
oxModelField(footprint)
|
||||
oxModelFieldRename(visible_size, visibleSz)
|
||||
oxModelFieldRename(tilesheet_path, tilesheetPath)
|
||||
oxModelFieldRename(subsheet_path, subsheetPath)
|
||||
oxModelEnd()
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
studio::Module const*studioModule() noexcept;
|
||||
|
||||
}
|
31
src/jasper/modules/world/include/jasper/world/world.hpp
Normal file
31
src/jasper/modules/world/include/jasper/world/world.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nostalgia/core/context.hpp>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "prefab.hpp"
|
||||
#include "worldstatic.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
namespace ncore = nostalgia::core;
|
||||
|
||||
class World {
|
||||
private:
|
||||
WorldStatic const&m_worldStatic;
|
||||
|
||||
public:
|
||||
explicit World(WorldStatic const&worldStatic) noexcept;
|
||||
|
||||
ox::Error setupDisplay(ncore::Context &ctx) const noexcept;
|
||||
|
||||
private:
|
||||
void setupLayer(ncore::Context&, ox::Vector<uint16_t> const&layer, unsigned layerNo) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
230
src/jasper/modules/world/include/jasper/world/worldstatic.hpp
Normal file
230
src/jasper/modules/world/include/jasper/world/worldstatic.hpp
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/types.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
#include <nostalgia/core/tilesheet.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
namespace ncore = nostalgia::core;
|
||||
|
||||
struct SpriteDoc {
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.world.SpriteDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
ox::String tilesheetPath;
|
||||
ox::Vector<ncore::SubSheetId> subsheetId;
|
||||
|
||||
};
|
||||
|
||||
struct TileDoc {
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.world.TileDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
ncore::SubSheetId subsheetId = -1;
|
||||
ox::String subsheetPath;
|
||||
uint8_t type = 0;
|
||||
ox::Array<uint8_t, 4> layerAttachments;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ncore::SubSheetId> getSubsheetId(ncore::TileSheet const&ts) const noexcept {
|
||||
// prefer the already present ID
|
||||
if (subsheetId > -1) {
|
||||
return subsheetId;
|
||||
}
|
||||
return ts.getIdFor(subsheetPath);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ox::StringView> getSubsheetPath(
|
||||
ncore::TileSheet const&ts) const noexcept {
|
||||
// prefer the already present path
|
||||
if (!subsheetPath.len()) {
|
||||
return ts.getNameFor(subsheetId);
|
||||
}
|
||||
return ox::StringView(subsheetPath);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
oxModelBegin(TileDoc)
|
||||
oxModelFieldRename(subsheet_id, subsheetId)
|
||||
oxModelFieldRename(subsheet_path, subsheetPath)
|
||||
oxModelField(type)
|
||||
oxModelFieldRename(layer_attachments, layerAttachments)
|
||||
oxModelEnd()
|
||||
|
||||
struct WorldDoc {
|
||||
|
||||
using TileMapRow = ox::Vector<TileDoc>;
|
||||
using TileMapLayer = ox::Vector<TileMapRow>;
|
||||
using TileMap = ox::Vector<TileMapLayer>;
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.world.WorldDoc";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
ox::String tilesheet; // path
|
||||
ox::Vector<ox::String> palettes; // paths
|
||||
TileMap tiles;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Size size(std::size_t layerIdx) const noexcept {
|
||||
const auto &layer = this->tiles[layerIdx];
|
||||
const auto rowCnt = static_cast<int>(layer.size());
|
||||
if (!rowCnt) {
|
||||
return {};
|
||||
}
|
||||
auto colCnt = layer[0].size();
|
||||
// find shortest row (they should all be the same, but you know this data
|
||||
// could come from a file)
|
||||
for (auto const&row : layer) {
|
||||
colCnt = ox::min(colCnt, row.size());
|
||||
}
|
||||
return {static_cast<int>(colCnt), rowCnt};
|
||||
}
|
||||
};
|
||||
|
||||
oxModelBegin(WorldDoc)
|
||||
oxModelField(tilesheet)
|
||||
oxModelField(palettes)
|
||||
oxModelField(tiles)
|
||||
oxModelEnd()
|
||||
|
||||
|
||||
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b11111100) | val8;
|
||||
}
|
||||
constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b11110011) | static_cast<uint8_t>(val8 << 2);
|
||||
}
|
||||
constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b11001111) | static_cast<uint8_t>(val8 << 4);
|
||||
}
|
||||
constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||
const auto val8 = static_cast<uint8_t>(val);
|
||||
layerAttachments = (layerAttachments & 0b00111111) | static_cast<uint8_t>(val8 << 6);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr unsigned topEdge(uint8_t layerAttachments) noexcept {
|
||||
return layerAttachments & 0b11;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr unsigned bottomEdge(uint8_t layerAttachments) noexcept {
|
||||
return (layerAttachments >> 2) & 0b11;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr unsigned leftEdge(uint8_t layerAttachments) noexcept {
|
||||
return (layerAttachments >> 4) & 0b11;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr unsigned rightEdge(uint8_t layerAttachments) noexcept {
|
||||
return (layerAttachments >> 6) & 0b11;
|
||||
}
|
||||
|
||||
|
||||
struct WorldStatic {
|
||||
|
||||
constexpr static auto TypeName = "net.drinkingtea.nostalgia.world.WorldStatic";
|
||||
constexpr static auto TypeVersion = 1;
|
||||
constexpr static auto Preloadable = true;
|
||||
|
||||
struct Tile {
|
||||
uint16_t &tileMapIdx;
|
||||
uint8_t &tileType;
|
||||
uint8_t &layerAttachments;
|
||||
constexpr Tile(uint16_t &pTileMapIdx, uint8_t &pTileType, uint8_t &pLayerAttachments) noexcept:
|
||||
tileMapIdx(pTileMapIdx),
|
||||
tileType(pTileType),
|
||||
layerAttachments(pLayerAttachments) {
|
||||
}
|
||||
};
|
||||
struct Layer {
|
||||
uint16_t &columns;
|
||||
uint16_t &rows;
|
||||
ox::Vector<uint16_t> &tileMapIdx;
|
||||
ox::Vector<uint8_t> &tileType;
|
||||
ox::Vector<uint8_t> &layerAttachments;
|
||||
constexpr Layer(
|
||||
uint16_t &pColumns,
|
||||
uint16_t &pRows,
|
||||
ox::Vector<uint16_t> &pTileMapIdx,
|
||||
ox::Vector<uint8_t> &pTileType,
|
||||
ox::Vector<uint8_t> &pLayerAttachments) noexcept:
|
||||
columns(pColumns),
|
||||
rows(pRows),
|
||||
tileMapIdx(pTileMapIdx),
|
||||
tileType(pTileType),
|
||||
layerAttachments(pLayerAttachments) {
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr Tile tile(std::size_t i) noexcept {
|
||||
return {tileMapIdx[i], tileType[i], layerAttachments[i]};
|
||||
}
|
||||
constexpr auto setDimensions(ox::Size dim) noexcept {
|
||||
columns = static_cast<uint16_t>(dim.width);
|
||||
rows = static_cast<uint16_t>(dim.height);
|
||||
const auto tileCnt = static_cast<unsigned>(columns * rows);
|
||||
tileMapIdx.resize(tileCnt);
|
||||
tileType.resize(tileCnt);
|
||||
layerAttachments.resize(tileCnt);
|
||||
}
|
||||
};
|
||||
|
||||
ox::FileAddress tilesheet;
|
||||
ox::Vector<ox::FileAddress> palettes;
|
||||
// tile layer data
|
||||
ox::Vector<uint16_t> columns;
|
||||
ox::Vector<uint16_t> rows;
|
||||
ox::Vector<ox::Vector<uint16_t>> tileMapIdx;
|
||||
ox::Vector<ox::Vector<uint8_t>> tileType;
|
||||
ox::Vector<ox::Vector<uint8_t>> layerAttachments;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Layer layer(std::size_t i) noexcept {
|
||||
return {
|
||||
columns[i],
|
||||
rows[i],
|
||||
tileMapIdx[i],
|
||||
tileType[i],
|
||||
layerAttachments[i],
|
||||
};
|
||||
}
|
||||
|
||||
constexpr auto setLayerCnt(std::size_t layerCnt) noexcept {
|
||||
this->layerAttachments.resize(layerCnt);
|
||||
this->columns.resize(layerCnt);
|
||||
this->rows.resize(layerCnt);
|
||||
this->tileMapIdx.resize(layerCnt);
|
||||
this->tileType.resize(layerCnt);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
oxModelBegin(WorldStatic)
|
||||
oxModelField(tilesheet)
|
||||
oxModelField(palettes)
|
||||
oxModelField(columns)
|
||||
oxModelField(rows)
|
||||
oxModelField(tileMapIdx)
|
||||
oxModelField(tileType)
|
||||
oxModelField(layerAttachments)
|
||||
oxModelEnd()
|
||||
|
||||
}
|
30
src/jasper/modules/world/src/CMakeLists.txt
Normal file
30
src/jasper/modules/world/src/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
add_library(
|
||||
JasperWorld
|
||||
world.cpp
|
||||
worldstatic.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
JasperWorld PUBLIC
|
||||
../include
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
JasperWorld PUBLIC
|
||||
NostalgiaCore
|
||||
JasperCore
|
||||
)
|
||||
|
||||
add_subdirectory(keel)
|
||||
if(NOSTALGIA_BUILD_STUDIO)
|
||||
add_subdirectory(studio)
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
JasperWorld
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
17
src/jasper/modules/world/src/keel/CMakeLists.txt
Normal file
17
src/jasper/modules/world/src/keel/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
add_library(
|
||||
JasperWorld-Keel
|
||||
keelmodule.cpp
|
||||
typeconv.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
JasperWorld-Keel PUBLIC
|
||||
Keel
|
||||
JasperWorld
|
||||
)
|
||||
install(
|
||||
TARGETS
|
||||
JasperWorld-Keel
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
52
src/jasper/modules/world/src/keel/keelmodule.cpp
Normal file
52
src/jasper/modules/world/src/keel/keelmodule.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/module.hpp>
|
||||
|
||||
#include <jasper/world/worldstatic.hpp>
|
||||
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class WorldModule: public keel::Module {
|
||||
private:
|
||||
WorldDocToWorldStaticConverter m_worldDocToWorldStaticConverter;
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
return ox::String("net.drinkingtea.jasper.world");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::TypeDescGenerator> types() const noexcept override {
|
||||
return {
|
||||
keel::generateTypeDesc<WorldDoc>,
|
||||
keel::generateTypeDesc<WorldStatic>,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<const keel::BaseConverter*> converters() const noexcept override {
|
||||
return {
|
||||
&m_worldDocToWorldStaticConverter,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept override {
|
||||
return {
|
||||
keel::transformRule<WorldDoc, WorldStatic>,
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static const WorldModule mod;
|
||||
keel::Module const*keelModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
70
src/jasper/modules/world/src/keel/typeconv.cpp
Normal file
70
src/jasper/modules/world/src/keel/typeconv.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include "typeconv.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
namespace ncore = nostalgia::core;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept {
|
||||
if (attachment == 0) {
|
||||
return layer;
|
||||
} else {
|
||||
return attachment - 1;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void setLayerAttachments(unsigned layer, TileDoc const&srcTile, WorldStatic::Tile &dstTile) noexcept {
|
||||
setTopEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[0]));
|
||||
setBottomEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[1]));
|
||||
setLeftEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[2]));
|
||||
setRightEdge(
|
||||
dstTile.layerAttachments,
|
||||
adjustLayerAttachment(layer, srcTile.layerAttachments[3]));
|
||||
}
|
||||
|
||||
ox::Error WorldDocToWorldStaticConverter::convert(
|
||||
keel::Context &ctx,
|
||||
WorldDoc &src,
|
||||
WorldStatic &dst) const noexcept {
|
||||
oxRequire(ts, keel::readObj<ncore::TileSheet>(ctx, src.tilesheet));
|
||||
const auto layerCnt = src.tiles.size();
|
||||
dst.setLayerCnt(layerCnt);
|
||||
dst.tilesheet = ox::FileAddress(src.tilesheet);
|
||||
dst.palettes.reserve(src.palettes.size());
|
||||
for (const auto &pal : src.palettes) {
|
||||
dst.palettes.emplace_back(pal);
|
||||
}
|
||||
for (auto layerIdx = 0u; const auto &layer : src.tiles) {
|
||||
const auto layerDim = src.size(layerIdx);
|
||||
auto dstLayer = dst.layer(layerIdx);
|
||||
dstLayer.setDimensions(layerDim);
|
||||
for (auto tileIdx = 0u; const auto &row : layer) {
|
||||
for (const auto &srcTile : row) {
|
||||
auto dstTile = dstLayer.tile(tileIdx);
|
||||
dstTile.tileType = srcTile.type;
|
||||
oxRequire(path, srcTile.getSubsheetPath(*ts));
|
||||
oxRequire(mapIdx, ts->getTileOffset(path));
|
||||
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
|
||||
setLayerAttachments(layerIdx, srcTile, dstTile);
|
||||
++tileIdx;
|
||||
}
|
||||
}
|
||||
++layerIdx;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
17
src/jasper/modules/world/src/keel/typeconv.hpp
Normal file
17
src/jasper/modules/world/src/keel/typeconv.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <keel/typeconv.hpp>
|
||||
|
||||
#include <jasper/world/worldstatic.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class WorldDocToWorldStaticConverter: public keel::Converter<WorldDoc, WorldStatic> {
|
||||
ox::Error convert(keel::Context&, WorldDoc &src, WorldStatic &dst) const noexcept final;
|
||||
};
|
||||
|
||||
}
|
20
src/jasper/modules/world/src/studio/CMakeLists.txt
Normal file
20
src/jasper/modules/world/src/studio/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
add_library(
|
||||
JasperWorld-Studio
|
||||
studiomodule.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
JasperWorld-Studio PUBLIC
|
||||
JasperWorld
|
||||
Studio
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
JasperWorld-Studio
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_MODULE}
|
||||
)
|
||||
|
||||
add_subdirectory(worldobjecteditor)
|
||||
add_subdirectory(worldeditor)
|
35
src/jasper/modules/world/src/studio/studiomodule.cpp
Normal file
35
src/jasper/modules/world/src/studio/studiomodule.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <jasper/world/consts.hpp>
|
||||
|
||||
#include "worldobjecteditor/worldobjecteditor-imgui.hpp"
|
||||
#include "worldeditor/worldeditor-imgui.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class StudioModule: public studio::Module {
|
||||
public:
|
||||
ox::Vector<studio::EditorMaker> editors(turbine::Context &ctx) const noexcept override {
|
||||
return {
|
||||
studio::editorMaker<WorldObjectEditorImGui>(ctx, FileExt_jwob),
|
||||
studio::editorMaker<WorldEditorImGui>(ctx, FileExt_jwld),
|
||||
};
|
||||
}
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> itemMakers(turbine::Context&) const noexcept override {
|
||||
ox::Vector<ox::UPtr<studio::ItemMaker>> out;
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<PrefabDoc>>("World Object", "WorldObjects", FileExt_jwob, ox::ClawFormat::Organic));
|
||||
out.emplace_back(ox::make<studio::ItemMakerT<WorldDoc>>("World", "Worlds", FileExt_jwld, ox::ClawFormat::Organic));
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
static StudioModule const mod;
|
||||
studio::Module const*studioModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
target_sources(
|
||||
JasperWorld-Studio PRIVATE
|
||||
worldeditor-imgui.cpp
|
||||
worldeditor.cpp
|
||||
worldeditorview.cpp
|
||||
)
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include "worldeditor-imgui.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
WorldEditorImGui::WorldEditorImGui(turbine::Context &ctx, ox::StringView path):
|
||||
Editor(path),
|
||||
m_ctx(ctx),
|
||||
m_editor(m_ctx, path),
|
||||
m_view(m_ctx, m_editor.world()) {
|
||||
setRequiresConstantRefresh(false);
|
||||
}
|
||||
|
||||
void WorldEditorImGui::draw(turbine::Context&) noexcept {
|
||||
auto const paneSize = ImGui::GetContentRegionAvail();
|
||||
m_view.draw(ox::Size{static_cast<int>(paneSize.x), static_cast<int>(paneSize.y)});
|
||||
auto &fb = m_view.framebuffer();
|
||||
auto const fbWidth = static_cast<float>(fb.width);
|
||||
auto const fbHeight = static_cast<float>(fb.height);
|
||||
auto const srcH = fbHeight / fbWidth;
|
||||
auto const dstH = paneSize.y / paneSize.x;
|
||||
float xScale{}, yScale{};
|
||||
if (dstH > srcH) {
|
||||
// crop off width
|
||||
xScale = srcH / dstH;
|
||||
yScale = 1;
|
||||
} else {
|
||||
auto const srcW = fbWidth / fbHeight;
|
||||
auto const dstW = (paneSize.x / paneSize.y);
|
||||
xScale = 1;
|
||||
yScale = srcW / dstW;
|
||||
}
|
||||
uintptr_t const buffId = fb.color.id;
|
||||
ImGui::Image(
|
||||
std::bit_cast<void*>(buffId),
|
||||
paneSize,
|
||||
ImVec2(0, 1),
|
||||
ImVec2(xScale, 1 - yScale));
|
||||
}
|
||||
|
||||
void WorldEditorImGui::onActivated() noexcept {
|
||||
oxLogError(m_view.setupWorld());
|
||||
}
|
||||
|
||||
ox::Error WorldEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||
oxReturnError(sctx->project->writeObj(itemPath(), m_editor.world(), ox::ClawFormat::Organic));
|
||||
oxReturnError(keelCtx(m_ctx).assetManager.setAsset(itemPath(), m_editor.world()));
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#include "worldeditor.hpp"
|
||||
#include "worldeditorview.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class WorldEditorImGui: public studio::Editor {
|
||||
|
||||
private:
|
||||
turbine::Context &m_ctx;
|
||||
WorldEditor m_editor;
|
||||
WorldEditorView m_view;
|
||||
|
||||
public:
|
||||
WorldEditorImGui(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
void draw(turbine::Context&) noexcept final;
|
||||
|
||||
void onActivated() noexcept override;
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
|
||||
#include "worldeditor.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
WorldEditor::WorldEditor(turbine::Context &ctx, ox::StringView path):
|
||||
m_ctx(*applicationData<studio::StudioContext>(ctx)),
|
||||
m_world(*readObj<WorldStatic>(keelCtx(ctx), path).unwrapThrow()) {
|
||||
}
|
||||
|
||||
ox::Error WorldEditor::saveItem() noexcept {
|
||||
return m_ctx.project->writeObj(m_itemPath, m_world);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
#include <studio/context.hpp>
|
||||
|
||||
#include <jasper/world/world.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class WorldEditor {
|
||||
|
||||
private:
|
||||
studio::StudioContext &m_ctx;
|
||||
ox::String m_itemPath;
|
||||
WorldStatic m_world;
|
||||
|
||||
public:
|
||||
WorldEditor(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
[[nodiscard]]
|
||||
WorldStatic const&world() const noexcept {
|
||||
return m_world;
|
||||
}
|
||||
|
||||
protected:
|
||||
ox::Error saveItem() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
|
||||
#include "worldeditorview.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
WorldEditorView::WorldEditorView(turbine::Context &tctx, WorldStatic const&worldStatic):
|
||||
m_cctx(ncore::init(tctx, {.glInstallDrawer = false}).unwrapThrow()),
|
||||
m_worldStatic(worldStatic),
|
||||
m_world(m_worldStatic) {
|
||||
}
|
||||
|
||||
ox::Error WorldEditorView::setupWorld() noexcept {
|
||||
glutils::resizeInitFrameBuffer(m_frameBuffer, ncore::gl::drawSize(m_scale));
|
||||
return m_world.setupDisplay(*m_cctx);
|
||||
}
|
||||
|
||||
void WorldEditorView::draw(ox::Size const&targetSz) noexcept {
|
||||
auto const scaleSz = targetSz / ncore::gl::drawSize(1);
|
||||
if (m_scaleSz != scaleSz) [[unlikely]] {
|
||||
m_scale = ox::max(1, ox::max(scaleSz.width, scaleSz.height));
|
||||
glutils::resizeInitFrameBuffer(m_frameBuffer, ncore::gl::drawSize(m_scale));
|
||||
}
|
||||
glutils::FrameBufferBind const frameBufferBind(m_frameBuffer);
|
||||
ncore::gl::draw(*m_cctx, m_scale);
|
||||
}
|
||||
|
||||
glutils::FrameBuffer const&WorldEditorView::framebuffer() const noexcept {
|
||||
return m_frameBuffer;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
|
||||
#include <nostalgia/core/context.hpp>
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <jasper/world/world.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
namespace ncore = nostalgia::core;
|
||||
|
||||
class WorldEditorView {
|
||||
|
||||
private:
|
||||
ncore::ContextUPtr m_cctx;
|
||||
WorldStatic const&m_worldStatic;
|
||||
World m_world;
|
||||
glutils::FrameBuffer m_frameBuffer;
|
||||
int m_scale = 1;
|
||||
ox::Size m_scaleSz = ncore::gl::drawSize(m_scale);
|
||||
|
||||
public:
|
||||
WorldEditorView(turbine::Context &ctx, WorldStatic const&worldStatic);
|
||||
|
||||
ox::Error setupWorld() noexcept;
|
||||
|
||||
void draw(ox::Size const&targetSz) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
glutils::FrameBuffer const&framebuffer() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
target_sources(
|
||||
JasperWorld-Studio PRIVATE
|
||||
worldobjecteditor.cpp
|
||||
worldobjecteditor-imgui.cpp
|
||||
)
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "worldobjecteditor-imgui.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
WorldObjectEditorImGui::WorldObjectEditorImGui(turbine::Context &ctx, ox::StringView path):
|
||||
Editor(path),
|
||||
m_sctx(*applicationData<studio::StudioContext>(ctx)),
|
||||
m_editor(ctx, path) {
|
||||
}
|
||||
|
||||
void WorldObjectEditorImGui::draw(turbine::Context&) noexcept {
|
||||
const auto paneSize = ImGui::GetContentRegionAvail();
|
||||
constexpr auto attrEditorWidth = 400.f;
|
||||
ImGui::BeginChild("Preview", ImVec2(paneSize.x - attrEditorWidth, 0));
|
||||
ImGui::EndChild();
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("AttrEditor", ImVec2(attrEditorWidth, 0), true);
|
||||
drawAttrEditor();
|
||||
drawTileSheetSelector();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void WorldObjectEditorImGui::onActivated() noexcept {
|
||||
}
|
||||
|
||||
void WorldObjectEditorImGui::drawAttrEditor() noexcept {
|
||||
static constexpr auto boundDimension = [](int &v) noexcept {
|
||||
v = ox::clamp(v, 1, 4);
|
||||
};
|
||||
auto &doc = m_editor.doc();
|
||||
ImGui::InputInt("Footprint Width", &doc.footprint.width);
|
||||
ImGui::InputInt("Footprint Height", &doc.footprint.height);
|
||||
ImGui::InputInt("Visible Width", &doc.visibleSz.width);
|
||||
ImGui::InputInt("Visible Height", &doc.visibleSz.height);
|
||||
boundDimension(doc.footprint.width);
|
||||
boundDimension(doc.footprint.height);
|
||||
boundDimension(doc.visibleSz.width);
|
||||
boundDimension(doc.visibleSz.height);
|
||||
}
|
||||
|
||||
void WorldObjectEditorImGui::drawTileSheetSelector() noexcept {
|
||||
auto const&tilesheetList = m_sctx.project->fileList(ncore::FileExt_ng);
|
||||
auto const first = m_selectedTilesheetIdx < tilesheetList.size() ?
|
||||
tilesheetList[m_selectedTilesheetIdx].c_str() : "";
|
||||
if (ImGui::BeginCombo("Tile Sheet", first, 0)) {
|
||||
for (auto i = 0u; i < tilesheetList.size(); ++i) {
|
||||
auto const selected = (m_selectedTilesheetIdx == i);
|
||||
if (ImGui::Selectable(tilesheetList[i].c_str(), selected) &&
|
||||
m_selectedTilesheetIdx != i) {
|
||||
m_selectedTilesheetIdx = i;
|
||||
//oxLogError(m_model.setPalette(tilesheetList[n]));
|
||||
}
|
||||
if (selected) {
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error WorldObjectEditorImGui::saveItem() noexcept {
|
||||
return m_editor.saveItem();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#include "worldobjecteditor.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class WorldObjectEditorImGui: public studio::Editor {
|
||||
|
||||
private:
|
||||
studio::StudioContext &m_sctx;
|
||||
PrefabEditor m_editor;
|
||||
uint_t m_selectedTilesheetIdx{};
|
||||
|
||||
public:
|
||||
WorldObjectEditorImGui(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
void draw(turbine::Context&) noexcept final;
|
||||
|
||||
void onActivated() noexcept override;
|
||||
|
||||
protected:
|
||||
void drawAttrEditor() noexcept;
|
||||
|
||||
void drawTileSheetSelector() noexcept;
|
||||
|
||||
ox::Error saveItem() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include "worldobjecteditor.hpp"
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
PrefabEditor::PrefabEditor(turbine::Context &ctx, ox::StringView path):
|
||||
m_ctx(*applicationData<studio::StudioContext>(ctx)),
|
||||
m_itemPath(path),
|
||||
m_doc(*readObj<PrefabDoc>(keelCtx(ctx), path).unwrapThrow()) {
|
||||
}
|
||||
|
||||
PrefabDoc const&PrefabEditor::doc() const noexcept {
|
||||
return m_doc;
|
||||
}
|
||||
|
||||
PrefabDoc &PrefabEditor::doc() noexcept {
|
||||
return m_doc;
|
||||
}
|
||||
|
||||
ox::Error PrefabEditor::saveItem() noexcept {
|
||||
return m_ctx.project->writeObj(m_itemPath, m_doc, ox::ClawFormat::Organic);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
#include <studio/context.hpp>
|
||||
|
||||
#include <jasper/world/world.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
class PrefabEditor {
|
||||
|
||||
private:
|
||||
studio::StudioContext &m_ctx;
|
||||
ox::String m_itemPath;
|
||||
PrefabDoc m_doc;
|
||||
|
||||
public:
|
||||
PrefabEditor(turbine::Context &ctx, ox::StringView path);
|
||||
|
||||
[[nodiscard]]
|
||||
PrefabDoc const&doc() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
PrefabDoc &doc() noexcept;
|
||||
|
||||
ox::Error saveItem() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
57
src/jasper/modules/world/src/world.cpp
Normal file
57
src/jasper/modules/world/src/world.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
|
||||
#include <jasper/world/world.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
namespace ncore = nostalgia::core;
|
||||
|
||||
World::World(WorldStatic const&worldStatic) noexcept:
|
||||
m_worldStatic(worldStatic) {
|
||||
}
|
||||
|
||||
ox::Error World::setupDisplay(ncore::Context &ctx) const noexcept {
|
||||
if (m_worldStatic.palettes.empty()) {
|
||||
return OxError(1, "World has no palettes");
|
||||
}
|
||||
auto const&palette = m_worldStatic.palettes[0];
|
||||
oxReturnError(ncore::loadBgTileSheet(
|
||||
ctx, 0, m_worldStatic.tilesheet));
|
||||
oxReturnError(ncore::loadBgPalette(ctx, palette));
|
||||
// disable all backgrounds
|
||||
ncore::setBgStatus(ctx, 0);
|
||||
for (auto layerNo = 0u; auto const&layer : m_worldStatic.tileMapIdx) {
|
||||
setupLayer(ctx, layer, layerNo);
|
||||
++layerNo;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void World::setupLayer(
|
||||
ncore::Context &ctx,
|
||||
ox::Vector<uint16_t> const&layer,
|
||||
unsigned layerNo) const noexcept {
|
||||
ncore::setBgStatus(ctx, layerNo, true);
|
||||
ncore::setBgCbb(ctx, layerNo, 0);
|
||||
auto x = 0;
|
||||
auto y = 0;
|
||||
const auto width = m_worldStatic.rows[layerNo];
|
||||
for (auto const&tile : layer) {
|
||||
const auto tile8 = static_cast<uint8_t>(tile);
|
||||
ncore::setBgTile(ctx, layerNo, x, y, tile8);
|
||||
ncore::setBgTile(ctx, layerNo, x + 1, y, tile8 + 1);
|
||||
ncore::setBgTile(ctx, layerNo, x, y + 1, tile8 + 2);
|
||||
ncore::setBgTile(ctx, layerNo, x + 1, y + 1, tile8 + 3);
|
||||
x += 2;
|
||||
if (x >= width * 2) {
|
||||
x = 0;
|
||||
y += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
src/jasper/modules/world/src/worldstatic.cpp
Normal file
11
src/jasper/modules/world/src/worldstatic.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <jasper/world/worldstatic.hpp>
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
|
||||
|
||||
}
|
34
src/jasper/player/CMakeLists.txt
Normal file
34
src/jasper/player/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
add_executable(
|
||||
jasper WIN32 MACOSX_BUNDLE
|
||||
app.cpp
|
||||
)
|
||||
|
||||
if(${BUILDCORE_TARGET} STREQUAL "gba")
|
||||
set(LOAD_KEEL_MODS FALSE)
|
||||
set_target_properties(jasper
|
||||
PROPERTIES
|
||||
LINK_FLAGS ${LINKER_FLAGS}
|
||||
COMPILER_FLAGS "-mthumb -mthumb-interwork"
|
||||
)
|
||||
OBJCOPY_FILE(jasper)
|
||||
else()
|
||||
set(LOAD_KEEL_MODS TRUE)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(
|
||||
jasper PRIVATE
|
||||
OLYMPIC_LOAD_KEEL_MODULES=$<BOOL:${LOAD_KEEL_MODS}>
|
||||
)
|
||||
|
||||
# enable LTO
|
||||
if(NOT WIN32)
|
||||
set_property(TARGET jasper PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
jasper PUBLIC
|
||||
JasperProfile
|
||||
JasperKeelModules
|
||||
OlympicApplib
|
||||
OxLogConn
|
||||
)
|
38
src/jasper/player/app.cpp
Normal file
38
src/jasper/player/app.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <ox/std/array.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include <jasper/core/bootfile.hpp>
|
||||
|
||||
namespace jasper {
|
||||
ox::Error run(turbine::Context &ctx, ox::StringView, ox::SpanView<ox::String>) noexcept {
|
||||
oxOut("Jasper Player\n");
|
||||
oxReturnError(turbine::run(ctx));
|
||||
oxOut("Exiting...\n");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
namespace olympic {
|
||||
|
||||
ox::Error run(
|
||||
[[maybe_unused]] ox::StringView project,
|
||||
[[maybe_unused]] ox::StringView appName,
|
||||
[[maybe_unused]] ox::StringView projectDataDir,
|
||||
[[maybe_unused]] int argc,
|
||||
[[maybe_unused]] char const**argv) noexcept {
|
||||
auto const path = ox::StringView(argv[1]);
|
||||
oxRequireM(fs, keel::loadRomFs(path));
|
||||
oxRequireM(tctx, turbine::init(std::move(fs), project));
|
||||
constexpr ox::FileAddress BootfileAddr = ox::StringLiteral("/Bootfile");
|
||||
oxRequire(bootfile, keel::readObj<jasper::core::Bootfile>(keelCtx(*tctx), BootfileAddr));
|
||||
return jasper::run(*tctx, bootfile->app, bootfile->args);
|
||||
}
|
||||
|
||||
}
|
57
src/jasper/tools/CMakeLists.txt
Normal file
57
src/jasper/tools/CMakeLists.txt
Normal file
@ -0,0 +1,57 @@
|
||||
add_executable(JasperStudio WIN32 MACOSX_BUNDLE)
|
||||
|
||||
target_link_libraries(
|
||||
JasperStudio
|
||||
OlympicApplib
|
||||
JasperStudioModules
|
||||
JasperKeelModules
|
||||
JasperProfile
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
JasperStudio
|
||||
RUNTIME DESTINATION
|
||||
${JASPER_DIST_BIN}
|
||||
BUNDLE DESTINATION .
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
js.icns
|
||||
DESTINATION
|
||||
${JASPER_DIST_RESOURCES}/icons
|
||||
)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT WIN32)
|
||||
# enable LTO
|
||||
set_property(TARGET JasperStudio PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set_target_properties(JasperStudio PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
|
||||
endif()
|
||||
|
||||
# Pack ########################################################################
|
||||
|
||||
add_executable(jasper-pack)
|
||||
|
||||
target_link_libraries(
|
||||
jasper-pack
|
||||
OlympicApplib
|
||||
KeelPack-AppLib
|
||||
JasperKeelModules
|
||||
JasperProfile
|
||||
)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT WIN32)
|
||||
# enable LTO
|
||||
set_property(TARGET jasper-pack PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
jasper-pack
|
||||
RUNTIME DESTINATION
|
||||
bin
|
||||
)
|
35
src/jasper/tools/Info.plist
Normal file
35
src/jasper/tools/Info.plist
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>JasperStudio</string>
|
||||
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>Jasper Studio</string>
|
||||
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icons/js.icns</string>
|
||||
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>net.drinkingtea.jasper.studio</string>
|
||||
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
|
||||
<key>CFBundleVersion</key>
|
||||
<string>d2023.12.0</string>
|
||||
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>12.0.0</string>
|
||||
|
||||
<!-- HiDPI -->
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>True</string>
|
||||
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright (c) 2016-2023 Gary Talent <gary@drinkingtea.net></string>
|
||||
</dict>
|
||||
</plist>
|
BIN
src/jasper/tools/js.icns
Normal file
BIN
src/jasper/tools/js.icns
Normal file
Binary file not shown.
BIN
src/jasper/tools/js_icon480.png
Normal file
BIN
src/jasper/tools/js_icon480.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 327 B |
Reference in New Issue
Block a user