mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
7 Commits
5e448453b9
...
1522dea7a4
Author | SHA1 | Date |
---|---|---|
|
1522dea7a4 | |
|
1d38cbafcb | |
|
992d58d799 | |
|
8f34b7a821 | |
|
bf6d0c4934 | |
|
3c4fb21a5e | |
|
bd9d785695 |
|
@ -36,3 +36,8 @@ AITown.FoundTown <- function(tile, size, city, layout, name) { return AITown.Fou
|
||||||
|
|
||||||
AIVehicle.SetNameCompat14 <- AIVehicle.SetName;
|
AIVehicle.SetNameCompat14 <- AIVehicle.SetName;
|
||||||
AIVehicle.SetName <- function(id, name) { return AIVehicle.SetNameCompat14(id, AICompat14.Text(name)); }
|
AIVehicle.SetName <- function(id, name) { return AIVehicle.SetNameCompat14(id, AICompat14.Text(name)); }
|
||||||
|
|
||||||
|
AIBaseStation.IsValidBaseStation <- function(station_id)
|
||||||
|
{
|
||||||
|
return AIStation.IsValidStation(station_id) || AIWaypoint.IsValidWaypoint(station_id);
|
||||||
|
}
|
||||||
|
|
|
@ -81,3 +81,8 @@ GSTown.FoundTown <- function(tile, size, city, layout, name) { return GSTown.Fou
|
||||||
|
|
||||||
GSVehicle.SetNameCompat14 <- GSVehicle.SetName;
|
GSVehicle.SetNameCompat14 <- GSVehicle.SetName;
|
||||||
GSVehicle.SetName <- function(id, name) { return GSVehicle.SetNameCompat14(id, GSCompat14.Text(name)); }
|
GSVehicle.SetName <- function(id, name) { return GSVehicle.SetNameCompat14(id, GSCompat14.Text(name)); }
|
||||||
|
|
||||||
|
GSBaseStation.IsValidBaseStation <- function(station_id)
|
||||||
|
{
|
||||||
|
return GSStation.IsValidStation(station_id) || GSWaypoint.IsValidWaypoint(station_id);
|
||||||
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq
|
||||||
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
||||||
sq_setinstanceup(vm, 2, nullptr);
|
sq_setinstanceup(vm, 2, nullptr);
|
||||||
/* Register the AI to the base system */
|
/* Register the AI to the base system */
|
||||||
info->GetScanner()->RegisterScript(info);
|
info->GetScanner()->RegisterScript(std::unique_ptr<AIInfo>{info});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,22 +136,21 @@ bool AIInfo::CanLoadFromVersion(int version) const
|
||||||
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)
|
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
/* Create a new library */
|
/* Create a new library */
|
||||||
AILibrary *library = new AILibrary();
|
auto library = std::make_unique<AILibrary>();
|
||||||
|
|
||||||
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
delete library;
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cache the category */
|
/* Cache the category */
|
||||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||||
delete library;
|
|
||||||
return SQ_ERROR;
|
return SQ_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register the Library to the base system */
|
/* Register the Library to the base system */
|
||||||
library->GetScanner()->RegisterScript(library);
|
ScriptScanner *scanner = library->GetScanner();
|
||||||
|
scanner->RegisterScript(std::move(library));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ void AIScannerInfo::Initialize()
|
||||||
{
|
{
|
||||||
ScriptScanner::Initialize("AIScanner");
|
ScriptScanner::Initialize("AIScanner");
|
||||||
|
|
||||||
ScriptAllocatorScope alloc_scope(this->engine);
|
ScriptAllocatorScope alloc_scope(this->engine.get());
|
||||||
|
|
||||||
/* Create the dummy AI */
|
/* Create the dummy AI */
|
||||||
this->main_script = "%_dummy";
|
this->main_script = "%_dummy";
|
||||||
|
|
|
@ -22,9 +22,10 @@
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
/** Default heights for the different sizes of fonts. */
|
/** Default unscaled heights for the different sizes of fonts. */
|
||||||
static const int _default_font_height[FS_END] = {10, 6, 18, 10};
|
/* static */ const int FontCache::DEFAULT_FONT_HEIGHT[FS_END] = {10, 6, 18, 10};
|
||||||
static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
|
/** Default unscaled ascenders for the different sizes of fonts. */
|
||||||
|
/* static */ const int FontCache::DEFAULT_FONT_ASCENDER[FS_END] = {8, 5, 15, 8};
|
||||||
|
|
||||||
FontCacheSettings _fcsettings;
|
FontCacheSettings _fcsettings;
|
||||||
|
|
||||||
|
@ -32,8 +33,7 @@ FontCacheSettings _fcsettings;
|
||||||
* Create a new font cache.
|
* Create a new font cache.
|
||||||
* @param fs The size of the font.
|
* @param fs The size of the font.
|
||||||
*/
|
*/
|
||||||
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_default_font_height[fs]),
|
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs)
|
||||||
ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] - _default_font_height[fs])
|
|
||||||
{
|
{
|
||||||
assert(this->parent == nullptr || this->fs == this->parent->fs);
|
assert(this->parent == nullptr || this->fs == this->parent->fs);
|
||||||
FontCache::caches[this->fs] = this;
|
FontCache::caches[this->fs] = this;
|
||||||
|
@ -50,7 +50,7 @@ FontCache::~FontCache()
|
||||||
|
|
||||||
int FontCache::GetDefaultFontHeight(FontSize fs)
|
int FontCache::GetDefaultFontHeight(FontSize fs)
|
||||||
{
|
{
|
||||||
return _default_font_height[fs];
|
return FontCache::DEFAULT_FONT_HEIGHT[fs];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,9 +23,9 @@ protected:
|
||||||
static FontCache *caches[FS_END]; ///< All the font caches.
|
static FontCache *caches[FS_END]; ///< All the font caches.
|
||||||
FontCache *parent; ///< The parent of this font cache.
|
FontCache *parent; ///< The parent of this font cache.
|
||||||
const FontSize fs; ///< The size of the font.
|
const FontSize fs; ///< The size of the font.
|
||||||
int height; ///< The height of the font.
|
int height = 0; ///< The height of the font.
|
||||||
int ascender; ///< The ascender value of the font.
|
int ascender = 0; ///< The ascender value of the font.
|
||||||
int descender; ///< The descender value of the font.
|
int descender = 0; ///< The descender value of the font.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FontCache(FontSize fs);
|
FontCache(FontSize fs);
|
||||||
|
@ -33,6 +33,11 @@ public:
|
||||||
|
|
||||||
static void InitializeFontCaches();
|
static void InitializeFontCaches();
|
||||||
|
|
||||||
|
/** Default unscaled font heights. */
|
||||||
|
static const int DEFAULT_FONT_HEIGHT[FS_END];
|
||||||
|
/** Default unscaled font ascenders. */
|
||||||
|
static const int DEFAULT_FONT_ASCENDER[FS_END];
|
||||||
|
|
||||||
static int GetDefaultFontHeight(FontSize fs);
|
static int GetDefaultFontHeight(FontSize fs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,7 +78,7 @@ template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) {
|
||||||
/* Remove the link to the real instance, else it might get deleted by RegisterGame() */
|
/* Remove the link to the real instance, else it might get deleted by RegisterGame() */
|
||||||
sq_setinstanceup(vm, 2, nullptr);
|
sq_setinstanceup(vm, 2, nullptr);
|
||||||
/* Register the Game to the base system */
|
/* Register the Game to the base system */
|
||||||
info->GetScanner()->RegisterScript(info);
|
info->GetScanner()->RegisterScript(std::unique_ptr<GameInfo>{info});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,22 +106,21 @@ bool GameInfo::CanLoadFromVersion(int version) const
|
||||||
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)
|
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
/* Create a new library */
|
/* Create a new library */
|
||||||
GameLibrary *library = new GameLibrary();
|
auto library = std::make_unique<GameLibrary>();
|
||||||
|
|
||||||
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
delete library;
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cache the category */
|
/* Cache the category */
|
||||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||||
delete library;
|
|
||||||
return SQ_ERROR;
|
return SQ_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register the Library to the base system */
|
/* Register the Library to the base system */
|
||||||
library->GetScanner()->RegisterScript(library);
|
ScriptScanner *scanner = library->GetScanner();
|
||||||
|
scanner->RegisterScript(std::move(library));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,8 +92,8 @@ GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int ver
|
||||||
std::string library_name = fmt::format("{}.{}", library, version);
|
std::string library_name = fmt::format("{}.{}", library, version);
|
||||||
|
|
||||||
/* Check if the library + version exists */
|
/* Check if the library + version exists */
|
||||||
ScriptInfoList::iterator it = this->info_list.find(library_name);
|
auto it = this->info_list.find(library_name);
|
||||||
if (it == this->info_list.end()) return nullptr;
|
if (it == this->info_list.end()) return nullptr;
|
||||||
|
|
||||||
return static_cast<GameLibrary *>((*it).second);
|
return static_cast<GameLibrary *>(it->second);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
* \li AICargo::CC_NON_POTABLE
|
* \li AICargo::CC_NON_POTABLE
|
||||||
* \li AIVehicleList_Waypoint
|
* \li AIVehicleList_Waypoint
|
||||||
*
|
*
|
||||||
|
* API removals:
|
||||||
|
* \li AIBaseStation::IsValidBaseStation, use AIStation::IsValidStation or AIWaypoint::IsValidWaypoint instead
|
||||||
|
*
|
||||||
* Other changes:
|
* Other changes:
|
||||||
* \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType
|
* \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType
|
||||||
* \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
* \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
* \li GSVehicleList_Waypoint
|
* \li GSVehicleList_Waypoint
|
||||||
* \li GSBaseStation::GetOwner
|
* \li GSBaseStation::GetOwner
|
||||||
*
|
*
|
||||||
|
* API removals:
|
||||||
|
* \li GSBaseStation::IsValidBaseStation, use GSStation::IsValidStation or GSWaypoint::IsValidWaypoint instead
|
||||||
|
*
|
||||||
* Other changes:
|
* Other changes:
|
||||||
* \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType
|
* \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType
|
||||||
* \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
* \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
||||||
|
|
|
@ -21,15 +21,16 @@
|
||||||
*/
|
*/
|
||||||
class ScriptBaseStation : public ScriptObject {
|
class ScriptBaseStation : public ScriptObject {
|
||||||
public:
|
public:
|
||||||
static constexpr StationID STATION_NEW = ::NEW_STATION; ///< Build a new station
|
static constexpr StationID STATION_NEW = ::NEW_STATION; ///< Build a new station or waypoint
|
||||||
static constexpr StationID STATION_JOIN_ADJACENT = ::ADJACENT_STATION; ///< Join an neighbouring station if one exists
|
static constexpr StationID STATION_JOIN_ADJACENT = ::ADJACENT_STATION; ///< Join a neighbouring station or waypoint if one exists
|
||||||
static constexpr StationID STATION_INVALID = ::StationID::Invalid(); ///< Invalid station id.
|
static constexpr StationID STATION_INVALID = ::StationID::Invalid(); ///< Invalid station or waypoint id.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given basestation is valid and owned by you.
|
* Checks whether the given basestation is valid and owned by you.
|
||||||
* @param station_id The station to check.
|
* @param station_id The station to check.
|
||||||
* @return True if and only if the basestation is valid.
|
* @return True if and only if the basestation is valid.
|
||||||
* @note IsValidBaseStation == (IsValidStation || IsValidWaypoint).
|
* @note IsValidBaseStation == (IsValidStation || IsValidWaypoint).
|
||||||
|
* @api -all
|
||||||
*/
|
*/
|
||||||
static bool IsValidBaseStation(StationID station_id);
|
static bool IsValidBaseStation(StationID station_id);
|
||||||
|
|
||||||
|
@ -43,18 +44,18 @@ public:
|
||||||
static ScriptCompany::CompanyID GetOwner(StationID station_id);
|
static ScriptCompany::CompanyID GetOwner(StationID station_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of a basestation.
|
* Get the name of a station or waypoint.
|
||||||
* @param station_id The basestation to get the name of.
|
* @param station_id The station or waypoint to get the name of.
|
||||||
* @pre IsValidBaseStation(station_id).
|
* @pre IsValidStation(station_id) || IsValidWaypoint(station_id).
|
||||||
* @return The name of the station.
|
* @return The name of the station or waypoint.
|
||||||
*/
|
*/
|
||||||
static std::optional<std::string> GetName(StationID station_id);
|
static std::optional<std::string> GetName(StationID station_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name this basestation.
|
* Set the name of a station or waypoint.
|
||||||
* @param station_id The basestation to set the name of.
|
* @param station_id The station or waypoint to set the name of.
|
||||||
* @param name The new name of the station (can be either a raw string, or a ScriptText object).
|
* @param name The new name of the station or waypoint (can be either a raw string, or a ScriptText object).
|
||||||
* @pre IsValidBaseStation(station_id).
|
* @pre IsValidStation(station_id) || IsValidWaypoint(station_id).
|
||||||
* @pre name != null && len(name) != 0.
|
* @pre name != null && len(name) != 0.
|
||||||
* @game @pre ScriptCompanyMode::IsValid().
|
* @game @pre ScriptCompanyMode::IsValid().
|
||||||
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
|
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
|
||||||
|
@ -63,19 +64,19 @@ public:
|
||||||
static bool SetName(StationID station_id, Text *name);
|
static bool SetName(StationID station_id, Text *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current location of a basestation.
|
* Get the current location of a station or waypoint.
|
||||||
* @param station_id The basestation to get the location of.
|
* @param station_id The station or waypoint to get the location of.
|
||||||
* @pre IsValidBaseStation(station_id).
|
* @pre IsValidStation(station_id) || IsValidWaypoint(station_id).
|
||||||
* @return The tile the basestation sign above it.
|
* @return The tile with the station or waypoint sign above it.
|
||||||
* @note The tile is not necessarily a station tile (and if it is, it could also belong to another station).
|
* @note The tile is not necessarily a station or waypoint tile (and if it is, it could also belong to another station or waypoint).
|
||||||
* @see ScriptTileList_StationType.
|
* @see ScriptTileList_StationType.
|
||||||
*/
|
*/
|
||||||
static TileIndex GetLocation(StationID station_id);
|
static TileIndex GetLocation(StationID station_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the last calendar-date a station part was added to this station.
|
* Get the last calendar-date a station or waypoint part was added to this station or waypoint.
|
||||||
* @param station_id The station to look at.
|
* @param station_id The station or waypoint to look at.
|
||||||
* @return The last calendar-date some part of this station was build.
|
* @return The last calendar-date some part of this station or waypoint was built.
|
||||||
* @see \ref ScriptCalendarTime
|
* @see \ref ScriptCalendarTime
|
||||||
*/
|
*/
|
||||||
static ScriptDate::Date GetConstructionDate(StationID station_id);
|
static ScriptDate::Date GetConstructionDate(StationID station_id);
|
||||||
|
|
|
@ -44,10 +44,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t, const std::stri
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptScanner::ScriptScanner() :
|
ScriptScanner::ScriptScanner() = default;
|
||||||
engine(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptScanner::ResetEngine()
|
void ScriptScanner::ResetEngine()
|
||||||
{
|
{
|
||||||
|
@ -58,7 +55,7 @@ void ScriptScanner::ResetEngine()
|
||||||
|
|
||||||
void ScriptScanner::Initialize(std::string_view name)
|
void ScriptScanner::Initialize(std::string_view name)
|
||||||
{
|
{
|
||||||
this->engine = new Squirrel(name);
|
this->engine = std::make_unique<Squirrel>(name);
|
||||||
|
|
||||||
this->RescanDir();
|
this->RescanDir();
|
||||||
|
|
||||||
|
@ -68,8 +65,6 @@ void ScriptScanner::Initialize(std::string_view name)
|
||||||
ScriptScanner::~ScriptScanner()
|
ScriptScanner::~ScriptScanner()
|
||||||
{
|
{
|
||||||
this->Reset();
|
this->Reset();
|
||||||
|
|
||||||
delete this->engine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptScanner::RescanDir()
|
void ScriptScanner::RescanDir()
|
||||||
|
@ -83,15 +78,12 @@ void ScriptScanner::RescanDir()
|
||||||
|
|
||||||
void ScriptScanner::Reset()
|
void ScriptScanner::Reset()
|
||||||
{
|
{
|
||||||
for (const auto &item : this->info_list) {
|
|
||||||
delete item.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->info_list.clear();
|
this->info_list.clear();
|
||||||
this->info_single_list.clear();
|
this->info_single_list.clear();
|
||||||
|
this->info_vector.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptScanner::RegisterScript(ScriptInfo *info)
|
void ScriptScanner::RegisterScript(std::unique_ptr<ScriptInfo> &&info)
|
||||||
{
|
{
|
||||||
std::string script_original_name = this->GetScriptName(*info);
|
std::string script_original_name = this->GetScriptName(*info);
|
||||||
std::string script_name = fmt::format("{}.{}", script_original_name, info->GetVersion());
|
std::string script_name = fmt::format("{}.{}", script_original_name, info->GetVersion());
|
||||||
|
@ -99,7 +91,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||||
/* Check if GetShortName follows the rules */
|
/* Check if GetShortName follows the rules */
|
||||||
if (info->GetShortName().size() != 4) {
|
if (info->GetShortName().size() != 4) {
|
||||||
Debug(script, 0, "The script '{}' returned a string from GetShortName() which is not four characters. Unable to load the script.", info->GetName());
|
Debug(script, 0, "The script '{}' returned a string from GetShortName() which is not four characters. Unable to load the script.", info->GetName());
|
||||||
delete info;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +102,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||||
#else
|
#else
|
||||||
if (it->second->GetMainScript() == info->GetMainScript()) {
|
if (it->second->GetMainScript() == info->GetMainScript()) {
|
||||||
#endif
|
#endif
|
||||||
delete info;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,20 +110,20 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||||
Debug(script, 1, " 2: {}", info->GetMainScript());
|
Debug(script, 1, " 2: {}", info->GetMainScript());
|
||||||
Debug(script, 1, "The first is taking precedence.");
|
Debug(script, 1, "The first is taking precedence.");
|
||||||
|
|
||||||
delete info;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->info_list[script_name] = info;
|
ScriptInfo *script_info = this->info_vector.emplace_back(std::move(info)).get();
|
||||||
|
this->info_list[script_name] = script_info;
|
||||||
|
|
||||||
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
if (!script_info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
||||||
/* Add the script to the 'unique' script list, where only the highest version
|
/* Add the script to the 'unique' script list, where only the highest version
|
||||||
* of the script is registered. */
|
* of the script is registered. */
|
||||||
auto it = this->info_single_list.find(script_original_name);
|
auto it = this->info_single_list.find(script_original_name);
|
||||||
if (it == this->info_single_list.end()) {
|
if (it == this->info_single_list.end()) {
|
||||||
this->info_single_list[script_original_name] = info;
|
this->info_single_list[script_original_name] = script_info;
|
||||||
} else if (it->second->GetVersion() < info->GetVersion()) {
|
} else if (it->second->GetVersion() < script_info->GetVersion()) {
|
||||||
it->second = info;
|
it->second = script_info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,17 +185,17 @@ struct ScriptFileChecksumCreator : FileScanner {
|
||||||
* @param info The script to get the shortname and md5 sum from.
|
* @param info The script to get the shortname and md5 sum from.
|
||||||
* @return True iff they're the same.
|
* @return True iff they're the same.
|
||||||
*/
|
*/
|
||||||
static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, Subdirectory dir)
|
static bool IsSameScript(const ContentInfo &ci, bool md5sum, const ScriptInfo &info, Subdirectory dir)
|
||||||
{
|
{
|
||||||
uint32_t id = 0;
|
uint32_t id = 0;
|
||||||
auto str = std::string_view{info->GetShortName()}.substr(0, 4);
|
auto str = std::string_view{info.GetShortName()}.substr(0, 4);
|
||||||
for (size_t j = 0; j < str.size(); j++) id |= static_cast<uint8_t>(str[j]) << (8 * j);
|
for (size_t j = 0; j < str.size(); j++) id |= static_cast<uint8_t>(str[j]) << (8 * j);
|
||||||
|
|
||||||
if (id != ci.unique_id) return false;
|
if (id != ci.unique_id) return false;
|
||||||
if (!md5sum) return true;
|
if (!md5sum) return true;
|
||||||
|
|
||||||
ScriptFileChecksumCreator checksum(dir);
|
ScriptFileChecksumCreator checksum(dir);
|
||||||
const auto &tar_filename = info->GetTarFile();
|
const auto &tar_filename = info.GetTarFile();
|
||||||
TarList::iterator iter;
|
TarList::iterator iter;
|
||||||
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
|
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
|
||||||
/* The main script is in a tar file, so find all files that
|
/* The main script is in a tar file, so find all files that
|
||||||
|
@ -224,7 +214,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
|
||||||
/* There'll always be at least 1 path separator character in a script
|
/* There'll always be at least 1 path separator character in a script
|
||||||
* main script name as the search algorithm requires the main script to
|
* main script name as the search algorithm requires the main script to
|
||||||
* be in a subdirectory of the script directory; so <dir>/<path>/main.nut. */
|
* be in a subdirectory of the script directory; so <dir>/<path>/main.nut. */
|
||||||
const std::string &main_script = info->GetMainScript();
|
const std::string &main_script = info.GetMainScript();
|
||||||
std::string path = main_script.substr(0, main_script.find_last_of(PATHSEPCHAR));
|
std::string path = main_script.substr(0, main_script.find_last_of(PATHSEPCHAR));
|
||||||
checksum.Scan(".nut", path);
|
checksum.Scan(".nut", path);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +225,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
|
||||||
bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
||||||
{
|
{
|
||||||
for (const auto &item : this->info_list) {
|
for (const auto &item : this->info_list) {
|
||||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true;
|
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +233,7 @@ bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
||||||
std::optional<std::string_view> ScriptScanner::FindMainScript(const ContentInfo &ci, bool md5sum)
|
std::optional<std::string_view> ScriptScanner::FindMainScript(const ContentInfo &ci, bool md5sum)
|
||||||
{
|
{
|
||||||
for (const auto &item : this->info_list) {
|
for (const auto &item : this->info_list) {
|
||||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript();
|
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return item.second->GetMainScript();
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "../fileio_func.h"
|
#include "../fileio_func.h"
|
||||||
#include "../string_func.h"
|
#include "../string_func.h"
|
||||||
|
|
||||||
typedef std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator> ScriptInfoList; ///< Type for the list of scripts.
|
using ScriptInfoList = std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator>; ///< Type for the list of scripts.
|
||||||
|
|
||||||
/** Scanner to help finding scripts. */
|
/** Scanner to help finding scripts. */
|
||||||
class ScriptScanner : public FileScanner {
|
class ScriptScanner : public FileScanner {
|
||||||
|
@ -26,7 +26,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the engine of the main squirrel handler (it indexes all available scripts).
|
* Get the engine of the main squirrel handler (it indexes all available scripts).
|
||||||
*/
|
*/
|
||||||
class Squirrel *GetEngine() { return this->engine; }
|
class Squirrel *GetEngine() { return this->engine.get(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current main script the ScanDir is currently tracking.
|
* Get the current main script the ScanDir is currently tracking.
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Register a ScriptInfo to the scanner.
|
* Register a ScriptInfo to the scanner.
|
||||||
*/
|
*/
|
||||||
void RegisterScript(class ScriptInfo *info);
|
void RegisterScript(std::unique_ptr<class ScriptInfo> &&info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of registered scripts to print on the console.
|
* Get the list of registered scripts to print on the console.
|
||||||
|
@ -84,10 +84,12 @@ public:
|
||||||
void RescanDir();
|
void RescanDir();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
class Squirrel *engine; ///< The engine we're scanning with.
|
std::unique_ptr<class Squirrel> engine; ///< The engine we're scanning with.
|
||||||
std::string main_script; ///< The full path of the script.
|
std::string main_script; ///< The full path of the script.
|
||||||
std::string tar_file; ///< If, which tar file the script was in.
|
std::string tar_file; ///< If, which tar file the script was in.
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<ScriptInfo>> info_vector;
|
||||||
|
|
||||||
ScriptInfoList info_list; ///< The list of all script.
|
ScriptInfoList info_list; ///< The list of all script.
|
||||||
ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.
|
ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.
|
||||||
|
|
||||||
|
|
|
@ -401,6 +401,40 @@ static void CancelIMEComposition(HWND hwnd)
|
||||||
HandleTextInput({}, true);
|
HandleTextInput({}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
|
||||||
|
/* We only use WinRT functions on Windows 10 or later. Unfortunately, newer Windows SDKs are now
|
||||||
|
* linking the two functions below directly instead of using dynamic linking as previously.
|
||||||
|
* To avoid any runtime linking errors on Windows 7 or older, we stub in our own dynamic
|
||||||
|
* linking trampoline. */
|
||||||
|
|
||||||
|
static LibraryLoader _combase("combase.dll");
|
||||||
|
|
||||||
|
extern "C" int32_t __stdcall WINRT_IMPL_RoOriginateLanguageException(int32_t error, void *message, void *languageException) noexcept
|
||||||
|
{
|
||||||
|
typedef BOOL(WINAPI *PFNRoOriginateLanguageException)(int32_t, void *, void *);
|
||||||
|
static PFNRoOriginateLanguageException RoOriginateLanguageException = _combase.GetFunction("RoOriginateLanguageException");
|
||||||
|
|
||||||
|
if (RoOriginateLanguageException != nullptr) {
|
||||||
|
return RoOriginateLanguageException(error, message, languageException);
|
||||||
|
} else {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int32_t __stdcall WINRT_IMPL_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept
|
||||||
|
{
|
||||||
|
typedef BOOL(WINAPI *PFNRoGetActivationFactory)(void *, winrt::guid const &, void **);
|
||||||
|
static PFNRoGetActivationFactory RoGetActivationFactory = _combase.GetFunction("RoGetActivationFactory");
|
||||||
|
|
||||||
|
if (RoGetActivationFactory != nullptr) {
|
||||||
|
return RoGetActivationFactory(classId, iid, factory);
|
||||||
|
} else {
|
||||||
|
*factory = nullptr;
|
||||||
|
return winrt::impl::error_class_not_available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool IsDarkModeEnabled()
|
static bool IsDarkModeEnabled()
|
||||||
{
|
{
|
||||||
/* Only build if SDK is Windows 10 1803 or later. */
|
/* Only build if SDK is Windows 10 1803 or later. */
|
||||||
|
|
Loading…
Reference in New Issue