Skip to content

Commit

Permalink
Release(0.0.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverGoLt committed May 6, 2023
1 parent fb0566b commit 17f8114
Show file tree
Hide file tree
Showing 40 changed files with 1,364 additions and 3,575 deletions.
19 changes: 14 additions & 5 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ RegisterNUICallback('selectCar', function(data, cb)
end
end)

RegisterNUICallback('rotateVeh', function (body, resultCallback)
if body.type then
Utils.rotateVehicle(body.type)
resultCallback(true)
end
end)

RegisterNUICallback('closeShop', function (data, cb)
_UIOpen = false
SetNuiFocus(false, false)
SendNUIMessage({type = 'close'})
Utils.destroyCam()

local delete = Utils.deleteVehicle()
Expand All @@ -65,20 +73,21 @@ end)

RegisterNUICallback('purchase', function (data,cb)
local plate = GeneratePlate()

local shop = Utils.getShop()
local sPos = shop.delivery.pos
local sHeading = shop.delivery.heading

ESX.TriggerServerCallback('h-vshop:buyCar', function(success)
if success then
Utils.spawnVehicle(data.vehicle, plate)
cb(true)
else
cb(false)
end
end, data.vehicle, plate)

end, {model = data.vehicle, plate = plate, pos = sPos, heading = sHeading})
end)

RegisterCommand('openCarShop', function()
Utils.openShop()
end)
end, false)

RegisterKeyMapping('openCarShop', 'Opens vehicle shop', 'keyboard', 'e')
2 changes: 0 additions & 2 deletions client/testDrive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local testShop

RegisterNUICallback('testDrive', function(data, cb)
ESX.TriggerServerCallback('h-vshop:testDrive', function(success)
print(success)
if success then
testDriving = true
local shop = Utils.getShop()
Expand All @@ -15,7 +14,6 @@ RegisterNUICallback('testDrive', function(data, cb)
local sHeading = shop.delivery.heading
ESX.Game.SpawnLocalVehicle(data.vehicle, sPos, heading, function(vehicle)
testVehicle = vehicle
print('Test vehicle spawned: '..vehicle)
end)
Wait(100)
SetPedIntoVehicle(PlayerPedId(), testVehicle, -1)
Expand Down
37 changes: 19 additions & 18 deletions client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,32 @@ Utils.loadModel = function(model)
Wait(1)
end

print('Loading Completed')

SendNUIMessage({
type = 'loadingDone'
})

return true
end

Utils.rotateVehicle = function (direction)
if not currentVeh then return end

local heading = GetEntityHeading(currentVeh)

if direction == 'left' then
SetEntityHeading(currentVeh, heading + 3.0)
elseif direction == 'right' then
SetEntityHeading(currentVeh, heading - 3.0)
end
end

Utils.spawnShowcase = function(vehicle)
local shop = Utils.getShop()
local pos = shop.preview
local heading = shop.previewHeading
local distance = shop.cameraDistance or 5.0
local pos = shop?.preview
local heading = shop?.previewHeading
local distance = shop?.cameraDistance or 5.0

local cars = Utils.getShopVehicles(shop.category)
local cars = Utils.getShopVehicles(shop?.category)

if not cars then return end

Expand All @@ -125,7 +135,6 @@ Utils.spawnShowcase = function(vehicle)
end
return false
end

end

Utils.getShop = function ()
Expand Down Expand Up @@ -156,17 +165,9 @@ Utils.spawnVehicle = function(model, plate)
isClear = ESX.Game.IsSpawnPointClear(sPos, 3)
end

ESX.Game.SpawnVehicle(model, sPos, sHeading, function(vehicle)
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
local props = ESX.Game.GetVehicleProperties(vehicle)
props.plate = plate
SetVehicleNumberPlateText(vehicle, plate)

ESX.TriggerServerCallback('h-vshop:setOwned', function(success)
if not success then print('Issues with setOwned callback!') end
end, props)

end)
ESX.TriggerServerCallback('h-vshop:setOwned', function(success)
if not success then print('Issues with setOwned callback!') end
end, {model = model, plate = plate, pos = sPos, heading = sHeading})
end
end

Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ shared_scripts {
}

ui_page 'web/dist/index.html'
--ui_page 'http://localhost:3000/'
--ui_page 'http://localhost:5173'

files {
'web/dist/**'
Expand Down
25 changes: 18 additions & 7 deletions server/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ ESX.RegisterServerCallback('esx_vehicleshop:isPlateTaken', function(source, cb,
end)
end)

ESX.RegisterServerCallback('h-vshop:buyCar', function (source, cb, model, plate)
ESX.RegisterServerCallback('h-vshop:buyCar', function (source, cb, data)
if source ~= nil and source ~= -1 then
local result = shop.purchaseCar(source, model, plate)
local result = shop.purchaseCar(source, data.model, data.model)

if Config.Debug then
print(string.format('[Player] %s purchased a %s', GetPlayerName(source), data.model))
end

if result then
shop.setOwned(source, data.plate, data.model)
ESX.OneSync.SpawnVehicle(joaat(data.model), data.pos, data.heading,{plate = data.plate}, function(vehicle)
Wait(100)
local vehicle = NetworkGetEntityFromNetworkId(vehicle)
Wait(300)
TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1)
end)
cb(true)
else
cb(false)
Expand Down Expand Up @@ -59,13 +70,13 @@ ESX.RegisterServerCallback('h-vshop:removeBucket', function (source, cb, bucket)
end
end)

function shop.setOwned(source, props)
function shop.setOwned(source, plate, model)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
local result = MySQL.insert.await('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (?,?,?)', {
xPlayer.identifier,
props.plate,
json.encode(props)
plate,
json.encode({model = joaat(model), plate = plate})
})

if result then return true else return false end
Expand Down Expand Up @@ -132,9 +143,9 @@ if Debug then
RegisterCommand('getPlayerBucket', function(source)
local bucket = GetPlayerRoutingBucket(source)
print('Bucket: ' .. bucket)
end)
end, false)

RegisterCommand('resetPlayerBucket', function (source)
SetPlayerRoutingBucket(source, 0)
end)
end, false)
end
1 change: 1 addition & 0 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Config.PlateNumbers = 3
Config.PlateUseSpace = true
Config.Payment = 'bank'
Config.TestTime = 30 -- Seconds
Config.Debug = false

-- This table is used to configure different shops!
Config.Shops = {
Expand Down
2 changes: 1 addition & 1 deletion web/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["Vue.volar"]
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
17 changes: 14 additions & 3 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Vue 3 + Vite
# Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support For `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
Binary file removed web/dist/favicon.ico
Binary file not shown.
8 changes: 4 additions & 4 deletions web/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="./favicon.ico" />
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script type="module" crossorigin src="./assets/index.a7fbebef.js"></script>
<link rel="stylesheet" href="./assets/index.820572fd.css">
<title>Vite + Vue + TS</title>
<script type="module" crossorigin src="./assets/index-b6e3a44b.js"></script>
<link rel="stylesheet" href="./assets/index-9bdb84e5.css">
</head>
<body>
<div id="app"></div>
Expand Down
6 changes: 3 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading

0 comments on commit 17f8114

Please sign in to comment.