Small script change and API change.

This commit is contained in:
Kapendev 2024-11-19 22:16:33 +02:00
parent 637879a5b3
commit 80b473965e
5 changed files with 29 additions and 25 deletions

View file

@ -95,6 +95,10 @@ bool isReleased(Gamepad key, int id = 0);
Vec2 wasd(); Vec2 wasd();
Vec2 wasdPressed(); Vec2 wasdPressed();
Vec2 wasdReleased(); Vec2 wasdReleased();
Vec2 mouse();
Vec2 deltaMouse();
float deltaWheel();
``` ```
## Sound ## Sound
@ -103,15 +107,10 @@ Parin provides a set of sound functions inside the `parin.engine` module.
```d ```d
void playSound(Sound sound); void playSound(Sound sound);
void playSound(SoundId sound);
void stopSound(Sound sound); void stopSound(Sound sound);
void stopSound(SoundId sound);
void pauseSound(Sound sound); void pauseSound(Sound sound);
void pauseSound(SoundId sound);
void resumeSound(Sound sound); void resumeSound(Sound sound);
void resumeSound(SoundId sound);
void updateSound(Sound sound); void updateSound(Sound sound);
void updateSound(SoundId sound);
``` ```
## Drawing ## Drawing

View file

@ -20,10 +20,10 @@ bool update(float dt) {
// The sprite should be updated every frame, regardless of whether it is running. // The sprite should be updated every frame, regardless of whether it is running.
sprite.update(dt); sprite.update(dt);
// Get some basic info about the mouse. // Get some basic info about the mouse.
auto mouseDistance = sprite.position.distanceTo(mouseScreenPosition); auto mouseDistance = sprite.position.distanceTo(mouse);
auto mouseDirection = sprite.position.directionTo(mouseScreenPosition); auto mouseDirection = sprite.position.directionTo(mouse);
// Move the sprite around in a smooth way. // Move the sprite around in a smooth way.
sprite.followPositionWithSlowdown(mouseScreenPosition, 0.2); sprite.followPositionWithSlowdown(mouse, 0.2);
// Play the right animation. // Play the right animation.
auto isWaiting = mouseDistance < 0.2; auto isWaiting = mouseDistance < 0.2;
@ -55,7 +55,7 @@ bool update(float dt) {
// Draw the sprite, the mouse position and some info. // Draw the sprite, the mouse position and some info.
drawSprite(atlas, sprite, options); drawSprite(atlas, sprite, options);
drawVec2(mouseScreenPosition, 8, isWaiting ? blank : white.alpha(150)); drawVec2(mouse, 8, isWaiting ? blank : white.alpha(150));
drawDebugText("Press 1, 2 or 3 to change the character.", Vec2(8)); drawDebugText("Press 1, 2 or 3 to change the character.", Vec2(8));
return false; return false;
} }

View file

