Skip to content

Commit

Permalink
added native-review-request to replace old hand-rolled one
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Nov 9, 2023
1 parent 3106604 commit 8fd4c45
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 39 deletions.
56 changes: 28 additions & 28 deletions .efrocachemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.7.28 (build 21578, api 8, 2023-11-09)
### 1.7.28 (build 21581, api 8, 2023-11-09)

- Massively cleaned up code related to rendering and window systems (OpenGL,
SDL, etc). This code had been growing into a nasty tangle for 15 years
Expand Down
4 changes: 4 additions & 0 deletions src/assets/ba_data/python/babase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
music_player_set_volume,
music_player_shutdown,
music_player_stop,
native_review_request,
native_review_request_supported,
native_stack_trace,
print_load_info,
pushcall,
Expand Down Expand Up @@ -276,6 +278,8 @@
'music_player_set_volume',
'music_player_shutdown',
'music_player_stop',
'native_review_request',
'native_review_request_supported',
'native_stack_trace',
'NodeNotFoundError',
'normalized_color',
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/babase/_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Callable


DEBUG_LOG = True
DEBUG_LOG = False


class LoginAdapter:
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/baenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 21578
TARGET_BALLISTICA_BUILD = 21581
TARGET_BALLISTICA_VERSION = '1.7.28'


Expand Down
4 changes: 4 additions & 0 deletions src/assets/ba_data/python/bauiv1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
lock_all_input,
LoginAdapter,
Lstr,
native_review_request,
native_review_request_supported,
NotFoundError,
Permission,
Plugin,
Expand Down Expand Up @@ -191,6 +193,8 @@
'LoginAdapter',
'Lstr',
'Mesh',
'native_review_request',
'native_review_request_supported',
'NotFoundError',
'open_file_externally',
'open_url',
Expand Down
20 changes: 14 additions & 6 deletions src/assets/ba_data/python/bauiv1lib/specialoffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,13 @@ def show_offer() -> bool:
assert plus is not None

app = bui.app
assert app.classic is not None
if app.classic is None:
raise RuntimeError(
'Classic feature-set is required to show offers.'
)

