Skip to content

Commit

Permalink
Added player set-home
Browse files Browse the repository at this point in the history
  • Loading branch information
TwidgeVR committed Sep 15, 2020
1 parent 9e9c92a commit 795e491
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
54 changes: 54 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,60 @@ wsAddHandler( 'clone_prefab', async( data ) => {
})


wsAddHandler( 'player_set_home', async (data) => {
console.log( `player_set_home`, data )
let locData = data.data
let player = locData.player
let destination = locData.destination
let pos = locData.position


attConsole.onMessage = async ( message ) => {
console.log( `player_set_home message: `, message )
if ( !!message.data.Command )
{
switch( message.data.Command.FullName )
{
case "player.detailed":
let posString = message.data.Result.Position.replace(/[()\ ]/g, '')
let npos = posString.split(',')
console.log( `new player home position: ${player} `, npos )
await attConsole.send(`player set-home ${player} "${npos[0]},${npos[1]},${npos[2]}"`)
break

case "player.set-home":
console.log( "player home set: ", message )
wsSendJSON({'result': 'OK', data: data })
break
}
}
}

switch( destination )
{
case "PlayerLoc":
// Retrieve the current location of the player and use this value
await attConsole.send(`player detailed ${player}`)
break

case "MyLoc":
// Retrieve my location and use this value
await attConsole.send(`player detailed ${attSession.getUsername()}`)
break

case "Respawn":
// Reset the value by specifying no location
await attConsole.send(`player set-home ${player}`)
break

case "Exact":
// Use the specified location
await attConsole.send(`player set-home ${player} ${pos.x},${pos.y},${pos.z}`)
break
}
})


// TODO: replace these with websocket handlers
server.post('/ajax', asyncMid( async( req, res, next ) => {
console.log( req.body )
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prefabulator",
"version": "1.6.3",
"version": "1.6.4",
"productName": "Prefabulator",
"description": "Add, remove and modify prefabs in A Township Tale",
"main": "electron-start.js",
Expand Down Expand Up @@ -35,9 +35,11 @@
"express": "^4.17.1",
"express-fileupload": "^1.1.6",
"express-session": "^1.17.1",
"g": "^2.0.1",
"ieee754": "^1.1.13",
"moment": "^2.27.0",
"nedb": "^1.8.0",
"nodemon": "^2.0.4",
"path": "^0.12.7",
"pug": "^2.0.4",
"save": "^2.4.0",
Expand Down
37 changes: 37 additions & 0 deletions public/script/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,36 @@ $(document).ready(() => {
$(e.target).toggleClass("active")
})

$("#PlayerConfigTeleport select#PlayerHomeSelect").on('change', (e) => {
let parent = selectedConfigForm
let optSelected = $(e.target).find("option:selected").val()
console.log( optSelected )
if ( optSelected == "Exact" )
{
$(parent + " #PlayerHomeExact").show()
} else {
$(parent + " #PlayerHomeExact").hide()
}
})

$("#PlayerConfigTeleport a#PlayerSetHomeButton").click( (e) => {
let parent = selectedConfigForm
let optSelected = $(parent + " select#PlayerHomeSelect").find("option:selected")
let position = {
x: $(parent +" #PlayerHomeX").val(),
y: $(parent +" #PlayerHomeY").val(),
z: $(parent +" #PlayerHomeZ").val()
}
let player = selectedPlayerId
let destination = optSelected.val()
let data = {
'position' : position,
'player' : player,
'destination' : destination
}
wsSendJSON({ 'action': 'player_set_home', data: data })
})

$("#PlayerConfigTeleport a#TeleportToDestination").click(( e ) =>{
let parent = selectedConfigForm
let optSelected = $(parent + " select#TeleportDestinations").find('option:selected')
Expand Down Expand Up @@ -1707,6 +1737,13 @@ $(document).ready(() => {
flash( $("#SelectedPrefabSelect"), color )
})

wsAddHandler('player_set_home', ( message ) => {
let parent = selectedConfigForm
console.log( message )
let color = ( message.result == 'OK' ) ? "20, 255, 20" : "255, 20, 20"
flash( $(parent +" #PlayerSetHomeButton"), color )
})

})

function addSpinner( e )
Expand Down
27 changes: 27 additions & 0 deletions views/PlayerConfigTeleport.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ div.Controls.w-100.pt-2.pb-2
div.row
a#TeleportToPlayerButton.btn.ControlsMini.w-100.text-center.align-middle Teleport to Player

div.row
span.px-2.py-1
b Set Player Home
div.row
select#PlayerHomeSelect.form-control.w-100
option(value="PlayerLoc" selected) Player's Current Location
option(value="MyLoc") My Current Location
option(value="Exact") Exact
option(value="Respawn") Respawn Point (Reset)
div#PlayerHomeExact.w-100.hidden
div.row.pt-1.w-100
div.col-1.pt-2
b X
div.col-3.px-1
input#PlayerHomeX.form-control(type="text" placeholder="0.0")
div.col-1.pt-2
b Y
div.col-3.px-1
input#PlayerHomeY.form-control(type="text" placeholder="0.0")
div.col-1.pt-2
b Z
div.col-3.px-1
input#PlayerHomeZ.form-control(type="text" placeholder="0.0")

div.pt-1.pb-2.row
a#PlayerSetHomeButton.ControlsMini.col.text-center.align-middle Set Home Location

div.row
span.px-2.py-1
b Select Destination
Expand Down

0 comments on commit 795e491

Please sign in to comment.