mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
4 Commits
1973ce6312
...
ff77ad385e
Author | SHA1 | Date |
---|---|---|
|
ff77ad385e | |
|
7546c1acab | |
|
a6143eea21 | |
|
41d497f36a |
|
@ -36,3 +36,11 @@ 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)); }
|
||||||
|
|
||||||
|
AIObject.constructorCompat14 <- AIObject.constructor;
|
||||||
|
foreach(name, object in CompatScriptRootTable) {
|
||||||
|
if (type(object) != "class") continue;
|
||||||
|
if (!object.rawin("constructor")) continue;
|
||||||
|
if (object.constructor != AIObject.constructorCompat14) continue;
|
||||||
|
object.constructor <- function() : (name) { AILog.Error("'" + name + "' is not instantiable"); }
|
||||||
|
}
|
||||||
|
|
|
@ -81,3 +81,11 @@ 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)); }
|
||||||
|
|
||||||
|
GSObject.constructorCompat14 <- GSObject.constructor;
|
||||||
|
foreach(name, object in CompatScriptRootTable) {
|
||||||
|
if (type(object) != "class") continue;
|
||||||
|
if (!object.rawin("constructor")) continue;
|
||||||
|
if (object.constructor != GSObject.constructorCompat14) continue;
|
||||||
|
object.constructor <- function() : (name) { GSLog.Error("'" + name + "' is not instantiable"); }
|
||||||
|
}
|
||||||
|
|
|
@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get SpriteID associated with a GlyphID.
|
* Get SpriteID associated with a character.
|
||||||
* @param key Glyph to find.
|
* @param key Character to find.
|
||||||
* @return SpriteID of glyph, or 0 if not present.
|
* @return SpriteID for character, or 0 if not present.
|
||||||
*/
|
*/
|
||||||
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key)
|
SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
|
||||||
{
|
{
|
||||||
const auto found = this->glyph_to_spriteid_map.find(key & ~SPRITE_GLYPH);
|
const auto found = this->char_map.find(key);
|
||||||
if (found == std::end(this->glyph_to_spriteid_map)) return 0;
|
if (found == std::end(this->char_map)) return 0;
|
||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
|
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
|
||||||
{
|
{
|
||||||
this->glyph_to_spriteid_map[key] = sprite;
|
this->char_map[key] = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteFontCache::InitializeUnicodeGlyphMap()
|
void SpriteFontCache::InitializeUnicodeGlyphMap()
|
||||||
{
|
{
|
||||||
/* Clear out existing glyph map if it exists */
|
/* Clear out existing glyph map if it exists */
|
||||||
this->glyph_to_spriteid_map.clear();
|
this->char_map.clear();
|
||||||
|
|
||||||
SpriteID base;
|
SpriteID base;
|
||||||
switch (this->fs) {
|
switch (this->fs) {
|
||||||
|
|
|
@ -28,8 +28,8 @@ public:
|
||||||
bool IsBuiltInFont() override { return true; }
|
bool IsBuiltInFont() override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs.
|
std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
|
||||||
SpriteID GetUnicodeGlyph(GlyphID key);
|
SpriteID GetUnicodeGlyph(char32_t key);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPRITEFONTCACHE_H */
|
#endif /* SPRITEFONTCACHE_H */
|
||||||
|
|
|
@ -24,10 +24,12 @@
|
||||||
#include "api/script_event.hpp"
|
#include "api/script_event.hpp"
|
||||||
#include "api/script_log.hpp"
|
#include "api/script_log.hpp"
|
||||||
|
|
||||||
#include "../company_base.h"
|
#include "../company_type.h"
|
||||||
#include "../company_func.h"
|
|
||||||
#include "../fileio_func.h"
|
#include "../fileio_func.h"
|
||||||
|
#include "../goal_type.h"
|
||||||
#include "../league_type.h"
|
#include "../league_type.h"
|
||||||
|
#include "../signs_type.h"
|
||||||
|
#include "../story_type.h"
|
||||||
#include "../misc/endian_buffer.hpp"
|
#include "../misc/endian_buffer.hpp"
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
@ -128,6 +130,13 @@ bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::span<const
|
||||||
|
|
||||||
ScriptLog::Info(fmt::format("Downgrading API to be compatible with version {}", this->api_version));
|
ScriptLog::Info(fmt::format("Downgrading API to be compatible with version {}", this->api_version));
|
||||||
|
|
||||||
|
HSQUIRRELVM vm = this->engine->GetVM();
|
||||||
|
sq_pushroottable(vm);
|
||||||
|
sq_pushstring(vm, "CompatScriptRootTable");
|
||||||
|
sq_pushroottable(vm);
|
||||||
|
sq_newslot(vm, -3, SQFalse);
|
||||||
|
sq_pop(vm, 1);
|
||||||
|
|
||||||
/* Downgrade the API till we are the same version as the script. The last
|
/* Downgrade the API till we are the same version as the script. The last
|
||||||
* entry in the list is always the current version, so skip that one. */
|
* entry in the list is always the current version, so skip that one. */
|
||||||
for (auto it = std::rbegin(api_versions) + 1; it != std::rend(api_versions); ++it) {
|
for (auto it = std::rbegin(api_versions) + 1; it != std::rend(api_versions); ++it) {
|
||||||
|
@ -136,6 +145,11 @@ bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::span<const
|
||||||
if (*it == this->api_version) break;
|
if (*it == this->api_version) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sq_pushroottable(vm);
|
||||||
|
sq_pushstring(vm, "CompatScriptRootTable");
|
||||||
|
sq_deleteslot(vm, -2, SQFalse);
|
||||||
|
sq_pop(vm, 1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,10 @@
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include "../signs_func.h"
|
#include "../command_type.h"
|
||||||
#include "../vehicle_func.h"
|
#include "../company_type.h"
|
||||||
|
#include "../rail_type.h"
|
||||||
#include "../road_type.h"
|
#include "../road_type.h"
|
||||||
#include "../group.h"
|
|
||||||
#include "../goal_type.h"
|
|
||||||
#include "../story_type.h"
|
|
||||||
|
|
||||||
#include "script_types.hpp"
|
#include "script_types.hpp"
|
||||||
#include "script_log_types.hpp"
|
#include "script_log_types.hpp"
|
||||||
|
|
Loading…
Reference in New Issue