Add camera bindings
override missing, but it's a start
This commit is contained in:
parent
9502b05ea4
commit
3b40e89b32
@ -22,6 +22,7 @@
|
|||||||
#include "StarInterfaceLuaBindings.hpp"
|
#include "StarInterfaceLuaBindings.hpp"
|
||||||
#include "StarInputLuaBindings.hpp"
|
#include "StarInputLuaBindings.hpp"
|
||||||
#include "StarVoiceLuaBindings.hpp"
|
#include "StarVoiceLuaBindings.hpp"
|
||||||
|
#include "StarCameraLuaBindings.hpp"
|
||||||
#include "StarClipboardLuaBindings.hpp"
|
#include "StarClipboardLuaBindings.hpp"
|
||||||
|
|
||||||
#if defined STAR_SYSTEM_WINDOWS
|
#if defined STAR_SYSTEM_WINDOWS
|
||||||
@ -541,6 +542,7 @@ void ClientApplication::changeState(MainAppState newState) {
|
|||||||
|
|
||||||
m_universeClient->setLuaCallbacks("input", LuaBindings::makeInputCallbacks());
|
m_universeClient->setLuaCallbacks("input", LuaBindings::makeInputCallbacks());
|
||||||
m_universeClient->setLuaCallbacks("voice", LuaBindings::makeVoiceCallbacks());
|
m_universeClient->setLuaCallbacks("voice", LuaBindings::makeVoiceCallbacks());
|
||||||
|
m_universeClient->setLuaCallbacks("camera", LuaBindings::makeCameraCallbacks(&m_worldPainter->camera()));
|
||||||
if (!m_root->configuration()->get("safeScripts").toBool())
|
if (!m_root->configuration()->get("safeScripts").toBool())
|
||||||
m_universeClient->setLuaCallbacks("clipboard", LuaBindings::makeClipboardCallbacks(appController()));
|
m_universeClient->setLuaCallbacks("clipboard", LuaBindings::makeClipboardCallbacks(appController()));
|
||||||
|
|
||||||
|
@ -162,6 +162,7 @@ SET (star_game_HEADERS
|
|||||||
StarWeatherTypes.hpp
|
StarWeatherTypes.hpp
|
||||||
StarWireProcessor.hpp
|
StarWireProcessor.hpp
|
||||||
StarWiring.hpp
|
StarWiring.hpp
|
||||||
|
StarWorldCamera.hpp
|
||||||
StarWorldClient.hpp
|
StarWorldClient.hpp
|
||||||
StarWorldClientState.hpp
|
StarWorldClientState.hpp
|
||||||
StarWorldGeneration.hpp
|
StarWorldGeneration.hpp
|
||||||
@ -231,6 +232,7 @@ SET (star_game_HEADERS
|
|||||||
objects/StarPhysicsObject.hpp
|
objects/StarPhysicsObject.hpp
|
||||||
objects/StarTeleporterObject.hpp
|
objects/StarTeleporterObject.hpp
|
||||||
|
|
||||||
|
scripting/StarCameraLuaBindings.hpp
|
||||||
scripting/StarCelestialLuaBindings.hpp
|
scripting/StarCelestialLuaBindings.hpp
|
||||||
scripting/StarBehaviorLuaBindings.hpp
|
scripting/StarBehaviorLuaBindings.hpp
|
||||||
scripting/StarConfigLuaBindings.hpp
|
scripting/StarConfigLuaBindings.hpp
|
||||||
@ -421,6 +423,7 @@ SET (star_game_SOURCES
|
|||||||
StarWeatherTypes.cpp
|
StarWeatherTypes.cpp
|
||||||
StarWireProcessor.cpp
|
StarWireProcessor.cpp
|
||||||
StarWiring.cpp
|
StarWiring.cpp
|
||||||
|
StarWorldCamera.cpp
|
||||||
StarWorldClient.cpp
|
StarWorldClient.cpp
|
||||||
StarWorldClientState.cpp
|
StarWorldClientState.cpp
|
||||||
StarWorldGeneration.cpp
|
StarWorldGeneration.cpp
|
||||||
@ -470,6 +473,7 @@ SET (star_game_SOURCES
|
|||||||
objects/StarPhysicsObject.cpp
|
objects/StarPhysicsObject.cpp
|
||||||
objects/StarTeleporterObject.cpp
|
objects/StarTeleporterObject.cpp
|
||||||
|
|
||||||
|
scripting/StarCameraLuaBindings.cpp
|
||||||
scripting/StarCelestialLuaBindings.cpp
|
scripting/StarCelestialLuaBindings.cpp
|
||||||
scripting/StarBehaviorLuaBindings.cpp
|
scripting/StarBehaviorLuaBindings.cpp
|
||||||
scripting/StarConfigLuaBindings.cpp
|
scripting/StarConfigLuaBindings.cpp
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Star {
|
namespace Star {
|
||||||
|
|
||||||
void WorldCamera::setCenterWorldPosition(Vec2F const& position, bool force) {
|
void WorldCamera::setCenterWorldPosition(Vec2F position, bool force) {
|
||||||
m_rawWorldCenter = position;
|
m_rawWorldCenter = position;
|
||||||
// Only actually move the world center if a half pixel distance has been
|
// Only actually move the world center if a half pixel distance has been
|
||||||
// moved in any direction. This is sort of arbitrary, but helps prevent
|
// moved in any direction. This is sort of arbitrary, but helps prevent
|
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
// Set the camera center position (in world space) to as close to the given
|
// Set the camera center position (in world space) to as close to the given
|
||||||
// location as possible while keeping the screen within world bounds.
|
// location as possible while keeping the screen within world bounds.
|
||||||
void setCenterWorldPosition(Vec2F const& position, bool force = false);
|
void setCenterWorldPosition(Vec2F position, bool force = false);
|
||||||
// Returns the actual camera position.
|
// Returns the actual camera position.
|
||||||
Vec2F centerWorldPosition() const;
|
Vec2F centerWorldPosition() const;
|
||||||
|
|
||||||
@ -28,10 +28,10 @@ public:
|
|||||||
// the world is non-euclidean, one world coordinate can transform to
|
// the world is non-euclidean, one world coordinate can transform to
|
||||||
// potentially an infinite number of screen coordinates. This will retrun
|
// potentially an infinite number of screen coordinates. This will retrun
|
||||||
// the closest to the center of the screen.
|
// the closest to the center of the screen.
|
||||||
Vec2F worldToScreen(Vec2F const& worldCoord) const;
|
Vec2F worldToScreen(Vec2F worldCoord) const;
|
||||||
|
|
||||||
// Assumes top left corner of screen is (0, 0) in screen coordinates.
|
// Assumes top left corner of screen is (0, 0) in screen coordinates.
|
||||||
Vec2F screenToWorld(Vec2F const& screen) const;
|
Vec2F screenToWorld(Vec2F screen) const;
|
||||||
|
|
||||||
// Returns screen dimensions in world space.
|
// Returns screen dimensions in world space.
|
||||||
RectF worldScreenRect() const;
|
RectF worldScreenRect() const;
|
||||||
@ -86,7 +86,7 @@ inline Vec2F WorldCamera::centerWorldPosition() const {
|
|||||||
return Vec2F(m_worldCenter);
|
return Vec2F(m_worldCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vec2F WorldCamera::worldToScreen(Vec2F const& worldCoord) const {
|
inline Vec2F WorldCamera::worldToScreen(Vec2F worldCoord) const {
|
||||||
Vec2F wrappedCoord = m_worldGeometry.nearestTo(Vec2F(m_worldCenter), worldCoord);
|
Vec2F wrappedCoord = m_worldGeometry.nearestTo(Vec2F(m_worldCenter), worldCoord);
|
||||||
return Vec2F(
|
return Vec2F(
|
||||||
(wrappedCoord[0] - m_worldCenter[0]) * (TilePixels * m_pixelRatio) + (float)m_screenSize[0] / 2.0,
|
(wrappedCoord[0] - m_worldCenter[0]) * (TilePixels * m_pixelRatio) + (float)m_screenSize[0] / 2.0,
|
||||||
@ -94,7 +94,7 @@ inline Vec2F WorldCamera::worldToScreen(Vec2F const& worldCoord) const {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vec2F WorldCamera::screenToWorld(Vec2F const& screen) const {
|
inline Vec2F WorldCamera::screenToWorld(Vec2F screen) const {
|
||||||
return Vec2F(
|
return Vec2F(
|
||||||
(screen[0] - (float)m_screenSize[0] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[0],
|
(screen[0] - (float)m_screenSize[0] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[0],
|
||||||
(screen[1] - (float)m_screenSize[1] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[1]
|
(screen[1] - (float)m_screenSize[1] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[1]
|
31
source/game/scripting/StarCameraLuaBindings.cpp
Normal file
31
source/game/scripting/StarCameraLuaBindings.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "StarCameraLuaBindings.hpp"
|
||||||
|
#include "StarLuaConverters.hpp"
|
||||||
|
#include "StarWorldCamera.hpp"
|
||||||
|
#include "StarRoot.hpp"
|
||||||
|
|
||||||
|
namespace Star {
|
||||||
|
|
||||||
|
LuaCallbacks LuaBindings::makeCameraCallbacks(WorldCamera* camera) {
|
||||||
|
LuaCallbacks callbacks;
|
||||||
|
|
||||||
|
callbacks.registerCallbackWithSignature<Vec2F>("position", bind(&WorldCamera::centerWorldPosition, camera));
|
||||||
|
callbacks.registerCallbackWithSignature<float>("pixelRatio", bind(&WorldCamera::pixelRatio, camera));
|
||||||
|
callbacks.registerCallback("setPixelRatio", [camera](float pixelRatio, Maybe<bool> smooth) {
|
||||||
|
if (smooth.value())
|
||||||
|
camera->setTargetPixelRatio(pixelRatio);
|
||||||
|
else
|
||||||
|
camera->setPixelRatio(pixelRatio);
|
||||||
|
Root::singleton().configuration()->set("zoomLevel", pixelRatio);
|
||||||
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallbackWithSignature<Vec2U>("screenSize", bind(&WorldCamera::screenSize, camera));
|
||||||
|
callbacks.registerCallbackWithSignature<RectF>("worldScreenRect", bind(&WorldCamera::worldScreenRect, camera));
|
||||||
|
callbacks.registerCallbackWithSignature<RectI>("worldTileRect", bind(&WorldCamera::worldTileRect, camera));
|
||||||
|
callbacks.registerCallbackWithSignature<Vec2F>("tileMinScreen", bind(&WorldCamera::tileMinScreen, camera));
|
||||||
|
callbacks.registerCallbackWithSignature<Vec2F, Vec2F>("screenToWorld", bind(&WorldCamera::screenToWorld, camera, _1));
|
||||||
|
callbacks.registerCallbackWithSignature<Vec2F, Vec2F>("worldToScreen", bind(&WorldCamera::worldToScreen, camera, _1));
|
||||||
|
|
||||||
|
return callbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
source/game/scripting/StarCameraLuaBindings.hpp
Normal file
12
source/game/scripting/StarCameraLuaBindings.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "StarLua.hpp"
|
||||||
|
|
||||||
|
namespace Star {
|
||||||
|
|
||||||
|
STAR_CLASS(WorldCamera);
|
||||||
|
|
||||||
|
namespace LuaBindings {
|
||||||
|
LuaCallbacks makeCameraCallbacks(WorldCamera* camera);
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,6 @@ SET (star_rendering_HEADERS
|
|||||||
StarFontTextureGroup.hpp
|
StarFontTextureGroup.hpp
|
||||||
StarTextPainter.hpp
|
StarTextPainter.hpp
|
||||||
StarTilePainter.hpp
|
StarTilePainter.hpp
|
||||||
StarWorldCamera.hpp
|
|
||||||
StarWorldPainter.hpp
|
StarWorldPainter.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,7 +27,6 @@ SET (star_rendering_SOURCES
|
|||||||
StarFontTextureGroup.cpp
|
StarFontTextureGroup.cpp
|
||||||
StarTextPainter.cpp
|
StarTextPainter.cpp
|
||||||
StarTilePainter.cpp
|
StarTilePainter.cpp
|
||||||
StarWorldCamera.cpp
|
|
||||||
StarWorldPainter.cpp
|
StarWorldPainter.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user