summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonAki <konaki@anokonaki.org>2026-10-14 18:47:55 +0800
committerKonAki <konaki@anokonaki.org>2026-10-14 18:47:55 +0800
commitac3f5875c373ade26547fecb7ad2e2a53003aabc (patch)
tree743fd396ab7402c70a4f0d172f56a6c590c704ff
parent8047c8acdbb8f3dddb423c553c1b74ed45ce99e9 (diff)
add RPG Maker screen commands to fx
-rw-r--r--kon/konfx.c62
-rw-r--r--kon/konfx.h5
2 files changed, 67 insertions, 0 deletions
diff --git a/kon/konfx.c b/kon/konfx.c
index abbc7ec..50f3454 100644
--- a/kon/konfx.c
+++ b/kon/konfx.c
@@ -225,3 +225,65 @@ void kon_screenfxApply(const kon_screenfx_t *fx, kon_framebuffer_t *fb)
kon_screenfxApplyScene(fx, fb);
kon_screenfxApplyOverlay(fx, fb);
}
+
+/*** konscript host commands ***/
+
+static int paramInt(int b, int c, int d, const char *text, int index)
+{
+ long value = 0;
+ int negative = 0, digits = 0;
+
+ if (!text) return index == 0 ? b : index == 1 ? c : index == 2 ? d : 0;
+
+ while (index > 0 && *text) {
+ if (*text++ == '\t') index--;
+ }
+ if (*text == '-') {
+ negative = 1;
+ text++;
+ }
+ while (*text >= '0' && *text <= '9' && digits < 9) {
+ value = value * 10 + (*text++ - '0');
+ digits++;
+ }
+ return (int)(negative ? -value : value);
+}
+
+int kon_screenfxHost(kon_screenfx_t *fx, int code, int b, int c, int d, const char *text)
+{
+ int frames, wait;
+ int tone[4];
+ int i;
+
+ if (!fx) return -1;
+ switch (code) {
+ case 221:
+ kon_screenfxFade(fx, 0x000000, 1.0f, 24.0f / 60.0f, KON_EASE_LINEAR);
+ return 1;
+ case 222:
+ kon_screenfxFade(fx, 0x000000, 0.0f, 24.0f / 60.0f, KON_EASE_LINEAR);
+ return 1;
+ case 223:
+ for (i = 0; i < 4; i++) tone[i] = paramInt(b, c, d, text, i);
+ frames = paramInt(b, c, d, text, 4);
+ wait = paramInt(b, c, d, text, 5);
+ kon_screenfxTone(fx, clampInt((float)tone[0], -255, 255), clampInt((float)tone[1], -255, 255), clampInt((float)tone[2], -255, 255), clampInt((float)tone[3], 0, 255), (float)frames / 60.0f, KON_EASE_LINEAR);
+ return wait && frames > 0;
+ case 224:
+ for (i = 0; i < 4; i++) tone[i] = clampInt((float)paramInt(b, c, d, text, i), 0, 255);
+ frames = paramInt(b, c, d, text, 4);
+ wait = paramInt(b, c, d, text, 5);
+ kon_screenfxFlash(fx, ((uint32_t)tone[3] << 24) | ((uint32_t)tone[0] << 16) | ((uint32_t)tone[1] << 8) | (uint32_t)tone[2], (float)frames / 60.0f);
+ return wait && frames > 0;
+ case 225:
+ /* RPG Maker swings by twice the power, sideways only, speed 1 to 9 is three quarters of a swing per second per step */
+ tone[0] = clampInt((float)paramInt(b, c, d, text, 0), 1, 9);
+ tone[1] = clampInt((float)paramInt(b, c, d, text, 1), 1, 9);
+ frames = paramInt(b, c, d, text, 2);
+ wait = paramInt(b, c, d, text, 3);
+ kon_screenfxShake(fx, (float)tone[0] * 2.0f, 0.0f, (float)tone[1] * 0.75f, (float)frames / 60.0f);
+ return wait && frames > 0;
+ default:
+ return -1;
+ }
+}
diff --git a/kon/konfx.h b/kon/konfx.h
index 0a7a913..cab36f2 100644
--- a/kon/konfx.h
+++ b/kon/konfx.h
@@ -76,6 +76,11 @@ void kon_screenfxApplyScene(const kon_screenfx_t *fx, kon_framebuffer_t *fb);
void kon_screenfxApplyOverlay(const kon_screenfx_t *fx, kon_framebuffer_t *fb);
void kon_screenfxApply(const kon_screenfx_t *fx, kon_framebuffer_t *fb);
+/* the RPG Maker screen commands the way mzscript writes them: 221 fadeout, 222 fadein, 223 tint, 224 flash, 225 shake.
+ returns -1 when the code is not one of those, 0 when it is done, 1 when the script is meant to wait. that wait is over
+ when kon_screenfxBusy says 0, so the host function returns 1 and you call kon_scriptResume then */
+int kon_screenfxHost(kon_screenfx_t *fx, int code, int b, int c, int d, const char *text);
+
#ifdef __cplusplus
}