Skip to content

Commit

Permalink
update and cleanup functino naming changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ppiecuch committed Nov 21, 2023
1 parent 61ae0a8 commit fb23522
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 146 deletions.
8 changes: 4 additions & 4 deletions modules/gdextensions/submodules/silentwolf/silent_wolf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static const char *SWKeyNames[] = {
};
static_assert(sizeof(SWKeyNames) / sizeof(const char *) == key_index_count, "Check enum values and enum names");

const Dictionary SilentWolf::config = helper::dict(
const Dictionary SilentWolf::config = make_dict(
"api_key", "ySX34qsKaT7RH1j6795tQ8lPqKlRmQlx55yxkwGy",
"game_id", "sdktest",
"game_version", "2.0.0",
Expand All @@ -64,7 +64,7 @@ const Dictionary SilentWolf::config = helper::dict(
#endif
);

const Dictionary SilentWolf::auth_config = helper::dict(
const Dictionary SilentWolf::auth_config = make_dict(
"session_duration_seconds", 0,
"saved_session_expiration_days", 30);

Expand Down Expand Up @@ -209,7 +209,7 @@ void SilentWolf::configure_session_expiration_days(int expiration) {
}

void SilentWolf::send_get_request(Ref<BasicHTTPRequest> http_node, const String &request_url) {
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
"x-api-key: " + get_cfg_str("api_key"),
"x-sw-game-id: " + get_cfg_str("game_id"),
"x-sw-plugin-version: " + version,
Expand All @@ -221,7 +221,7 @@ void SilentWolf::send_get_request(Ref<BasicHTTPRequest> http_node, const String
}

void SilentWolf::send_post_request(Ref<BasicHTTPRequest> http_node, const String &request_url, const Dictionary &payload) {
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
String("Content-Type: application/json"),
"x-api-key: " + get_cfg_str("api_key"),
"x-sw-game-id: " + get_cfg_str("game_id"),
Expand Down
44 changes: 22 additions & 22 deletions modules/gdextensions/submodules/silentwolf/sw_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void SW_Auth::sw_notification(int what) {
if (what == SW_NOTIFICATION_PROCESS) {
if (requesting) {
int check = 0; // any active request
for (auto &http_req : helper::vector(RegisterPlayer, VerifyEmail, ResendConfCode, LoginPlayer, RequestPasswordReset, ResetPassword, GetPlayerDetails, ValidateSession)) {
for (auto &http_req : make_vector(RegisterPlayer, VerifyEmail, ResendConfCode, LoginPlayer, RequestPasswordReset, ResetPassword, GetPlayerDetails, ValidateSession)) {
if (http_req) {
check += http_req->poll();
}
Expand Down Expand Up @@ -93,9 +93,9 @@ SW_Auth *SW_Auth::register_player_anon(const String &player_name) {
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "anon", true, "player_name", player_name, "user_local_id", user_local_id);
Dictionary payload = make_dict("game_id", game_id, "anon", true, "player_name", player_name, "user_local_id", user_local_id);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
String(application_json),
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -117,9 +117,9 @@ SW_Auth *SW_Auth::register_player(const String &player_name, const String &email
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "anon", false, "player_name", player_name, "email", email, "password", password, "confirm_password", confirm_password);
Dictionary payload = make_dict("game_id", game_id, "anon", false, "player_name", player_name, "email", email, "password", password, "confirm_password", confirm_password);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -141,9 +141,9 @@ SW_Auth *SW_Auth::register_player_user_password(const String &player_name, const
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "player_name", player_name, "password", password, "confirm_password", confirm_password);
Dictionary payload = make_dict("game_id", game_id, "player_name", player_name, "password", password, "confirm_password", confirm_password);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -165,9 +165,9 @@ SW_Auth *SW_Auth::verify_email(const String &player_name, const String &code) {
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "username", player_name, "code", code);
Dictionary payload = make_dict("game_id", game_id, "username", player_name, "code", code);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -188,9 +188,9 @@ SW_Auth *SW_Auth::resend_conf_code(const String &player_name) {
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "username", player_name);
Dictionary payload = make_dict("game_id", game_id, "username", player_name);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -211,13 +211,13 @@ SW_Auth *SW_Auth::login_player(const String &username, const String &password, b
sw_info("Calling SilentWolf to log in a player");
String game_id = SilentWolf::config["game_id"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "username", username, "password", password, "remember_me", remember_me);
Dictionary payload = make_dict("game_id", game_id, "username", username, "password", password, "remember_me", remember_me);
if (SilentWolf::auth_config.has("saved_session_expiration_days")) {
payload["remember_me_expires_in"] = SilentWolf::auth_config["saved_session_expiration_days"];
}
sw_debug("SilentWolf login player payload: ", payload);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -237,10 +237,10 @@ SW_Auth *SW_Auth::request_player_password_reset(const String &player_name) {
sw_info("Calling SilentWolf to request a password reset for: ", player_name);
String game_id = SilentWolf::config["game_id"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "player_name", player_name);
Dictionary payload = make_dict("game_id", game_id, "player_name", player_name);
sw_debug("SilentWolf request player password reset payload: ", payload);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -259,10 +259,10 @@ SW_Auth *SW_Auth::reset_player_password(const String &player_name, const String
sw_info("Calling SilentWolf to reset password for: ", player_name);
String game_id = SilentWolf::config["game_id"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "player_name", player_name, "conf_code", conf_code, "password", new_password, "confirm_password", confirm_password);
Dictionary payload = make_dict("game_id", game_id, "player_name", player_name, "conf_code", conf_code, "password", new_password, "confirm_password", confirm_password);
sw_debug("SilentWolf request player password reset payload: ", payload);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -282,9 +282,9 @@ SW_Auth *SW_Auth::get_player_details(const String &player_name) {
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "player_name", player_name);
Dictionary payload = make_dict("game_id", game_id, "player_name", player_name);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
Expand All @@ -309,7 +309,7 @@ void SW_Auth::on_login_timeout_complete() {
// store lookup (not logged in player name) and validator in local file
void SW_Auth::save_session(const Dictionary &lookup, const Dictionary &validator) {
String path = "user://swsession.save";
Dictionary session_data = helper::dict(
Dictionary session_data = make_dict(
"lookup", lookup,
"validator", validator);
sw_save_data("user://swsession.save", session_data, "Saving SilentWolf session: ");
Expand Down Expand Up @@ -356,10 +356,10 @@ SW_Auth *SW_Auth::validate_player_session(const Dictionary &lookup, const Dictio
sw_info("Calling SilentWolf to validate an existing player session");
String game_id = SilentWolf::config["game_id"];
String api_key = SilentWolf::config["api_key"];
Dictionary payload = helper::dict("game_id", game_id, "lookup", lookup, "validator", validator);
Dictionary payload = make_dict("game_id", game_id, "lookup", lookup, "validator", validator);
sw_debug("Validate session payload: ", payload);
String query = JSON::print(payload);
Vector<String> headers = helper::vector(application_json, "x-api-key: " + api_key, "x-sw-plugin-version: " + SilentWolf::version);
Vector<String> headers = make_vector(application_json, "x-api-key: " + api_key, "x-sw-plugin-version: " + SilentWolf::version);
ValidateSession->request("https://api.silentwolf.com/validate_remember_me", headers, true, HTTPClient::METHOD_POST, query);
NOTIFY_REQUEST();
}
Expand Down
18 changes: 9 additions & 9 deletions modules/gdextensions/submodules/silentwolf/sw_players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void SW_Player::sw_notification(int what) {
if (what == SW_NOTIFICATION_PROCESS) {
if (requesting) {
int check = 0; // any active request
for (auto &http_req : helper::vector(GetPlayerData, PushPlayerData, RemovePlayerData)) {
for (auto &http_req : make_vector(GetPlayerData, PushPlayerData, RemovePlayerData)) {
if (http_req) {
check += !http_req->poll();
}
Expand All @@ -65,7 +65,7 @@ void SW_Player::clear_player_data() {
Dictionary SW_Player::get_stats() {
Dictionary stats;
if (!player_data.empty()) {
stats = helper::dict(
stats = make_dict(
"strength", player_data["strength"],
"speed", player_data["speed"],
"reflexes", player_data["reflexes"],
Expand All @@ -78,7 +78,7 @@ Dictionary SW_Player::get_stats() {
Dictionary SW_Player::get_inventory() {
Dictionary inventory;
if (!player_data.empty()) {
inventory = helper::dict(
inventory = make_dict(
"weapons", player_data["weapons"],
"gold", player_data["gold"]);
}
Expand All @@ -95,7 +95,7 @@ SW_Player *SW_Player::get_player_data(const String &player_name) {
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
"x-sw-game-id: " + game_id,
Expand All @@ -114,20 +114,20 @@ SW_Player *SW_Player::post_player_data(const String &player_name, const Dictiona
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
String api_key = SilentWolf::config["api_key"];
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
"x-sw-game-id: " + game_id,
"x-sw-godot-version: " + SilentWolf::godot_version);
Dictionary payload = helper::dict("game_id", game_id, "game_version", game_version, "player_name", player_name, "player_data", player_data, "overwrite", overwrite);
Dictionary payload = make_dict("game_id", game_id, "game_version", game_version, "player_name", player_name, "player_data", player_data, "overwrite", overwrite);
String query = JSON::print(payload);
PushPlayerData->request("https://api.silentwolf.com/push_player_data", headers, true, HTTPClient::METHOD_POST, query);
NOTIFY_REQUEST();
}

SW_Player *SW_Player::delete_player_items(const String &player_name, const String &item_name) {
Dictionary item = helper::dict(item_name, "");
Dictionary item = make_dict(item_name, "");
return delete_player_data(player_name, item);
}

Expand All @@ -144,13 +144,13 @@ SW_Player *SW_Player::delete_player_data(const String &player_name, const Dictio
sw_info("Calling SilentWolf to remove player data");
String game_id = SilentWolf::config["game_id"];
String api_key = SilentWolf::config["api_key"];
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + api_key,
"x-sw-plugin-version: " + SilentWolf::version,
"x-sw-game-id: " + game_id,
"x-sw-godot-version: " + SilentWolf::godot_version);
Dictionary payload = helper::dict("game_id", game_id, "player_name", player_name, "player_data", player_data);
Dictionary payload = make_dict("game_id", game_id, "player_name", player_name, "player_data", player_data);
String query = JSON::print(payload);
RemovePlayerData->request("https://api.silentwolf.com/remove_player_data", headers, true, HTTPClient::METHOD_POST, query);
NOTIFY_REQUEST();
Expand Down
14 changes: 7 additions & 7 deletions modules/gdextensions/submodules/silentwolf/sw_scores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void SW_Scores::sw_notification(int what) {
if (what == SW_NOTIFICATION_PROCESS) {
if (requesting) {
int check = 0;
for (auto &http_req : helper::vector(ScorePosition, ScoresAround, HighScores, ScoresByPlayer, WipeLeaderboard, PostScore, DeleteScore)) {
for (auto &http_req : make_vector(ScorePosition, ScoresAround, HighScores, ScoresByPlayer, WipeLeaderboard, PostScore, DeleteScore)) {
if (http_req) {
check += !http_req->poll();
}
Expand Down Expand Up @@ -75,7 +75,7 @@ SW_Scores *SW_Scores::get_score_position(const String &score, const String &ldbo
sw_info("Calling SilentWolf to get score position");
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
Dictionary payload = helper::dict("game_id", game_id, "game_version", game_version, "ldboard_name", ldboard_name);
Dictionary payload = make_dict("game_id", game_id, "game_version", game_version, "ldboard_name", ldboard_name);
if (!score_id.empty()) {
payload["score_id"] = score_id;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ SW_Scores *SW_Scores::get_top_score_by_player(const String &player_name, int max
}

void SW_Scores::add_to_local_scores(const Dictionary &game_result, const String &ld_name) {
Dictionary local_score = helper::dict(
Dictionary local_score = make_dict(
"score_id", game_result["score_id"],
"game_id_version", vconcat(game_result["game_id"], ";", game_result["game_version"]),
"player_name", game_result["player_name"],
Expand Down Expand Up @@ -201,7 +201,7 @@ SW_Scores *SW_Scores::persist_score(const String &player_name, const String &sco

String score_uuid = generate_uuid_v4();
score_id = score_uuid;
Dictionary payload = helper::dict(
Dictionary payload = make_dict(
"score_id", score_id,
"player_name", player_name,
"game_id", game_id,
Expand Down Expand Up @@ -232,7 +232,7 @@ SW_Scores *SW_Scores::wipe_leaderboard(const String &ldboard_name) {
sw_info("Calling SilentWolf backend to wipe leaderboard...");
String game_id = SilentWolf::config["game_id"];
String game_version = SilentWolf::config["game_version"];
Dictionary payload = helper::dict("game_id", game_id, "game_version", game_version, "ldboard_name", ldboard_name);
Dictionary payload = make_dict("game_id", game_id, "game_version", game_version, "ldboard_name", ldboard_name);
String request_url = "https://api.silentwolf.com/wipe_leaderboard";
send_post_request(WipeLeaderboard, request_url, payload);
return this;
Expand Down Expand Up @@ -464,7 +464,7 @@ void SW_Scores::_on_WipeLeaderboard_request_completed(int result, int response_c
}

void SW_Scores::send_get_request(Ref<BasicHTTPRequest> http_req, const String &request_url) {
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
"x-api-key: " + SilentWolf::get_cfg_str("api_key"),
"x-sw-plugin-version: " + SilentWolf::version);
sw_debug("Method: GET");
Expand All @@ -479,7 +479,7 @@ void SW_Scores::send_get_request(Ref<BasicHTTPRequest> http_req, const String &r
}

void SW_Scores::send_post_request(Ref<BasicHTTPRequest> http_req, const String &request_url, const Dictionary &payload) {
Vector<String> headers = helper::vector(
Vector<String> headers = make_vector(
application_json,
"x-api-key: " + SilentWolf::get_cfg_str("api_key"),
"x-sw-plugin-version: " + SilentWolf::version);
Expand Down
2 changes: 1 addition & 1 deletion modules/gdextensions/submodules/silentwolf/sw_wsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void SW_WSClient::send_to_server(const String &p_category, const Dictionary &p_d

void SW_WSClient::init_mp_session(const String &p_player_name) {
sw_debug("WSClient init_mp_session, sending initialisation packet to server");
Dictionary init_packet = helper::dict("player_name", p_player_name);
Dictionary init_packet = make_dict("player_name", p_player_name);
return send_to_server("init", init_packet);
}

Expand Down
Loading

0 comments on commit fb23522

Please sign in to comment.