/* * sptpl.h — scorpiox-scorpioplayer-template-parse * * SCORPIO PLAYER 2027 dynamic UI template engine. Turns the server-driven * `SetttingsGroup` JSON templates (settings, context menus, onboarding, paywall, * add-server ...) into a flat render list for ONE platform, ONE language and ONE * set of runtime flags. Offline only: no network, no UI, no behaviour. * * Behaviour is specified in SPEC.md (rules R1..R30, each citing * bosxixi.ScorpioPlayer.Core/Toolkit14/TableView.cs @ 820d6c0). The legacy * visibility outcome is reproduced exactly (differential-tested against the real * TableView.cs); the legacy *mutation* of the parsed tree is not: the parsed tree * is immutable and every render is a pure function of (template, context). * * Conventions (everything-is-c-dll-everything-is-testable): * - int status: 0 ok, 1 expected failure (not found / not parseable), -1 error * - every const char * is library-owned and valid until the next call to ANY * sptpl_* export that returns a string. Copy it immediately. * - single-threaded; all state is global. */ #ifndef SPTPL_H #define SPTPL_H #include #ifdef __cplusplus extern "C" { #endif #if defined(SPTPL_STATIC) # define SPTPL_API #elif defined(_WIN32) # if defined(SPTPL_BUILD) # define SPTPL_API __declspec(dllexport) # else # define SPTPL_API __declspec(dllimport) # endif #else # define SPTPL_API __attribute__((visibility("default"))) #endif #define SPTPL_ABI_VERSION 1 /* ---- lifecycle ---- */ SPTPL_API int sptpl_init(void); /* idempotent; resets everything */ SPTPL_API void sptpl_cleanup(void); /* frees everything */ SPTPL_API const char *sptpl_version(void); /* "1.0.0" */ /* ---- bundle ---- * A bundle is the RuntimeTemplates payload: a JSON object {"": ""} * either raw or zlib-compressed (as served by /api/AAA/RuntimeTemplates?zip=true and * shipped as TPlayer/Assets/package/runtimetemplatebundle.txt). Loading REPLACES the * current bundle and its parsed templates. */ SPTPL_API int sptpl_load_bundle_file(const char *path); SPTPL_API int sptpl_load_bundle_bytes(const void *buf, size_t len); SPTPL_API int sptpl_add_template(const char *name, const char *json); /* add/replace one entry */ SPTPL_API int sptpl_entry_count(void); /* every entry (.json, .html, .png ...) */ SPTPL_API const char *sptpl_entry_name(int i); SPTPL_API const char *sptpl_entry_text(const char *name); /* raw content, NULL if absent */ SPTPL_API int sptpl_template_count(void); /* entries whose name ends in ".json" */ SPTPL_API const char *sptpl_template_name(int i); SPTPL_API int sptpl_has_template(const char *name); /* 1 yes, 0 no */ SPTPL_API int sptpl_parse_template(const char *name); /* 0 ok, 1 absent, -1 not a SetttingsGroup */ /* ---- language (strings.json in the bundle) ---- */ SPTPL_API int sptpl_set_language(const char *lang); /* "en", "zh-Hant", "en-NZ" */ SPTPL_API const char *sptpl_language(void); SPTPL_API int sptpl_language_count(void); SPTPL_API const char *sptpl_language_name(int i); SPTPL_API const char *sptpl_translate(const char *key); /* key itself when untranslated */ /* ---- render context ---- */ SPTPL_API int sptpl_set_platform(const char *platform); /* UWP | iOS | tvOS | Droid | SkiaMacOS */ SPTPL_API int sptpl_set_device(const char *device); /* UWP Plat: Desktop | Xbox | ... (NULL = none) */ SPTPL_API int sptpl_set_edition(const char *edition); /* UWP PlatEdition, e.g. "XboxEdition" (NULL = none) */ SPTPL_API int sptpl_set_app_version(const char *version);/* "2.10.1038.0" (NULL = no version capping) */ SPTPL_API int sptpl_set_flag(const char *key, const char *value); /* runtime flag; value NULL removes */ SPTPL_API void sptpl_clear_flags(void); SPTPL_API int sptpl_flag_count(void); SPTPL_API int sptpl_set_global_flags_enabled(int on); /* legacy Initializer.HasFeatureFlag installed? default 1 */ SPTPL_API int sptpl_set_global_flag(const char *name, int on); SPTPL_API void sptpl_clear_global_flags(void); SPTPL_API int sptpl_use_bundle_feature_flags(void); /* ffsp.json DefaultValue -> global flags; returns count true */ SPTPL_API int sptpl_set_clean_empty(int on); /* Clean(cleanEmptyContainer), default 1 */ SPTPL_API int sptpl_set_max_depth(int depth); /* nested groups emitted; -1 = all (default), 0 = page only */ /* ---- render: PURE. Same inputs -> same output; never mutates the parsed tree ---- * page_key: NULL/"" = template root, else "Key/Key/..." path of VISIBLE items that carry a Group. * section_key (render_section only): keep only the section(s) of the page with that Key. */ SPTPL_API int sptpl_render(const char *template_name, const char *page_key); SPTPL_API int sptpl_render_section(const char *template_name, const char *page_key, const char *section_key); SPTPL_API int sptpl_node_count(void); SPTPL_API const char *sptpl_node_field(int i, const char *field); /* field: kind(section|item) key type display text subtitle placeholder default icon * fallback_icon_url handler url feature_flag verdict depth parent path * section section_text has_group group_key group_text group_type group_use_grid * values_count * ext.. (e.g. ext.iOS.Icon, ext.UWP.TextColor, ext.FeatureFlag, ext.Clean) * am. (AdvanceMenu: am.Url, am.NativeHandlerCode, am.UseWebView ...) * rs. (RuntimeSettings, case-sensitive: rs.ID) * unknown field / out-of-range index -> NULL; absent value -> "" */ SPTPL_API int sptpl_node_field_is_null(int i, const char *field); /* 1 C# null, 0 has a value ("" included), -1 bad args */ SPTPL_API int sptpl_node_value_count(int i); SPTPL_API const char *sptpl_node_value_field(int i, int v, const char *field); SPTPL_API const char *sptpl_result_json(void); /* whole render list (yyjson) */ /* ---- pure helpers (exposed so every rule is unit-testable from any binding) ---- */ SPTPL_API int sptpl_version_parse(const char *v); /* 0 parseable (.NET Version.TryParse), 1 not */ SPTPL_API const char *sptpl_version_normalized(void); /* last parse: "a.b.c.d" with -1 for absent */ SPTPL_API int sptpl_version_compare(const char *a, const char *b); /* -1/0/1, -2 unparseable */ SPTPL_API int sptpl_has_feature_flag(const char *flag); /* TableView.HasFeatureFlag vs runtime flags: 1/0 */ SPTPL_API int sptpl_eval_global_flag(const char *flag); /* the Initializer.HasFeatureFlag stand-in: 1/0 */ /* ---- diagnostics ---- */ SPTPL_API int sptpl_warning_count(void); /* tolerated oddities from the last parse/render */ SPTPL_API const char *sptpl_warning(int i); SPTPL_API const char *sptpl_last_error(void); #ifdef __cplusplus } #endif #endif /* SPTPL_H */