Skip to content

Commit 47a2781

Browse files
committed
luaスクリプト用のgetcurve()関数の第一引数を文字列指定でも呼び出せるようにした
1 parent 3f05a97 commit 47a2781

File tree

10 files changed

+103
-42
lines changed

10 files changed

+103
-42
lines changed

curve_editor/constants.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66

77
namespace cved {
88
namespace global {
9-
inline constexpr int MARGIN = 6;
10-
inline constexpr int MARGIN_PRESET = 8;
11-
inline constexpr int MIN_WIDTH = 100;
12-
inline constexpr int MIN_HEIGHT = 200;
139
inline constexpr int SEPARATOR_WIDTH = 8;
14-
inline constexpr int MENU_HEIGHT = 75;
1510
inline constexpr size_t IDCURVE_MAX_N = 524288u;
16-
inline constexpr float ROUND_RADIUS = 4.f;
17-
inline constexpr float SEPARATOR_LINE_WIDTH = 3.6f;
18-
inline constexpr float SEPARATOR_LINE_LENGTH = 32.f;
19-
inline constexpr float HANDLE_THICKNESS_PRESET = 0.8f;
20-
inline constexpr float HANDLE_SIZE_PRESET = 0.7f;
21-
inline constexpr float HANDLE_BORDER_THICKNESS_PRESET = 0.5f;
22-
inline constexpr float POINT_SIZE_PREEST = 2.f;
11+
12+
inline constexpr auto CURVE_NAME_NORMAL = "normal";
13+
inline constexpr auto CURVE_NAME_VALUE = "value";
14+
inline constexpr auto CURVE_NAME_BEZIER = "bezier";
15+
inline constexpr auto CURVE_NAME_ELASTIC = "elastic";
16+
inline constexpr auto CURVE_NAME_BOUNCE = "bounce";
17+
inline constexpr auto CURVE_NAME_LINEAR = "linear";
18+
inline constexpr auto CURVE_NAME_SCRIPT = "script";
2319

2420
inline constexpr auto PLUGIN_NAME = "Curve Editor";
2521
inline constexpr auto PLUGIN_VERSION = mkaul::Version{

curve_editor/curve.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ namespace cved {
2121
virtual void unlock() noexcept { locked_ = false; }
2222
auto is_locked() const noexcept { return locked_; }
2323
virtual bool is_default() const noexcept = 0;
24-
virtual std::string get_type() const noexcept = 0;
24+
constexpr virtual std::string get_type() const noexcept = 0;
2525
};
2626
} // namespace cved

curve_editor/curve_bezier.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve_graph_numeric.hpp"
45

56

@@ -25,7 +26,7 @@ namespace cved {
2526
// コピーコンストラクタ
2627
BezierCurve(const BezierCurve& curve) noexcept;
2728

28-
std::string get_type() const noexcept override { return "bezier"; }
29+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_BEZIER; }
2930

3031
double get_handle_left_x() const noexcept { return anchor_start().x + handle_left_.x; }
3132
double get_handle_left_y() const noexcept { return anchor_start().y + handle_left_.y; }

curve_editor/curve_bounce.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve_graph_numeric.hpp"
45

56

@@ -30,7 +31,7 @@ namespace cved {
3031
// コピーコンストラクタ
3132
BounceCurve(const BounceCurve& curve) noexcept;
3233

33-
std::string get_type() const noexcept override { return "bounce"; }
34+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_BOUNCE; }
3435

3536
// カーブの値を生成
3637
double curve_function(double progress, double start, double end) const noexcept override;

curve_editor/curve_elastic.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve_graph_numeric.hpp"
45

56

@@ -32,7 +33,7 @@ namespace cved {
3233
// コピーコンストラクタ
3334
ElasticCurve(const ElasticCurve& curve) noexcept;
3435

35-
std::string get_type() const noexcept override { return "elastic"; }
36+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_ELASTIC; }
3637

3738
// カーブの値を取得
3839
double curve_function(double progress, double start, double end) const noexcept override;

curve_editor/curve_linear.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve_graph.hpp"
45

56

@@ -18,7 +19,7 @@ namespace cved {
1819
GraphCurve{ anchor_start, anchor_end, pt_fixed, prev, next }
1920
{}
2021

21-
std::string get_type() const noexcept override { return "linear"; }
22+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_LINEAR; }
2223

2324
// カーブの値を取得
2425
double curve_function(double progress, double start, double end) const noexcept override;

curve_editor/curve_normal.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve_graph.hpp"
45
#include "enum.hpp"
56
#include <cereal/types/vector.hpp>
@@ -21,7 +22,7 @@ namespace cved {
2122
// コピーコンストラクタ
2223
NormalCurve(const NormalCurve& curve) noexcept;
2324

24-
std::string get_type() const noexcept override { return "normal"; }
25+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_NORMAL; }
2526

2627
// セグメント数を取得
2728
auto segment_n() const noexcept { return curve_segments_.size(); }

curve_editor/curve_script.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve.hpp"
45
#include <cereal/archives/binary.hpp>
56
#include <cereal/types/polymorphic.hpp>
@@ -17,7 +18,7 @@ namespace cved {
1718
ScriptCurve() : script_{DEFAULT_SCRIPT}
1819
{}
1920

20-
std::string get_type() const noexcept override { return "script"; }
21+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_SCRIPT; }
2122
double curve_function(double, double start, double) const noexcept override;
2223
void clear() noexcept override { script_ = DEFAULT_SCRIPT; }
2324
bool is_default() const noexcept override { return true; }

curve_editor/curve_value.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "constants.hpp"
34
#include "curve_graph.hpp"
45
#include "enum.hpp"
56

@@ -18,7 +19,7 @@ namespace cved {
1819

1920
ValueCurve(const ValueCurve& curve) noexcept;
2021

21-
std::string get_type() const noexcept override { return "value"; }
22+
constexpr std::string get_type() const noexcept override { return global::CURVE_NAME_VALUE; }
2223

2324
double curve_function(double progress, double start, double end) const noexcept override;
2425
void clear() noexcept override;

curve_editor/lua_export.cpp

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "config.hpp"
12
#include "constants.hpp"
23
#include "curve_bezier.hpp"
34
#include "curve_editor.hpp"
@@ -9,35 +10,81 @@
910
namespace cved {
1011
// カーブの値を取得
1112
int get_curve(::lua_State* L) {
12-
// mode: 編集モード
13+
// mode: 編集モード(数値または文字列)
1314
// parameter: カーブのコードまたはID
1415
// progress: 進捗(0~1)
1516
// start: トラックバーでの開始時の値
1617
// end: トラックバーでの終了時の値
17-
const int mode = ::lua_tointeger(L, 1);
1818
const int parameter = ::lua_tointeger(L, 2);
1919
const double progress = ::lua_tonumber(L, 3);
2020
const double start = ::lua_tonumber(L, 4);
2121
const double end = ::lua_tonumber(L, 5);
2222
double ret = 0.;
23+
EditMode mode;
24+
25+
if (::lua_isnumber(L, 1)) {
26+
int mode_int = ::lua_tointeger(L, 1);
27+
switch (mode_int) {
28+
case 0:
29+
mode = EditMode::Bezier;
30+
break;
31+
case 1:
32+
mode = EditMode::Normal;
33+
break;
34+
case 2:
35+
mode = EditMode::Value;
36+
break;
37+
case 3:
38+
mode = EditMode::Elastic;
39+
break;
40+
case 4:
41+
mode = EditMode::Bounce;
42+
break;
43+
case 5:
44+
mode = EditMode::Script;
45+
break;
46+
default:
47+
::lua_pushnil(L);
48+
return 1;
49+
}
50+
}
51+
else if (::lua_isstring(L, 1)) {
52+
auto mode_str = ::lua_tolstring(L, 1, NULL);
53+
if (::strcmp(mode_str, global::CURVE_NAME_NORMAL) == 0) {
54+
mode = EditMode::Normal;
55+
}
56+
else if (::strcmp(mode_str, global::CURVE_NAME_VALUE) == 0) {
57+
mode = EditMode::Value;
58+
}
59+
else if (::strcmp(mode_str, global::CURVE_NAME_BEZIER) == 0) {
60+
mode = EditMode::Bezier;
61+
}
62+
else if (::strcmp(mode_str, global::CURVE_NAME_ELASTIC) == 0) {
63+
mode = EditMode::Elastic;
64+
}
65+
else if (::strcmp(mode_str, global::CURVE_NAME_BOUNCE) == 0) {
66+
mode = EditMode::Bounce;
67+
}
68+
else if (::strcmp(mode_str, global::CURVE_NAME_SCRIPT) == 0) {
69+
mode = EditMode::Script;
70+
}
71+
else {
72+
::lua_pushnil(L);
73+
return 1;
74+
}
75+
}
76+
else {
77+
::lua_pushnil(L);
78+
return 1;
79+
}
2380

2481
// Numeric Typeのカーブのオブジェクトを用意しておく
2582
static BezierCurve curve_bezier;
2683
static ElasticCurve curve_elastic;
2784
static BounceCurve curve_bounce;
2885

2986
switch (mode) {
30-
// ベジェ
31-
case 0:
32-
if (!curve_bezier.decode(parameter)) {
33-
::lua_pushnil(L);
34-
return 1;
35-
}
36-
ret = curve_bezier.get_value(progress, start, end);
37-
break;
38-
39-
// 標準
40-
case 1:
87+
case EditMode::Normal:
4188
{
4289
int idx = parameter - 1;
4390
if (idx < 0) {
@@ -55,32 +102,36 @@ namespace cved {
55102
break;
56103
}
57104

58-
// 値指定
59-
case 2:
105+
case EditMode::Value:
60106
::lua_pushnil(L);
61107
return 1;
62108
break;
63109

64-
// 振動
65-
case 3:
110+
case EditMode::Bezier:
111+
if (!curve_bezier.decode(parameter)) {
112+
::lua_pushnil(L);
113+
return 1;
114+
}
115+
ret = curve_bezier.get_value(progress, start, end);
116+
break;
117+
118+
case EditMode::Elastic:
66119
if (!curve_elastic.decode(parameter)) {
67120
::lua_pushnil(L);
68121
return 1;
69122
}
70123
ret = curve_elastic.get_value(progress, start, end);
71124
break;
72125

73-
// バウンス
74-
case 4:
126+
case EditMode::Bounce:
75127
if (!curve_bounce.decode(parameter)) {
76128
::lua_pushnil(L);
77129
return 1;
78130
}
79131
ret = curve_bounce.get_value(progress, start, end);
80132
break;
81133

82-
// スクリプト
83-
case 5:
134+
case EditMode::Script:
84135
{
85136
int idx = parameter - global::IDCURVE_MAX_N - 1;
86137
if (idx < 0) {
@@ -108,17 +159,24 @@ namespace cved {
108159
}
109160

110161

162+
int get_edit_mode(::lua_State* L) {
163+
::lua_pushstring(L, global::config.get_edit_mode_str());
164+
return 1;
165+
}
166+
167+
111168
int get_version_str(::lua_State* L) {
112169
::lua_pushstring(L, cved::global::PLUGIN_VERSION.str().c_str());
113170
return 1;
114171
}
115172
}
116173

117174

118-
extern "C" __declspec(dllexport) int luaopen_curve_editor(::lua_State * L)
175+
extern "C" __declspec(dllexport) int luaopen_curve_editor(::lua_State* L)
119176
{
120177
static ::luaL_Reg functions[] = {
121178
{ "getcurve", cved::get_curve },
179+
{ "geteditmode", cved::get_edit_mode },
122180
{ "getversionstr", cved::get_version_str },
123181
{ nullptr, nullptr }
124182
};

0 commit comments

Comments
 (0)