@ -14,7 +14,7 @@ bool update(float dt) {
if (isWindowResized) viewport.resize(resolutionWidth / 2, resolutionHeight / 2); if (isWindowResized) viewport.resize(resolutionWidth / 2, resolutionHeight / 2);
// Draw the mouse position inside the viewport. // Draw the mouse position inside the viewport.
auto viewportCenter = viewport.size * Vec2(0.5); auto viewportCenter = viewport.size * Vec2(0.5);
auto viewportMousePosition = mouseScreenPosition - Rect(resolution * Vec2(0.5), viewport.size).centerArea.position; auto viewportMousePosition = mouse - Rect(resolution * Vec2(0.5), viewport.size).centerArea.position;
viewport.attach(); viewport.attach();
drawVec2(viewportCenter, 20); drawVec2(viewportCenter, 20);
drawVec2(viewportMousePosition, 20); drawVec2(viewportMousePosition, 20);

View file

@ -169,8 +169,8 @@ int runDubSetup(string[] args, bool isFirstRun) {
} }
whileExit: whileExit:
if (arg == "Y" || arg == "y") { if (arg == "Y" || arg == "y") {
auto dub1 = spawnProcess(["dub", "add", "raylib-d"]).wait(); auto dub1 = spawnProcess(["dub", "add", "raylib-d", "--verror"]).wait();
auto dub2 = spawnProcess(["dub", "run", "raylib-d:install"]).wait(); auto dub2 = spawnProcess(["dub", "run", "raylib-d:install", "--verror", "--", "-q", "-u=no"]).wait();
// Remove the backup copies if something failed. // Remove the backup copies if something failed.
if (dub1 != 0 || dub2 != 0) { if (dub1 != 0 || dub2 != 0) {
if (exists(dubCopyFile)) std.file.remove(dubCopyFile); if (exists(dubCopyFile)) std.file.remove(dubCopyFile);
@ -182,7 +182,7 @@ int runDubSetup(string[] args, bool isFirstRun) {
// Replace the dub file content if needed. // Replace the dub file content if needed.
if (isFirstRun) { if (isFirstRun) {
std.file.write(dubFile, dubFileContent); std.file.write(dubFile, dubFileContent);
std.file.remove(dubLockFile); if (exists(dubLockFile)) std.file.remove(dubLockFile);
// Remove the backup copies. // Remove the backup copies.
if (exists(dubCopyFile)) std.file.remove(dubCopyFile); if (exists(dubCopyFile)) std.file.remove(dubCopyFile);
if (exists(dubLockCopyFile)) std.file.remove(dubLockCopyFile); if (exists(dubLockCopyFile)) std.file.remove(dubLockCopyFile);
@ -202,8 +202,14 @@ int runDubSetup(string[] args, bool isFirstRun) {
} }
int main(string[] args) { int main(string[] args) {
auto isSimpProject = !exists(dubFile); auto result = 0;
auto isFirstRun = !exists(assetsDir); auto isFirstRun = !exists(assetsDir);
if (isSimpProject) return runSimpSetup(args[1 .. $], isFirstRun); auto isSimpProject = !exists(dubFile);
else return runDubSetup(args[1 .. $], isFirstRun); if (isSimpProject) {
result = runSimpSetup(args[1 .. $], isFirstRun);
} else {
result = runDubSetup(args[1 .. $], isFirstRun);
}
if (result == 0) writeln("Done!");
return result;
} }

View file

@ -166,8 +166,8 @@ struct DrawOptions {
Vec2 scale = Vec2(1.0f); /// The scale of the drawn object. Vec2 scale = Vec2(1.0f); /// The scale of the drawn object.
float rotation = 0.0f; /// The rotation of the drawn object, in degrees. float rotation = 0.0f; /// The rotation of the drawn object, in degrees.
Color color = white; /// The color of the drawn object. Color color = white; /// The color of the drawn object.
Hook hook = Hook.topLeft; /// An value representing the origin point of the drawn object when origin is set to zero. Hook hook = Hook.topLeft; /// A value representing the origin point of the drawn object when origin is set to zero.
Flip flip = Flip.none; /// An value representing flipping orientations. Flip flip = Flip.none; /// A value representing flipping orientations.
@safe @nogc nothrow: @safe @nogc nothrow:
@ -555,9 +555,9 @@ struct SoundId {
/// Represents the viewing area for rendering. /// Represents the viewing area for rendering.
struct Viewport { struct Viewport {
rl.RenderTexture2D data; rl.RenderTexture2D data;
Color color; /// TOOO Color color; /// The background color of the viewport.
Blend blend; /// TOOO Blend blend; /// A value representing blending modes.
bool isAttached; /// Indicates whether the viewport is currently in use. bool isAttached; /// Indicates whether the viewport is currently in use.
@safe @nogc nothrow: @safe @nogc nothrow:
@ -1652,7 +1652,7 @@ float deltaTime() {
/// Returns the change in mouse position since the last frame. /// Returns the change in mouse position since the last frame.
@trusted @trusted
Vec2 deltaMouse() { Vec2 deltaMouse() {
return toParin(rl.GetMouseDelta()); return rl.GetMouseDelta().toParin();
} }
/// Returns the change in mouse wheel position since the last frame. /// Returns the change in mouse wheel position since the last frame.
@ -1675,9 +1675,8 @@ float deltaWheel() {
/// Measures the size of the specified text when rendered with the given font and draw options. /// Measures the size of the specified text when rendered with the given font and draw options.
@trusted @trusted
Vec2 measureTextSize(Font font, IStr text, DrawOptions options = DrawOptions()) { Vec2 measureTextSize(Font font, IStr text, DrawOptions options = DrawOptions()) {
if (font.isEmpty || text.length == 0) { if (font.isEmpty || text.length == 0) return Vec2();
return Vec2();
}
auto result = Vec2(); auto result = Vec2();
auto tempByteCounter = 0; // Used to count longer text line num chars. auto tempByteCounter = 0; // Used to count longer text line num chars.
auto byteCounter = 0; auto byteCounter = 0;