Skip to content

Commit 9c1c3a6

Browse files
authored
feat: implement legacy association api (#226)
1 parent 468f45e commit 9c1c3a6

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

parse-resolver-runtime/assoc.cc

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <algorithm>
77
#include <utility>
88
#include <memory>
9+
#include <stdexcept>
910
#include "parse-resolver-runtime/ids.hh"
1011
#include "parse-resolver-runtime/lifecycle.hh"
1112

@@ -325,3 +326,103 @@ void ecsact_meta_system_assoc_capabilities(
325326
out_capabilities[i] = info->caps[i].second;
326327
}
327328
}
329+
330+
static auto get_legacy_assoc_info( //
331+
ecsact_system_like_id id
332+
) -> std::shared_ptr<assoc_info> {
333+
auto list = get_system_assoc_list(id);
334+
if(!list || list->empty()) {
335+
return {};
336+
}
337+
// shouldn't be using the legacy API!
338+
if(list->size() > 1) {
339+
throw std::logic_error{"invalid use of legacy api"};
340+
}
341+
return list->at(0);
342+
}
343+
344+
[[deprecated]]
345+
int32_t ecsact_meta_system_association_fields_count(
346+
ecsact_system_like_id system_id,
347+
ecsact_component_like_id component_id
348+
) {
349+
auto info = get_legacy_assoc_info(system_id);
350+
if(component_id != info->comp_id) {
351+
// shouldn't be using the legacy API!
352+
throw std::logic_error{"(legacy api) invalid association component"};
353+
}
354+
355+
return static_cast<int32_t>(info->assoc_fields.size());
356+
}
357+
358+
[[deprecated]]
359+
void ecsact_meta_system_association_fields(
360+
ecsact_system_like_id system_id,
361+
ecsact_component_like_id component_id,
362+
int32_t max_fields_count,
363+
ecsact_field_id* out_fields,
364+
int32_t* out_fields_count
365+
) {
366+
auto info = get_legacy_assoc_info(system_id);
367+
if(component_id != info->comp_id) {
368+
// shouldn't be using the legacy API!
369+
throw std::logic_error{"(legacy api) invalid association component"};
370+
}
371+
ecsact_meta_system_assoc_fields(
372+
system_id,
373+
info->id,
374+
max_fields_count,
375+
out_fields,
376+
out_fields_count
377+
);
378+
}
379+
380+
[[deprecated]]
381+
int32_t ecsact_meta_system_association_capabilities_count(
382+
ecsact_system_like_id system_id,
383+
ecsact_component_like_id component_id,
384+
ecsact_field_id field_id
385+
) {
386+
auto info = get_legacy_assoc_info(system_id);
387+
if(component_id != info->comp_id) {
388+
// shouldn't be using the legacy API!
389+
throw std::logic_error{"(legacy api) invalid association component"};
390+
}
391+
return ecsact_meta_system_assoc_capabilities_count(system_id, info->id);
392+
}
393+
394+
[[deprecated]]
395+
void ecsact_meta_system_association_capabilities(
396+
ecsact_system_like_id system_id,
397+
ecsact_component_like_id component_id,
398+
ecsact_field_id field_id,
399+
int32_t max_capabilities_count,
400+
ecsact_component_like_id* out_capability_component_ids,
401+
ecsact_system_capability* out_capabilities,
402+
int32_t* out_capabilities_count
403+
) {
404+
auto info = get_legacy_assoc_info(system_id);
405+
if(component_id != info->comp_id) {
406+
// shouldn't be using the legacy API!
407+
throw std::logic_error{"(legacy api) invalid association component"};
408+
}
409+
if(info->assoc_fields.size() != 1) {
410+
// shouldn't be using the legacy API!
411+
throw std::logic_error{
412+
"(legacy api) doesn't support multi field association"
413+
};
414+
}
415+
if(info->assoc_fields.at(0) != field_id) {
416+
// shouldn't be using the legacy API!
417+
throw std::logic_error{"(legacy api) invalid association field"};
418+
}
419+
420+
ecsact_meta_system_assoc_capabilities(
421+
system_id,
422+
info->id,
423+
max_capabilities_count,
424+
out_capability_component_ids,
425+
out_capabilities,
426+
out_capabilities_count
427+
);
428+
}

0 commit comments

Comments
 (0)