Skip to content

Commit

Permalink
database integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Brain-dawg committed Nov 26, 2024
1 parent 15ed53b commit dd8eca1
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions scripts/vscripts/trespasser_remaster.nut
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,31 @@ if(hObjectiveResource && hObjectiveResource.IsValid()) hObjectiveResource.Accept
if(sNetworkID == "" || sNetworkID == "BOT") continue

local sNetworkIDSlice = sNetworkID.slice(5, sNetworkID.find("]"))
local sScriptData = FileToString(format("trespasser_remaster_wins/updated/player_%s.txt", sNetworkIDSlice))
if(sScriptData != null)
compilestring(format("Trespasser.Wins[\"%s\"] <- %s", sNetworkID, sScriptData))()
// local sScriptData = FileToString(format("trespasser_remaster_wins/updated/player_%s.txt", sNetworkIDSlice))
// if(sScriptData != null)
// compilestring(format("Trespasser.Wins[\"%s\"] <- %s", sNetworkID, sScriptData))()

//test database read
VPI.AsyncCall({func="VPI_DB_Trespasser_ReadWrite", kwargs= {
query_mode="read",
network_id=sNetworkIDSlice
},
callback=function(response) {
VPI.AsyncCall({
func="VPI_DB_Trespasser_ReadWrite",
kwargs= {
query_mode="read",
network_id=sNetworkIDSlice
},
callback=function(response) {

if (typeof(response) != "array" || !response.len())
{
Trespasser.Wins[sNetworkID] <- [0, false, false]
printl("empty win data for " + sNetworkID + ": " + response)
return;
}
local r = response[0]
printl("READ: Win data for " + sNetworkID + ": "+r[0]+"|"+r[1]+"|"+r[2])

if (typeof(response) != "array" || !response.len())
{
printl("empty");
return;
Trespasser.Wins[sNetworkID] <- [r[0], r[1], r[2]]
}

// local s = ""
// foreach (col in response)
// if (typeof col == "array")
// foreach (c in col)
// s += format("%s%s", c.tostring(), ",");
// else
// s += format("%s%s", col.tostring(), ",");
// printl(s)
}})
})
}
}
function SavePlayerWins()
Expand All @@ -328,26 +327,28 @@ if(hObjectiveResource && hObjectiveResource.IsValid()) hObjectiveResource.Accept

local sNetworkIDSlice = sNetworkID.slice(5, sNetworkID.find("]"))
//test database write
VPI.AsyncCall({func="VPI_DB_Trespasser_ReadWrite", kwargs= {
query_mode="write",
network_id=sNetworkIDSlice,
wins=Array[0],
solo_win=Array[1],
all_survivors_alive_win=Array[2]
},
callback=function(response) {

printl("write response")
printl("write response")
printl("write response")

foreach (r in response)
if (typeof r == "array")
foreach (col in r)
printl(col)
else
printl(r)
}})
VPI.AsyncCall({
func="VPI_DB_Trespasser_ReadWrite",
kwargs= {
query_mode="write",
network_id=sNetworkIDSlice,
wins=Array[0],
solo_win=Array[1],
all_survivors_alive_win=Array[2]
}
// callback=function(response) {

// foreach (a in Array)
// printl("write input: " + a)

// foreach (r in response)
// if (typeof r == "array")
// foreach (col in r)
// printl(col)
// else
// printl(r)
// }
})
}
}
bAllSurvivorsAlive = true
Expand Down

0 comments on commit dd8eca1

Please sign in to comment.