57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
//DATA STORE LOGIC
|
|
|
|
|
|
integer getItemCountFromSlot(list _dataStorage, integer _slot)
|
|
{
|
|
return (integer)getDataEntryFromDataList(_dataStorage, "inventar.slot." + _slot + ".count");
|
|
}
|
|
|
|
list getDataListFromDataStorage(string _storage)
|
|
{
|
|
return llCSV2List(osGetDataValue(_storage));
|
|
}
|
|
|
|
saveDataListToDataStorage(list _dataList, string _storage)
|
|
{
|
|
string _csv = llList2CSV(_dataList);
|
|
osSetDataValue(_storage, _csv);
|
|
}
|
|
|
|
integer checkDataEntryInDataList(list _dataList, string _key)
|
|
{
|
|
integer _inListPosition = llListFindList(_dataList, [_key]);
|
|
|
|
if(_inListPosition == -1)
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
string getDataEntryFromDataList(list _dataList, string _key)
|
|
{
|
|
integer _inListPosition = llListFindList(_dataList, [_key]);
|
|
|
|
if(_inListPosition == -1)
|
|
return "";
|
|
|
|
return llList2String(_dataList, _inListPosition + 1);
|
|
}
|
|
|
|
list setDataEntryInDataList(list _dataList, string _key, string _value)
|
|
{
|
|
integer _inListPosition = llListFindList(_dataList, [_key]);
|
|
|
|
if(_inListPosition == -1)
|
|
{
|
|
_dataList += [_key, _value];
|
|
return _dataList;
|
|
}
|
|
|
|
return llListReplaceList(_dataList, [_value], _inListPosition + 1, _inListPosition + 1);
|
|
}
|
|
|
|
//Example
|
|
list _dataStorage = getDataListFromDataStorage("storage.example");
|
|
_dataStorage = setDataEntryInDataList(_dataStorage, "test.entry", "dummy");
|
|
llOwnerSay(getDataEntryFromDataList(_dataStorage, "test.entry"));
|
|
saveDataListToDataStorage("storage.example", _dataStorage); |