1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
#pragma once
#include "../../Main.h"
#include "JJ2Block.h"
#include "JJ2Event.h"
#include "JJ2Version.h"
#include "EventConverter.h"
#include "../WeatherType.h"
#include <Containers/Function.h>
#include <Containers/SmallVector.h>
#include <Containers/String.h>
#include <Containers/StringView.h>
#include <IO/MemoryStream.h>
using namespace Death::Containers;
using namespace Death::IO;
namespace Jazz2::Compatibility
{
class JJ2Episode;
/** @brief Parses original `.j2l` level files */
class JJ2Level
{
friend class JJ2Episode;
public:
/** @brief Episode name and level name */
struct LevelToken {
/** @brief Episode name */
String Episode;
/** @brief Level name */
String Level;
};
/** @brief Alternate palette */
struct AlternatePalette {
/** @brief Palette name */
String Name;
/** @brief Colors (24-bit) */
std::uint8_t Colors[256 * 3];
};
/** @brief Color mode of tile set */
enum class TilesetColorMode : std::uint8_t {
Original8bit, /**< Original 8-bit palette is used */
Remapped8bit, /**< 8-bit palette is remapped according to @ref PaletteRemapping */
Original24bit, /**< Original 24-bit palette is used */
AlternatePalette24bit /**< Alternate 24-bit palette is used */
};
/** @brief Extra tileset used in the level */
struct ExtraTilesetEntry {
/** @brief Tile set name */
String Name;
/** @brief Offset tile index */
std::uint16_t Offset;
/** @brief Number of tiles */
std::uint16_t Count;
/** @brief Color mode */
TilesetColorMode ColorMode;
union {
/** @brief Palette remapping */
std::uint8_t PaletteRemapping[256];
/** @brief Alternate palette mapping ID for 24-bit */
std::uint8_t AlternatePaletteMappingID24Bit;
};
};
/** @brief Number of layers in the original game */
static constexpr std::int32_t JJ2LayerCount = 8;
/** @brief Number of level text entries in the original game */
static constexpr std::int32_t TextEventStringsCount = 16;
String LevelName;
String DisplayName;
String Tileset;
SmallVector<AlternatePalette, 0> AlternatePalettes;
SmallVector<ExtraTilesetEntry, 0> ExtraTilesets;
String Music;
String NextLevel;
String BonusLevel;
String SecretLevel;
std::uint8_t LightingMin, LightingStart;
JJ2Level() : _version(JJ2Version::Unknown), _animCount(0), _verticalMPSplitscreen(false), _isMpLevel(false), _hasPit(false), _hasPitInstantDeath(false), _hasCTF(false), _hasLaps(false), _useLevelPalette(false) { }
bool Open(StringView path, bool strictParser);
void Convert(StringView targetPath, EventConverter& eventConverter, Function<LevelToken(StringView)>&& levelTokenConversion = {});
void AddLevelTokenTextID(std::uint8_t textId);
/** @brief Returns target version of the level */
JJ2Version GetVersion() const {
return _version;
}
/** @brief Returns maximum number of supported tiles */
std::int32_t GetMaxSupportedTiles() const {
return (_version == JJ2Version::BaseGame ? 1024 : 4096);
}
/** @brief Returns maximum number of supported animations */
std::int32_t GetMaxSupportedAnims() const {
return (_version == JJ2Version::BaseGame ? 128 : 256);
}
private:
enum class LayerSectionSpeedModel {
Normal,
Legacy,
BothSpeeds,
FromStart,
FitLevel,
SpeedMultipliers
};
#ifndef DOXYGEN_GENERATING_OUTPUT
// Doxygen 1.12.0 outputs also private structs/unions even if it shouldn't
struct LayerSection {
std::uint32_t Flags;
std::uint8_t Type; // Ignored
bool Used;
bool Visible;
std::uint8_t DetailLevel; // Ignored
std::int32_t Width;
std::int32_t InternalWidth;
std::int32_t Height;
std::int32_t Depth;
float OffsetX;
float OffsetY;
float SpeedX;
float SpeedY;
float AutoSpeedX;
float AutoSpeedY;
LayerSectionSpeedModel SpeedModelX;
LayerSectionSpeedModel SpeedModelY;
std::uint8_t TexturedBackgroundType;
std::uint8_t TexturedParams1;
std::uint8_t TexturedParams2;
std::uint8_t TexturedParams3;
std::uint8_t SpriteMode;
std::uint8_t SpriteParam;
std::unique_ptr<std::uint16_t[]> Tiles;
};
struct TileEventSection {
JJ2Event EventType;
std::uint8_t GeneratorFlags;
std::uint8_t Difficulty;
bool Illuminate;
std::uint32_t TileParams; // Partially supported
std::int32_t GeneratorDelay;
ConversionResult Converted;
};
struct TilePropertiesSection {
TileEventSection Event;
bool Flipped;
std::uint8_t Type;
};
struct AnimatedTileSection {
std::uint16_t Delay;
std::uint16_t DelayJitter;
std::uint16_t ReverseDelay;
bool IsPingPong;
std::uint8_t Speed;
std::uint8_t FrameCount;
std::uint16_t Frames[64];
};
struct OverridenTileDiffuse {
std::uint16_t TileID;
std::uint8_t Diffuse[32 * 32];
};
struct OverridenTileMask {
std::uint16_t TileID;
std::uint8_t Mask[32 * 32];
};
struct OffGridEvent {
std::uint16_t X;
std::uint16_t Y;
JJ2Event EventType;
std::uint8_t GeneratorFlags;
std::uint8_t Difficulty;
bool Illuminate;
std::uint32_t TileParams; // Partially supported
std::int32_t GeneratorDelay;
ConversionResult Converted;
};
#endif
JJ2Version _version;
std::uint16_t _animCount;
bool _isHidden, _verticalMPSplitscreen, _isMpLevel;
bool _hasPit, _hasPitInstantDeath, _hasCTF, _hasLaps;
std::uint32_t _darknessColor;
WeatherType _weatherType;
std::uint8_t _weatherIntensity;
std::uint16_t _waterLevel;
String _textEventStrings[TextEventStringsCount];
std::uint8_t _levelPalette[256 * 3];
bool _useLevelPalette;
SmallVector<LayerSection, JJ2LayerCount> _layers;
std::unique_ptr<TilePropertiesSection[]> _staticTiles;
std::unique_ptr<AnimatedTileSection[]> _animatedTiles;
SmallVector<OverridenTileDiffuse, 0> _overridenTileDiffuses;
SmallVector<OverridenTileMask, 0> _overridenTileMasks;
std::unique_ptr<TileEventSection[]> _events;
SmallVector<std::uint8_t, TextEventStringsCount> _levelTokenTextIds;
SmallVector<OffGridEvent, 0> _offGridEvents;
void LoadMetadata(JJ2Block& block, bool strictParser);
void LoadStaticTileData(JJ2Block& block, bool strictParser);
void LoadAnimatedTiles(JJ2Block& block, bool strictParser);
void LoadLayerMetadata(JJ2Block& block, bool strictParser);
void LoadEvents(JJ2Block& block, bool strictParser);
void LoadLayers(JJ2Block& dictBlock, std::int32_t dictLength, JJ2Block& layoutBlock, bool strictParser);
void LoadMlleData(JJ2Block& block, std::uint32_t version, StringView path, bool strictParser);
void CheckWaterLevelAroundStart();
static void WriteLevelName(Stream& so, MutableStringView value, Function<LevelToken(StringView)>&& levelTokenConversion = {});
static bool StringHasSuffixIgnoreCase(StringView value, StringView suffix);
};
}
|