Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/scripting/StarLuaGameConverters.hpp
blob: e1d5d2282dcf8e392bb46f0e58923aa967dccc7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#pragma once

#include "StarLuaConverters.hpp"
#include "StarInventoryTypes.hpp"
#include "StarCollisionBlock.hpp"
#include "StarPlatformerAStar.hpp"
#include "StarActorMovementController.hpp"
#include "StarDamage.hpp"
#include "StarCollectionDatabase.hpp"
#include "StarBehaviorState.hpp"
#include "StarSystemWorld.hpp"
#include "StarDrawable.hpp"
#include "StarRpcThreadPromise.hpp"

namespace Star {

template <>
struct LuaConverter<InventorySlot> {
  static LuaValue from(LuaEngine& engine, InventorySlot k);
  static Maybe<InventorySlot> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<CollisionKind> {
  static LuaValue from(LuaEngine& engine, CollisionKind k);
  static Maybe<CollisionKind> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<CollisionSet> {
  static LuaValue from(LuaEngine& engine, CollisionSet const& s);
  static Maybe<CollisionSet> to(LuaEngine& engine, LuaValue const& v);
};

template <typename T>
struct LuaConverter<RpcPromise<T>> : LuaUserDataConverter<RpcPromise<T>> {};

template <typename T>
struct LuaUserDataMethods<RpcPromise<T>> {
  static LuaMethods<RpcPromise<T>> make();
};

template <typename T>
struct LuaConverter<RpcThreadPromise<T>> : LuaUserDataConverter<RpcThreadPromise<T>> {};

template <typename T>
struct LuaUserDataMethods<RpcThreadPromise<T>> {
  static LuaMethods<RpcThreadPromise<T>> make();
};

template <>
struct LuaConverter<PlatformerAStar::Path> {
  static LuaValue from(LuaEngine& engine, PlatformerAStar::Path const& path);
};

template <>
struct LuaConverter<PlatformerAStar::PathFinder> : LuaUserDataConverter<PlatformerAStar::PathFinder> {};

template <>
struct LuaUserDataMethods<PlatformerAStar::PathFinder> {
  static LuaMethods<PlatformerAStar::PathFinder> make();
};

template <>
struct LuaConverter<PlatformerAStar::Parameters> {
  static Maybe<PlatformerAStar::Parameters> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<ActorJumpProfile> {
  static LuaValue from(LuaEngine& engine, ActorJumpProfile const& v);
  static Maybe<ActorJumpProfile> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<ActorMovementParameters> {
  static LuaValue from(LuaEngine& engine, ActorMovementParameters const& v);
  static Maybe<ActorMovementParameters> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<ActorMovementModifiers> {
  static LuaValue from(LuaEngine& engine, ActorMovementModifiers const& v);
  static Maybe<ActorMovementModifiers> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<StatModifier> {
  static LuaValue from(LuaEngine& engine, StatModifier const& v);
  static Maybe<StatModifier> to(LuaEngine& engine, LuaValue v);
};

template <>
struct LuaConverter<EphemeralStatusEffect> {
  static LuaValue from(LuaEngine& engine, EphemeralStatusEffect const& v);
  static Maybe<EphemeralStatusEffect> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<DamageRequest> {
  static LuaValue from(LuaEngine& engine, DamageRequest const& v);
  static Maybe<DamageRequest> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<DamageNotification> {
  static LuaValue from(LuaEngine& engine, DamageNotification const& v);
  static Maybe<DamageNotification> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<LiquidLevel> {
  static LuaValue from(LuaEngine& engine, LiquidLevel const& v);
  static Maybe<LiquidLevel> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<Drawable> {
  static LuaValue from(LuaEngine& engine, Drawable const& v);
  static Maybe<Drawable> to(LuaEngine& engine, LuaValue const& v);
};

template <typename T>
LuaMethods<RpcPromise<T>> LuaUserDataMethods<RpcPromise<T>>::make() {
  LuaMethods<RpcPromise<T>> methods;
  methods.template registerMethodWithSignature<bool, RpcPromise<T>&>("finished", mem_fn(&RpcPromise<T>::finished));
  methods.template registerMethodWithSignature<bool, RpcPromise<T>&>("succeeded", mem_fn(&RpcPromise<T>::succeeded));
  methods.template registerMethodWithSignature<Maybe<T>, RpcPromise<T>&>("result", mem_fn(&RpcPromise<T>::result));
  methods.template registerMethodWithSignature<Maybe<String>, RpcPromise<T>&>("error", mem_fn(&RpcPromise<T>::error));
  return methods;
}

template <typename T>
LuaMethods<RpcThreadPromise<T>> LuaUserDataMethods<RpcThreadPromise<T>>::make() {
  LuaMethods<RpcThreadPromise<T>> methods;
  methods.template registerMethodWithSignature<bool, RpcThreadPromise<T>&>("finished", mem_fn(&RpcThreadPromise<T>::finished));
  methods.template registerMethodWithSignature<bool, RpcThreadPromise<T>&>("succeeded", mem_fn(&RpcThreadPromise<T>::succeeded));
  methods.template registerMethodWithSignature<Maybe<T>, RpcThreadPromise<T>&>("result", mem_fn(&RpcThreadPromise<T>::result));
  methods.template registerMethodWithSignature<Maybe<String>, RpcThreadPromise<T>&>("error", mem_fn(&RpcThreadPromise<T>::error));
  return methods;
}

template <>
struct LuaConverter<Collection> {
  static LuaValue from(LuaEngine& engine, Collection const& c);
  static Maybe<Collection> to(LuaEngine& engine, LuaValue const& v);
};

template <>
struct LuaConverter<Collectable> {
  static LuaValue from(LuaEngine& engine, Collectable const& c);
  static Maybe<Collectable> to(LuaEngine& engine, LuaValue const& v);
};

// BehaviorState contains Lua references, putting it in a UserData violates
// the "don't put lua references in userdata, just don't" rule. We get around it by keeping
// a weak pointer to the behavior state, forcing it to be destroyed elsewhere.
template <>
struct LuaConverter<BehaviorStateWeakPtr> : LuaUserDataConverter<BehaviorStateWeakPtr> {};

template <>
struct LuaUserDataMethods<BehaviorStateWeakPtr> {
  static LuaMethods<BehaviorStateWeakPtr> make();
};

template <>
struct LuaConverter<NodeStatus> {
  static LuaValue from(LuaEngine& engine, NodeStatus const& status);
  static NodeStatus to(LuaEngine& engine, LuaValue const& v);
};

// Weak pointer for the same reasons as BehaviorState.
template <>
struct LuaConverter<BlackboardWeakPtr> : LuaUserDataConverter<BlackboardWeakPtr> {};

template <>
struct LuaUserDataMethods<BlackboardWeakPtr> {
  static LuaMethods<BlackboardWeakPtr> make();
};

}