# Space things out a bit so we don't hit the poor user with an ad and
# then an in-game offer.
# Space things out a bit so we don't hit the poor user with an
# ad and then an in-game offer.
has_been_long_enough_since_ad = True
if app.classic.ads.last_ad_completion_time is not None and (
bui.apptime() - app.classic.ads.last_ad_completion_time < 30.0
Expand All @@ -532,8 +535,9 @@ def show_offer() -> bool:
app.classic.special_offer is not None
and has_been_long_enough_since_ad
):
# Special case: for pro offers, store this in our prefs so we
# can re-show it if the user kills us (set phasers to 'NAG'!!!).
# Special case: for pro offers, store this in our prefs so
# we can re-show it if the user kills us (set phasers to
# 'NAG'!!!).
if app.classic.special_offer.get('item') == 'pro_fullprice':
cfg = app.config
cfg['pendingSpecialOffer'] = {
Expand All @@ -543,7 +547,11 @@ def show_offer() -> bool:
cfg.commit()

if app.classic.special_offer['item'] == 'rating':
feedback.ask_for_rating()
# Go with a native thing if we've got one.
if bui.native_review_request_supported():
bui.native_review_request()
else:
feedback.ask_for_rating()
else:
SpecialOfferWindow(app.classic.special_offer)

Expand Down
9 changes: 9 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,13 @@ auto AppAdapter::GetKeyName(int keycode) -> std::string {
return "?";
}

auto AppAdapter::NativeReviewRequestSupported() -> bool { return false; }

void AppAdapter::NativeReviewRequest() {
BA_PRECONDITION(NativeReviewRequestSupported());
PushMainThreadCall([this] { DoNativeReviewRequest(); });
}

void AppAdapter::DoNativeReviewRequest() { FatalError("Fixme unimplemented."); }

} // namespace ballistica::base
12 changes: 11 additions & 1 deletion src/ballistica/base/app_adapter/app_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,15 @@ class AppAdapter {
/// context. By default this is simply the main thread.
virtual void DoPushGraphicsContextRunnable(Runnable* runnable);

// Return a name for a ballistica keyboard keycode.
/// Return a name for a ballistica keyboard keycode.
virtual auto GetKeyName(int keycode) -> std::string;

/// Return whether there is a native 'review-this-app' prompt.
virtual auto NativeReviewRequestSupported() -> bool;

/// Asynchronously kick off a native review request.
void NativeReviewRequest();

protected:
virtual ~AppAdapter();

Expand All @@ -241,6 +247,10 @@ class AppAdapter {
virtual void DoClipboardSetText(const std::string& text);
virtual auto DoClipboardGetText() -> std::string;

/// Override to implement native review requests. Will be called in the
/// main thread.
virtual void DoNativeReviewRequest();

private:
void OnAppSuspend_();
void OnAppUnsuspend_();
Expand Down
17 changes: 17 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter_apple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ auto AppAdapterApple::GetKeyName(int keycode) -> std::string {
return MinSDL_GetKeyName(keycode);
}

auto AppAdapterApple::NativeReviewRequestSupported() -> bool {
// StoreKit currently supports this everywhere except tvOS.
if (g_buildconfig.xcode_build() && g_buildconfig.use_store_kit()
&& !g_buildconfig.ostype_tvos()) {
return true;
}
return false;
}

void AppAdapterApple::DoNativeReviewRequest() {
#if BA_XCODE_BUILD && BA_USE_STORE_KIT && !BA_OSTYPE_TVOS
BallisticaKit::StoreKitContext::requestReview();
#else
FatalError("This should not be getting called.");
#endif
}

} // namespace ballistica::base

#endif // BA_XCODE_BUILD
2 changes: 2 additions & 0 deletions src/ballistica/base/app_adapter/app_adapter_apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AppAdapterApple : public AppAdapter {
auto GetKeyRepeatDelay() -> float override;
auto GetKeyRepeatInterval() -> float override;
auto GetKeyName(int keycode) -> std::string override;
auto NativeReviewRequestSupported() -> bool override;

protected:
void DoPushMainThreadRunnable(Runnable* runnable) override;
Expand All @@ -60,6 +61,7 @@ class AppAdapterApple : public AppAdapter {
auto DoClipboardHasText() -> bool override;
void DoClipboardSetText(const std::string& text) override;
auto DoClipboardGetText() -> std::string override;
void DoNativeReviewRequest() override;

private:
class ScopedAllowGraphics_;
Expand Down
41 changes: 41 additions & 0 deletions src/ballistica/base/python/methods/python_methods_misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,45 @@ static PyMethodDef PyUsingGameCenterDef = {
"(internal)",
};

// --------------------- native_review_request_supported -----------------------

static auto PyNativeReviewRequestSupported(PyObject* self) -> PyObject* {
BA_PYTHON_TRY;
if (g_base->app_adapter->NativeReviewRequestSupported()) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
BA_PYTHON_CATCH;
}

static PyMethodDef PyNativeReviewRequestSupportedDef = {
"native_review_request_supported", // name
(PyCFunction)PyNativeReviewRequestSupported, // method
METH_NOARGS, // flags

"native_review_request_supported() -> bool\n"
"\n"
"(internal)",
};

// -------------------------- native_review_request ----------------------------

static auto PyNativeReviewRequest(PyObject* self) -> PyObject* {
BA_PYTHON_TRY;
g_base->app_adapter->NativeReviewRequest();
Py_RETURN_NONE;
BA_PYTHON_CATCH;
}

static PyMethodDef PyNativeReviewRequestDef = {
"native_review_request", // name
(PyCFunction)PyNativeReviewRequest, // method
METH_NOARGS, // flags

"native_review_request() -> None\n"
"\n"
"(internal)",
};
// -----------------------------------------------------------------------------

auto PythonMethodsMisc::GetMethods() -> std::vector<PyMethodDef> {
Expand Down Expand Up @@ -1789,6 +1828,8 @@ auto PythonMethodsMisc::GetMethods() -> std::vector<PyMethodDef> {
PyAssetLoadsAllowedDef,
PyUsingGooglePlayGameServicesDef,
PyUsingGameCenterDef,
PyNativeReviewRequestSupportedDef,
PyNativeReviewRequestDef,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/ballistica/shared/ballistica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int {
namespace ballistica {

// These are set automatically via script; don't modify them here.
const int kEngineBuildNumber = 21578;
const int kEngineBuildNumber = 21581;
const char* kEngineVersion = "1.7.28";
const int kEngineApiVersion = 8;

Expand Down

0 comments on commit 8fd4c45

Please sign in to comment.