Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak(citizen-resources-client): have a default value with GET_RESOUR… #3102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ struct SerializeValue<RawType>
};

template<typename T>
static void GetResourceKvp_Impl(const std::string& key, fx::ScriptContext& context)
static void GetResourceKvp_Impl(const std::string& key, bool external, fx::ScriptContext& context)
{
auto db = EnsureDatabase();

std::string value;
if (db->Get(leveldb::ReadOptions{}, key, &value).IsNotFound())
{
context.SetResult<const char*>(nullptr);
context.SetResult<T>(context.GetArgument<T>(external ? 2 : 1));
return;
}

Expand All @@ -207,15 +207,15 @@ static void GetResourceKvp(fx::ScriptContext& context)
{
auto key = FormatKey(context.CheckArgument<const char*>(0));

return GetResourceKvp_Impl<T>(key, context);
return GetResourceKvp_Impl<T>(key, false, context);
}

template<typename T>
static void GetExternalKvp(fx::ScriptContext& context)
{
auto key = FormatKey(context.CheckArgument<const char*>(1), context.CheckArgument<const char*>(0));

return GetResourceKvp_Impl<T>(key, context);
return GetResourceKvp_Impl<T>(key, true, context);
}

#include <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static void GetResourceKvp(fx::ScriptContext& context)
std::string value;
if (db->Get(rocksdb::ReadOptions{}, key, &value).IsNotFound())
{
context.SetResult<const char*>(nullptr);
context.SetResult<T>(context.GetArgument<T>(1));
return;
}

Expand Down
5 changes: 3 additions & 2 deletions ext/native-decls/kvp/GetResourceKvpFloat.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ apiset: shared
## GET_RESOURCE_KVP_FLOAT

```c
float GET_RESOURCE_KVP_FLOAT(char* key);
float GET_RESOURCE_KVP_FLOAT(char* key, float default);
```

A getter for [SET_RESOURCE_KVP_FLOAT](#_0x9ADD2938).

## Parameters
* **key**: The key to fetch
* **default**: The default value to set if none is found.

## Return value
The floating-point value stored under the specified key, or 0.0 if not found.
The floating-point value stored under the specified key, or 0.0/default if not found.

## Examples

Expand Down
5 changes: 3 additions & 2 deletions ext/native-decls/kvp/GetResourceKvpInt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ apiset: shared
## GET_RESOURCE_KVP_INT

```c
int GET_RESOURCE_KVP_INT(char* key);
int GET_RESOURCE_KVP_INT(char* key, int default);
```

A getter for [SET_RESOURCE_KVP_INT](#_0x6A2B1E8).

## Parameters
* **key**: The key to fetch
* **default**: The default value to set if none is found.

## Return value
The integer value stored under the specified key, or 0 if not found.
The integer value stored under the specified key, or 0/default if not found.

## Examples

Expand Down
5 changes: 3 additions & 2 deletions ext/native-decls/kvp/GetResourceKvpString.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ apiset: shared
## GET_RESOURCE_KVP_STRING

```c
char* GET_RESOURCE_KVP_STRING(char* key);
char* GET_RESOURCE_KVP_STRING(char* key, char* default);
```

A getter for [SET_RESOURCE_KVP](#_0x21C7A35B).

## Parameters
* **key**: The key to fetch
* **default**: The default value to set if none is found.

## Return value
The string value stored under the specified key, or nil/null if not found.
The string value stored under the specified key, or nil/null/default if not found.

## Examples

Expand Down
5 changes: 3 additions & 2 deletions ext/native-decls/kvp/external/GetExternalKvpFloat.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ apiset: client
## GET_EXTERNAL_KVP_FLOAT

```c
float GET_EXTERNAL_KVP_FLOAT(char* resource, char* key);
float GET_EXTERNAL_KVP_FLOAT(char* resource, char* key, float default);
```

A getter for [SET_RESOURCE_KVP_FLOAT](#_0x9ADD2938), but for a specified resource.

## Parameters
* **resource**: The resource to fetch from.
* **key**: The key to fetch
* **default**: The default value to set if none is found.

## Return value
A float that contains the value stored in the Kvp or nil/null if none.
A float that contains the value stored in the Kvp or nil/null/default if none.

## Examples

Expand Down
5 changes: 3 additions & 2 deletions ext/native-decls/kvp/external/GetExternalKvpInt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ apiset: client
## GET_EXTERNAL_KVP_INT

```c
int GET_EXTERNAL_KVP_INT(char* resource, char* key);
int GET_EXTERNAL_KVP_INT(char* resource, char* key, int default);
```

A getter for [SET_RESOURCE_KVP_INT](#_0x6A2B1E8), but for a specified resource.

## Parameters
* **resource**: The resource to fetch from.
* **key**: The key to fetch
* **default**: The default value to set if none is found.

## Return value
A int that contains the value stored in the Kvp or nil/null if none.
A int that contains the value stored in the Kvp or nil/null/default if none.

## Examples

Expand Down
5 changes: 3 additions & 2 deletions ext/native-decls/kvp/external/GetExternalKvpString.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ apiset: client
## GET_EXTERNAL_KVP_STRING

```c
char* GET_EXTERNAL_KVP_STRING(char* resource, char* key);
char* GET_EXTERNAL_KVP_STRING(char* resource, char* key, char* default);
```

A getter for [SET_RESOURCE_KVP](#_0x21C7A35B), but for a specified resource.

## Parameters
* **resource**: The resource to fetch from.
* **key**: The key to fetch
* **default**: The default value to set if none is found.

## Return value
A string that contains the value stored in the Kvp or nil/null if none.
A string that contains the value stored in the Kvp or nil/null/default if none.

## Examples

Expand Down
Loading