/* * 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. * * v1.1.0 (additive; every v1.0.0 export and the render list are unchanged) adds the TV * form factor: a PURE-FUNCTION focus graph over the render list (D-pad neighbours, default * focus, restore-on-back) and one remote-action vocabulary with key maps for a keyboard, * the Xbox gamepad, the Siri Remote, Android TV/Fire TV and HDMI-CEC user-control codes. * A shell translates its native event into an action name and calls sptpl_focus_apply(); * it holds no focus logic of its own. SPEC.md R31-R40. */ #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) */ /* ==================================================================== v1.1.0 - TV ====== * Additive. Nothing above changes: same bundle, same render, same render list, same verdicts. * What is new is a second, PURE layer over the render list: where focus can go, and what a * remote control press means. The shell owns pixels and native events only. * -------------------------------------------------------------------------------------- */ /* ---- form factor: which layout policy the focus layer applies (SPEC R31) ---- */ SPTPL_API int sptpl_set_form_factor(const char *ff); /* "handheld" | "desktop" | "tv" (default "desktop") */ SPTPL_API const char *sptpl_form_factor(void); SPTPL_API int sptpl_set_tv_columns(int n); /* explicit columns; 0 = derive from UseGrid/SuggestColumnCount */ SPTPL_API int sptpl_set_tv_rows(int n); /* rows on one screen (pageup/pagedown stride); default 10 */ SPTPL_API int sptpl_set_tv_safe_inset(int pct); /* TV-safe margin percent, reported not applied; default 5 */ SPTPL_API int sptpl_tv_columns(void); /* the resolved column count of the current page */ SPTPL_API int sptpl_tv_rows(void); SPTPL_API const char *sptpl_tv_layout_json(void); /* per-section {key,cols,rows,items,pages,first} */ /* ---- focus graph over the CURRENT render list (SPEC R32-R38) ---- * sptpl_focus_build() renders the template/page and builds the graph in one call, so the * list the shell draws and the graph it navigates can never disagree. Every other focus * export below operates on that graph and is a pure function of it: same call, same answer. * A focus entry index is a *focus* index (0..focus_count-1), not a render-list index. */ SPTPL_API int sptpl_focus_build(const char *template_name, const char *page_key); SPTPL_API int sptpl_focus_count(void); /* focusable nodes on this page */ SPTPL_API const char *sptpl_focus_field(int i, const char *field); /* see the field list below */ SPTPL_API const char *sptpl_focus_json(void); /* the whole graph */ SPTPL_API int sptpl_focus_default(void); /* index of the node focus starts on; -1 none */ SPTPL_API int sptpl_focus_index(void); /* index currently focused; -1 none */ SPTPL_API int sptpl_focus_set(int i); /* 0 ok, 1 out of range */ SPTPL_API int sptpl_focus_move(int i, const char *direction); /* -> new index, -1 no move */ SPTPL_API int sptpl_focus_find(const char *path); /* render path ("IMDbId/Continue") -> index, -1 */ SPTPL_API int sptpl_focus_parent(int i); /* enclosing page item focus index, -1 at root */ SPTPL_API const char *sptpl_focus_child_page(int i); /* page key to enter (root-relative); "" when not a page */ SPTPL_API int sptpl_focus_enter(int i); /* 0 entered (push + render child + its default focus), 1 not a page */ SPTPL_API int sptpl_focus_back(void); /* pop, re-render, restore the focus that was left; 1 at root */ SPTPL_API const char *sptpl_focus_root(void); /* template of the bottom nav entry */ SPTPL_API int sptpl_focus_unreachable_count(void); /* nodes no D-pad route reaches from default focus */ SPTPL_API const char *sptpl_focus_unreachable(int k); SPTPL_API int sptpl_focus_apply(const char *action); /* THE shell entry point: nav|confirm|back|menu|page±|search + none */ /* ---- navigation stack (SPEC R39) ---- * Every entry is {template, page, focus_path, focus_index}. sptpl_focus_enter/back drive it; * a shell that renders its own page transitions may push/pop directly instead. */ SPTPL_API int sptpl_nav_push(const char *template_name, const char *page_key, const char *focus_path); SPTPL_API int sptpl_nav_back(void); /* 0 popped (see sptpl_nav_field(depth,"popped_*")), 1 stack was empty */ SPTPL_API void sptpl_nav_clear(void); SPTPL_API int sptpl_nav_depth(void); SPTPL_API const char *sptpl_nav_field(int i, const char *field); /* template page focus_path focus_index; * popped_path / popped_index are read at i == sptpl_nav_depth() and describe the last back() */ /* ---- remote action vocabulary (SPEC R40) ---- * One name per thing a remote can do; five key maps translate native codes into those names. * A shell turns its event into the name, then calls sptpl_focus_apply(name). Nothing else. */ SPTPL_API int sptpl_action_count(void); /* distinct actions */ SPTPL_API const char *sptpl_action_field(int i, const char *field); /* name legacy direction family description */ SPTPL_API int sptpl_action_find(const char *name); /* index, -1 unknown */ SPTPL_API const char *sptpl_action_from_key(const char *map, const char *key); /* map: keyboard | xbox | siri | androidtv | cec * keyboard : VirtualKey name ("Up","GamepadA","PageDown",...) * xbox : Windows.System.VirtualKey numeric 195..208 accepted here too * siri : "up","down","left","right","select","menu","playpause","home","back" * androidtv : Android KEYCODE name ("DPAD_UP","DPAD_CENTER",...) or numeric code * cec : HDMI-CEC 1.4 UI Control code, "0x00".."0x76" (hex) or decimal * returns the action name, or NULL when the map has no binding for that key */ SPTPL_API const char *sptpl_action_from_cec(int ui_control_code); /* HDMI-CEC 1.4 §CEC 13 */ SPTPL_API const char *sptpl_action_from_virtual_key(int vk); /* WinRT Windows.System.VirtualKey */ SPTPL_API const char *sptpl_action_from_android_keycode(int keycode); /* android.view.KeyEvent */ SPTPL_API const char *sptpl_action_from_linux_keycode(int keycode); /* linux/input-event-codes.h */ SPTPL_API const char *sptpl_action_key_name(const char *map, const char *action); /* reverse: a printable label */ SPTPL_API const char *sptpl_action_json(void); /* ---- 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 */