Skip to content
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
22 changes: 22 additions & 0 deletions data/styles/mobile/10-buttons.otui
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Button < UIButton
font: verdana-11px-antialised
color: #dfdfdfff
size: 146 63
text-offset: 0 0
image-source: /images/ui/button
image-color: #dfdfdf
image-clip: 0 0 22 23
image-border: 3
padding: 5 10 5 10
opacity: 1.0

$hover !disabled:
image-clip: 0 23 22 23

$pressed:
image-clip: 0 46 22 23
text-offset: 1 1

$disabled:
color: #dfdfdf88
opacity: 0.8
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ g_game.setLastSupportedVersion(1291)
-- setup logger
g_logger.setLogFile(g_resources.getWorkDir() .. g_app.getCompactName() .. '.log')
g_logger.info(os.date('== application started at %b %d %Y %X'))
g_logger.info("== operating system: " .. g_platform.getOSName())

-- print first terminal message
g_logger.info(g_app.getName() .. ' ' .. g_app.getVersion() .. ' rev ' .. g_app.getBuildRevision() .. ' (' ..
Expand Down
3 changes: 3 additions & 0 deletions modules/client_entergame/entergame.mobile.otui
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EnterGameWindow < MainWindow
!text: tr('Mobile: Enter Game')
size: 436 498
53 changes: 33 additions & 20 deletions modules/client_styles/styles.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
local resourceLoaders = {
["otui"] = g_ui.importStyle,
["otfont"] = g_fonts.importFont,
["otps"] = g_particles.importParticle,
}

function init()
local files
files = g_resources.listDirectoryFiles('/styles')
for _, file in pairs(files) do
if g_resources.isFileType(file, 'otui') then
g_ui.importStyle('/styles/' .. file)
end
end
local device = g_platform.getDevice()
importResources("styles", "otui", device)
importResources("fonts", "otfont", device)
importResources("particles", "otps", device)

g_mouse.loadCursors('/cursors/cursors')
end

files = g_resources.listDirectoryFiles('/fonts')
for _, file in pairs(files) do
if g_resources.isFileType(file, 'otfont') then
g_fonts.importFont('/fonts/' .. file)
function terminate()
end

function importResources(dir, type, device)
local path = '/'..dir..'/'
local files = g_resources.listDirectoryFiles(path)
for _,file in pairs(files) do
if g_resources.isFileType(file, type) then
resourceLoaders[type](path .. file)
end
end

files = g_resources.listDirectoryFiles('/particles')
for _, file in pairs(files) do
if g_resources.isFileType(file, 'otps') then
g_particles.importParticle('/particles/' .. file)
-- try load device specific resources
if device then
local devicePath = g_platform.getDeviceShortName(device.type)
if devicePath ~= "" then
table.insertall(files, importResources(dir..'/'..devicePath, type))
end
local osPath = g_platform.getOsShortName(device.os)
if osPath ~= "" then
table.insertall(files, importResources(dir..'/'..osPath, type))
end
return
end

g_mouse.loadCursors('/cursors/cursors')
end

function terminate()
return files
end
23 changes: 18 additions & 5 deletions modules/corelib/const.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
-- @docconsts @{
OsUnknown = 0
OsWindows = 1
OsLinux = 2
OsMacOS = 3
OsAndroid = 4
OsiOS = 5

DeviceUnknown = 0
DeviceDesktop = 1
DeviceMobile = 2
DeviceConsole = 3

AnchorNone = 0
AnchorTop = 1
AnchorBottom = 2
Expand All @@ -7,11 +19,12 @@ AnchorRight = 4
AnchorVerticalCenter = 5
AnchorHorizontalCenter = 6

LogDebug = 0
LogInfo = 1
LogWarning = 2
LogError = 3
LogFatal = 4
LogFine = 0
LogDebug = 1
LogInfo = 2
LogWarning = 3
LogError = 4
LogFatal = 5

MouseFocusReason = 0
KeyboardFocusReason = 1
Expand Down
7 changes: 7 additions & 0 deletions modules/corelib/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ function table.collect(t, func)
return res
end

function table.insertall(t, s)
for k,v in pairs(s) do
table.insert(t,v)
end
return res
end

function table.equals(t, comp)
if type(t) == 'table' and type(comp) == 'table' then
for k, v in pairs(t) do
Expand Down
3 changes: 2 additions & 1 deletion src/framework/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ namespace Fw

enum LogLevel : uint8_t
{
LogDebug = 0,
LogFine = 0,
LogDebug,
LogInfo,
LogWarning,
LogError,
Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void Application::init(std::vector<std::string>& args)
std::locale::global(std::locale());

// process args encoding
g_platform.processArgs(args);
g_platform.init(args);

g_asyncDispatcher.init();

Expand Down
5 changes: 4 additions & 1 deletion src/framework/core/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ void Logger::log(Fw::LogLevel level, const std::string_view message)
std::scoped_lock lock(m_mutex);

#ifdef NDEBUG
if (level == Fw::LogDebug)
if (level == Fw::LogDebug || level == Fw::LogFine)
return;
#endif

if (level < m_level)
return;

if (s_ignoreLogs)
return;

Expand Down
4 changes: 4 additions & 0 deletions src/framework/core/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Logger
void log(Fw::LogLevel level, const std::string_view message);
void logFunc(Fw::LogLevel level, const std::string_view message, const std::string_view prettyFunction);

void fine(const std::string_view what) { log(Fw::LogFine, what); }
void debug(const std::string_view what) { log(Fw::LogDebug, what); }
void info(const std::string_view what) { log(Fw::LogInfo, what); }
void warning(const std::string_view what) { log(Fw::LogWarning, what); }
Expand All @@ -58,12 +59,15 @@ class Logger
void fireOldMessages();
void setLogFile(const std::string_view file);
void setOnLog(const OnLogCallback& onLog) { m_onLog = onLog; }
void setLevel(Fw::LogLevel level) { m_level = level; }
Fw::LogLevel getLevel() { return m_level; }

private:
std::deque<LogMessage> m_logMessages;
OnLogCallback m_onLog;
std::ofstream m_outFile;
std::recursive_mutex m_mutex;
Fw::LogLevel m_level{ Fw::LogInfo };
};

extern Logger g_logger;
Expand Down
27 changes: 27 additions & 0 deletions src/framework/core/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ bool Module::load()
if (m_loaded || !m_enabled)
return true;

if (!m_supportedDevices.empty() && !hasSupportedDevice(g_platform.getDevice()))
return true;

try {
// add to package.loaded
g_lua.getGlobalField("package", "loaded");
Expand Down Expand Up @@ -177,6 +180,17 @@ bool Module::hasDependency(const std::string_view name, bool recursive)
return false;
}

bool Module::hasSupportedDevice(Platform::Device device)
{
for (const auto& sd : m_supportedDevices) {
if (sd.type == device.type || sd.type == Platform::DeviceUnknown) {
if (sd.os == device.os || sd.os == Platform::OsUnknown)
return true;
}
}
return false;
}

int Module::getSandbox(LuaInterface* lua)
{
lua->getRef(m_sandboxEnv);
Expand All @@ -196,6 +210,19 @@ void Module::discover(const OTMLNodePtr& moduleNode)
m_sandboxed = moduleNode->valueAt<bool>("sandboxed", false);
m_autoLoadPriority = moduleNode->valueAt<int>("autoload-priority", 9999);

if (const auto& node = moduleNode->get("devices")) {
for (const auto& tmp : node->children()) {
auto deviceInfo = stdext::split(tmp->value(), ":");
if (deviceInfo.empty())
continue;

auto device = Platform::Device();
device.type = Platform::getDeviceTypeByName(deviceInfo.at(0));
if (deviceInfo.size() > 1) device.os = Platform::getOsByName(deviceInfo.at(1));
m_supportedDevices.emplace_back(device);
}
}

if (const auto& node = moduleNode->get("dependencies")) {
for (const auto& tmp : node->children())
m_dependencies.emplace_back(tmp->value());
Expand Down
2 changes: 2 additions & 0 deletions src/framework/core/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Module : public LuaObject
bool isDependent() const;
bool isSandboxed() { return m_sandboxed; }
bool hasDependency(const std::string_view name, bool recursive = false);
bool hasSupportedDevice(Platform::Device device);
int getSandbox(LuaInterface* lua);

std::string getDescription() { return m_description; }
Expand Down Expand Up @@ -83,4 +84,5 @@ class Module : public LuaObject
std::list<std::string> m_dependencies;
std::list<std::string> m_scripts;
std::list<std::string> m_loadLaterModules;
std::list<Platform::Device> m_supportedDevices;
};
14 changes: 13 additions & 1 deletion src/framework/luaengine/luaobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,23 @@ connect(const LuaObjectPtr& obj, const std::string_view field, const Lambda& f,
template<typename... T>
int LuaObject::luaCallLuaField(const std::string_view field, const T&... args)
{
// we need to gracefully catch a cast exception here in case
// this is called from a constructor, this does not need to
// blow up, we can just debug log it and exit.
LuaObjectPtr self;
try {
self = asLuaObject();
} catch (std::exception e) {
g_logger.fine(stdext::format(
"luaCallLuaField: error calling '%s', likely called in ctor.", field));
return 0;
}

// note that the field must be retrieved from this object lua value
// to force using the __index metamethod of it's metatable
// so cannot use LuaObject::getField here
// push field
g_lua.pushObject(asLuaObject());
g_lua.pushObject(self);
g_lua.getField(field);

if (!g_lua.isNil()) {
Expand Down
27 changes: 27 additions & 0 deletions src/framework/luaengine/luavaluecasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ bool luavalue_cast(int index, Size& size)
return false;
}

// device
int push_luavalue(const Platform::Device& device)
{
g_lua.createTable(0, 2);
g_lua.pushInteger(device.type);
g_lua.setField("type");
g_lua.pushInteger(device.os);
g_lua.setField("os");
return 1;
}

bool luavalue_cast(int index, Platform::Device& device)
{
if (g_lua.isTable(index)) {
g_lua.getField("type", index);
device.type = static_cast<Platform::DeviceType>(g_lua.popInteger());
g_lua.getField("os", index);
device.os = static_cast<Platform::OperatingSystem>(g_lua.popInteger());
return true;
}
if (g_lua.isNil()) {
device = {};
return true;
}
return false;
}

// otml nodes
void push_otml_subnode_luavalue(const OTMLNodePtr& node)
{
Expand Down
5 changes: 5 additions & 0 deletions src/framework/luaengine/luavaluecasts.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// this file is and must be included only from luainterface.h

#include <framework/otml/declarations.h>
#include <framework/platform/platform.h>
#include "declarations.h"

template<typename T>
Expand Down Expand Up @@ -135,6 +136,10 @@ bool luavalue_cast(int index, Point& point);
int push_luavalue(const Size& size);
bool luavalue_cast(int index, Size& size);

// device
int push_luavalue(const Platform::Device& device);
bool luavalue_cast(int index, Platform::Device& device);

// otml nodes
int push_luavalue(const OTMLNodePtr& node);
bool luavalue_cast(int index, OTMLNodePtr& node);
Expand Down
Loading