Skip to content

Commit

Permalink
Add ship log function from lua
Browse files Browse the repository at this point in the history
  • Loading branch information
daid committed Oct 31, 2024
1 parent a30d0df commit 50635d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/api/entity/playerspaceship.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end
--- Takes a string as the message and a color applied to the logged message.
--- Example: player:addToShipLog("Acknowledged","yellow") -- adds "Acknowledged" in yellow to the `player` ship's log
function Entity:addToShipLog(message, color)
--TODO
addEntryToShipsLog(self, message, color)
end
--- Moves all players connected to this ship to the same crew positions on another PlayerSpaceship.
--- If the target isn't a PlayerSpaceship, this function has no effect.
Expand Down
8 changes: 8 additions & 0 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "components/beamweapon.h"
#include "components/internalrooms.h"
#include "components/zone.h"
#include "components/shiplog.h"
#include "components/selfdestruct.h"
#include "systems/jumpsystem.h"
#include "systems/missilesystem.h"
Expand Down Expand Up @@ -477,6 +478,12 @@ void luaRemovePlayerShipCustomFunction(sp::ecs::Entity entity, string name)
}
}

void luaAddEntryToShipsLog(sp::ecs::Entity entity, string entry, glm::u8vec4 color)
{
auto sl = entity.getComponent<ShipLog>();
if (!sl) return;
sl->add(entry, color);
}


static sp::ecs::Entity luaGetPlayerShip(int index)
Expand Down Expand Up @@ -1204,6 +1211,7 @@ bool setupScriptEnvironment(sp::script::Environment& env)
env.setGlobal("hasPlayerCrewAtPosition", &luaHasPlayerAtPosition);
env.setGlobal("setPlayerShipCustomFunction", &luaSetPlayerShipCustomFunction);
env.setGlobal("removePlayerShipCustomFunction", &luaRemovePlayerShipCustomFunction);
env.setGlobal("addEntryToShipsLog", &luaAddEntryToShipsLog);

/// EScanningComplexity getScanningComplexity()
/// Returns the running scenario's scanning complexity setting.
Expand Down
28 changes: 27 additions & 1 deletion src/script/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,33 @@ template<> struct Convert<glm::u8vec4> {
}
static glm::u8vec4 fromLua(lua_State* L, int idx) {
glm::u8vec4 result{};
if (lua_isinteger(L, idx)) {
if (lua_isstring(L, idx)) {
result = glm::u8vec4(255,255,255,255);
string str = string(lua_tostring(L, idx)).lower();
if (str == "black") { result = glm::u8vec4(0,0,0,255); return result; }
else if (str == "white") { result = glm::u8vec4(255,255,255,255); return result; }
else if (str == "red") { result = glm::u8vec4(255,0,0,255); return result; }
else if (str == "green") { result = glm::u8vec4(0,255,0,255); return result; }
else if (str == "blue") { result = glm::u8vec4(0,0,255,255); return result; }
else if (str == "yellow") { result = glm::u8vec4(255,255,0,255); return result; }
else if (str == "magenta") { result = glm::u8vec4(255,0,255,255); return result; }
else if (str == "cyan") { result = glm::u8vec4(0,255,255,255); return result; }

if (str.startswith("#") && str.length() == 7)
{
result.r = static_cast<uint8_t>(str.substr(1, 2).toInt(16));
result.g = static_cast<uint8_t>(str.substr(3, 2).toInt(16));
result.b = static_cast<uint8_t>(str.substr(5, 2).toInt(16));
} else {
std::vector<string> parts = str.split(",");
if (parts.size() == 3)
{
result.r = static_cast<uint8_t>(parts[0].toInt());
result.g = static_cast<uint8_t>(parts[1].toInt());
result.b = static_cast<uint8_t>(parts[2].toInt());
}
}
} else if (lua_isinteger(L, idx)) {
int n = lua_tointeger(L, idx);
result.r = float(n & 0xFF) / 255.0f;
result.g = float((n >> 8) & 0xFF) / 255.0f;
Expand Down

1 comment on commit 50635d9

@daid-tinyci
Copy link

@daid-tinyci daid-tinyci bot commented on 50635d9 Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TinyCI build failure:

[/home/tinyci/builds/daid/EmptyEpsilon/_build_native:ninja -j 10 package] returned [1]:


Reading api/all.lua

Reading api/modelData.lua

Reading api/shipTemplate.lua

Reading api/entity/spaceobject.lua

Reading api/entity/factioninfo.lua

Reading api/entity/shiptemplatebasedobject.lua

Reading api/entity/spaceship.lua

Reading api/entity/playerspaceship.lua

Reading api/entity/cpuship.lua

Reading api/entity/spacestation.lua

Reading api/entity/warpjammer.lua

Reading api/entity/artifact.lua

Reading api/entity/asteroid.lua

Reading api/entity/mine.lua

Reading api/entity/nebula.lua

Reading api/entity/blackhole.lua

Reading api/entity/planet.lua

Reading api/entity/sciencedatabase.lua

Reading api/entity/multiuse.lua

Reading api/entity/scanprobe.lua

Reading api/entity/supplydrop.lua

Reading api/entity/zone.lua

Reading api/gm.lua

Reading api/callsign.lua

[2/5] Building CXX object CMakeFiles/EmptyEpsilon.dir/src/script.cpp.o

[3/5] Building CXX object CMakeFiles/EmptyEpsilon.dir/src/script/components.cpp.o

[4/5] Linking CXX executable EmptyEpsilon

lto-wrapper: warning: using serial compilation of 93 LTRANS jobs

lto-wrapper: note: see the ‘-flto’ option documentation for more information

[4/5] Run CPack packaging tool...

CPack: Create package using DEB

CPack: Install projects

CPack: - Install project: EmptyEpsilon []

CMake Error at /data/tinyci_builds/daid/EmptyEpsilon/_build_native/cmake_install.cmake:82 (file):

  file INSTALL cannot find

  "/data/tinyci_builds/daid/EmptyEpsilon/io.github.daid.EmptyEpsilon.metainfo.xml":

  No such file or directory.





CPack Error: Error when generating package: EmptyEpsilon

FAILED: CMakeFiles/package.util 

cd /data/tinyci_builds/daid/EmptyEpsilon/_build_native && /usr/bin/cpack --config ./CPackConfig.cmake

ninja: build stopped: subcommand failed.

Please sign in to comment.