mirror of
https://github.com/BeamMP/BeamNG-FuelStations.git
synced 2025-07-01 23:35:46 +00:00
Hot Liquid + Battery Juice Working
This commit is contained in:
parent
3dff45fc31
commit
098a78dc69
105
lua/ge/extensions/fuelStations.lua
Normal file
105
lua/ge/extensions/fuelStations.lua
Normal file
@ -0,0 +1,105 @@
|
||||
local M = {}
|
||||
print("Fuel Stations Initialising...")
|
||||
|
||||
local map = ""
|
||||
local debug = false
|
||||
local cVeh = 0
|
||||
|
||||
local stations = {
|
||||
["/levels/east_coast_usa/info.json"] = {
|
||||
{vec3(-778.813, 485.973, 23.4637), vec3(-778.813, 485.973, 25.4637), "Gas"},
|
||||
{vec3(-776.504, 488.427, 23.4637), vec3(-776.504, 488.427, 25.4637), "Gas"},
|
||||
{vec3(-775.036, 490.828, 23.4637), vec3(-775.036, 490.828, 25.4637), "Gas"},
|
||||
{vec3(-772.457, 493.484, 23.4637), vec3(-772.457, 493.484, 25.4637), "Gas"},
|
||||
{vec3(-770.871, 495.714, 23.4637), vec3(-770.871, 495.714, 25.4637), "Gas"},
|
||||
{vec3(-768.417, 498.436, 23.4637), vec3(-768.417, 498.436, 25.4637), "Gas"},
|
||||
{vec3(704.304, -23.125, 51.8), vec3(704.304, -23.125, 55.0), "Gas"},
|
||||
{vec3(708.497, -23.3151, 51.8), vec3(708.497, -23.3151, 55.0), "Gas"},
|
||||
{vec3(711.115, -23.5511, 51.8), vec3(711.115, -23.5511, 55.0), "Gas"},
|
||||
{vec3(714.968, -23.6462, 51.8), vec3(714.968, -23.6462, 55.0), "Gas"},
|
||||
{vec3(717.763, -23.9071, 51.8), vec3(717.763, -23.9071, 55.0), "Gas"},
|
||||
{vec3(721.414, -24.0725, 51.8), vec3(721.414, -24.0725, 55.0), "Gas"},
|
||||
{vec3(625.651, -183.448, 53.0), vec3(625.651, -183.448, 55.0), "EV"},
|
||||
{vec3(622.667, -186.129, 53.0), vec3(622.667, -186.129, 55.0), "EV"},
|
||||
{vec3(619.97, -189.098, 53.0), vec3(619.97, -189.098, 55.0), "EV"},
|
||||
{vec3(617.164, -192.107, 53.0), vec3(617.164, -192.107, 55.0), "EV"},
|
||||
}
|
||||
}
|
||||
|
||||
local function distance (pos1, pos2, useZ)
|
||||
local dx = pos1.x - pos2.x
|
||||
local dy = pos1.y - pos2.y
|
||||
local dz = pos1.z - pos2.z
|
||||
if useZ then
|
||||
return math.sqrt ( dx * dx + dy * dy + dz * dz )
|
||||
else
|
||||
return math.sqrt ( dx * dx + dy * dy )
|
||||
end
|
||||
end
|
||||
|
||||
local function IsEntityInsideArea(pos1, pos2)
|
||||
if distance(pos1, pos2, true) < 1 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function addFuel()
|
||||
--print("Should i add fuel?")
|
||||
local veh = be:getObjectByID(cVeh)
|
||||
if veh then
|
||||
print("[Fuel Stations] [GE] Calling Add Fuel VE")
|
||||
veh:queueLuaCommand("fuelStation.addFuel()")
|
||||
end
|
||||
end
|
||||
|
||||
local function onVehicleSwitched(oldID, newID)
|
||||
print("[Fuel Stations] Active Vehicle Switched : "..oldID.." - "..newID)
|
||||
cVeh = newID
|
||||
end
|
||||
|
||||
local function onVehicleSpawned(gameVehicleID)
|
||||
--print("[BeamMP] Vehicle spawned : "..gameVehicleID)
|
||||
local veh = be:getObjectByID(gameVehicleID)
|
||||
veh:queueLuaCommand("extensions.addModulePath('lua/vehicle/extensions/FuelStation')") -- Load lua files
|
||||
veh:queueLuaCommand("extensions.loadModulesInDirectory('lua/vehicle/extensions/FuelStation')")
|
||||
end
|
||||
|
||||
local function onUpdate()
|
||||
local atStation = false
|
||||
if debug then
|
||||
debugDrawer:drawTextAdvanced(be:getObject(0):getPosition(), String(" "..tostring(be:getObject(0):getPosition())), ColorF(194/255, 55/255, 55/255, 255/255), true, false, ColorI(0,0,0,127))
|
||||
end
|
||||
map = getMissionFilename()
|
||||
for k = 1, #stations[map] do
|
||||
local color = 0
|
||||
if stations[map][k][3] == "EV" then
|
||||
color = ColorF(0.0,0.9,0.1,0.5)
|
||||
else
|
||||
color = ColorF(0.9,0.1,0.1,0.5)
|
||||
end
|
||||
debugDrawer:drawCylinder(stations[map][k][1]:toPoint3F(), stations[map][k][2]:toPoint3F(), 1, color)
|
||||
for i = 0, be:getObjectCount() -1 do -- For each vehicle
|
||||
local veh = be:getObject(i) -- Get vehicle
|
||||
if IsEntityInsideArea(veh:getPosition(), stations[map][k][1]) then
|
||||
-- we are inside one of the filling areas of the map
|
||||
--ui_message("Press E To Refuel")
|
||||
atStation = true
|
||||
be:executeJS('fuelUIShowHide("true", "'..stations[map][k][3]..'")')
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not atStation then -- We are not in a spot for filling then we should force the UI to be hidden
|
||||
be:executeJS('fuelUIShowHide("false")')
|
||||
end
|
||||
end
|
||||
|
||||
M.onUpdate = onUpdate
|
||||
M.addFuel = addFuel
|
||||
M.onVehicleSwitched = onVehicleSwitched
|
||||
M.onVehicleSpawned = onVehicleSpawned
|
||||
|
||||
print("Fuel Stations Loaded")
|
||||
return M
|
53
lua/vehicle/extensions/FuelStation/fuelStation.lua
Normal file
53
lua/vehicle/extensions/FuelStation/fuelStation.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local M = {}
|
||||
print("[Fuel Stations] [VE] Loaded")
|
||||
|
||||
local function addFuel()
|
||||
print("[Fuel Stations] [VE] Add Fuel Called")
|
||||
if energyStorage.getStorage('mainTank') ~= nil then
|
||||
local Tank = energyStorage.getStorage('mainTank').remainingRatio
|
||||
if Tank < 1 then
|
||||
local Level = Tank + 0.005
|
||||
print("Adding Fuel: "..Level)
|
||||
energyStorage.getStorage('mainTank'):setRemainingRatio(Level)
|
||||
else
|
||||
energyStorage.getStorage('mainTank'):setRemainingRatio(1.0)
|
||||
end
|
||||
end
|
||||
|
||||
if energyStorage.getStorage('mainBattery') ~= nil then
|
||||
local Battery = energyStorage.getStorage('mainBattery').remainingRatio
|
||||
if Battery < 1 then
|
||||
local Level = Battery + 0.005
|
||||
print("Adding Fuel: "..Level)
|
||||
energyStorage.getStorage('mainBattery'):setRemainingRatio(Level)
|
||||
else
|
||||
energyStorage.getStorage('mainBattery'):setRemainingRatio(1.0)
|
||||
end
|
||||
end
|
||||
|
||||
if energyStorage.getStorage('mainTankL') ~= nil then
|
||||
local Tank = energyStorage.getStorage('mainTankL').remainingRatio
|
||||
if Tank < 1 then
|
||||
local Level = Tank + 0.005
|
||||
print("Adding Fuel: "..Level)
|
||||
energyStorage.getStorage('mainTankL'):setRemainingRatio(Level)
|
||||
else
|
||||
energyStorage.getStorage('mainTankL'):setRemainingRatio(1.0)
|
||||
end
|
||||
end
|
||||
|
||||
if energyStorage.getStorage('mainTankR') ~= nil then
|
||||
local Tank = energyStorage.getStorage('mainTankR').remainingRatio
|
||||
if Tank < 1 then
|
||||
local Level = Tank + 0.005
|
||||
print("Adding Fuel: "..Level)
|
||||
energyStorage.getStorage('mainTankR'):setRemainingRatio(Level)
|
||||
else
|
||||
energyStorage.getStorage('mainTankR'):setRemainingRatio(1.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.addFuel = addFuel
|
||||
|
||||
return M
|
2
scripts/FuelStations/modScript.lua
Normal file
2
scripts/FuelStations/modScript.lua
Normal file
@ -0,0 +1,2 @@
|
||||
load("fuelStations")
|
||||
registerCoreModule("fuelStations")
|
95
ui/modules/apps/FuelStation/app.html
Normal file
95
ui/modules/apps/FuelStation/app.html
Normal file
@ -0,0 +1,95 @@
|
||||
<div ng-controller="fuelstation" id="fuelstation" class="fuelstation" ng-style="{'width': '100%', 'height': '100%'}" ng-init="init()">
|
||||
<style id="applicationStylesheet" type="text/css">
|
||||
.Background {
|
||||
position: absolute;
|
||||
overflow: visible;
|
||||
width: 470px;
|
||||
height: 309px;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
}
|
||||
#Gallon {
|
||||
position: absolute;
|
||||
left: 38px;
|
||||
top: 46px;
|
||||
overflow: visible;
|
||||
width: 143px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
font-family: Segoe UI;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-size: 50px;
|
||||
color: rgba(255,255,255,1);
|
||||
}
|
||||
#Price {
|
||||
position: absolute;
|
||||
left: 38px;
|
||||
top: 140px;
|
||||
overflow: visible;
|
||||
width: 108px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
font-family: Segoe UI;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-size: 50px;
|
||||
color: rgba(255,255,255,1);
|
||||
}
|
||||
#Fuel_served_at_5_degrees {
|
||||
position: absolute;
|
||||
left: 145px;
|
||||
top: 227px;
|
||||
overflow: visible;
|
||||
width: 151px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
font-family: Segoe UI;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-size: 14px;
|
||||
color: rgba(255,255,255,1);
|
||||
}
|
||||
#AddFuel {
|
||||
position: absolute;
|
||||
right: -40px;
|
||||
bottom: 130px;
|
||||
overflow: visible;
|
||||
width: 151px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
font-family: Segoe UI;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-size: 14px;
|
||||
color: rgba(255,255,255,1);
|
||||
}
|
||||
input.fuelStationNumberValue {
|
||||
width: 250px;
|
||||
right: -270px;
|
||||
position: absolute;
|
||||
}
|
||||
button {
|
||||
font-size: 30px;
|
||||
}
|
||||
</style>
|
||||
<svg class="Background">
|
||||
<rect fill="rgba(113,113,113,1)" stroke="rgba(255,255,255,1)" stroke-width="1px" stroke-linejoin="miter" stroke-linecap="butt" stroke-miterlimit="4" shape-rendering="auto" id="Background" rx="26" ry="26" x="0" y="0" width="470" height="309">
|
||||
</rect>
|
||||
</svg>
|
||||
<div id="Gallon">
|
||||
<span id="GasNote">Gallon</span>
|
||||
<span id="EVNote">p/Kw</span>
|
||||
<input type="number" name="" value="2.73" class="fuelStationNumberValue" disabled>
|
||||
</div>
|
||||
<div id="Price">
|
||||
<span>Price</span>
|
||||
<input type="number" name="" value="0.0" class="fuelStationNumberValue" style="right: -305px;" disabled id="FuelValueIncreasedBy">
|
||||
</div>
|
||||
<div id="Fuel_served_at_5_degrees">
|
||||
<span id="FuelNote">Fuel served at 5 degrees</span>
|
||||
</div>
|
||||
<div id="AddFuel">
|
||||
<button id="ActionButton" type="button" ng-mousedown='addFuel()' ng-mouseup="stopAddFuel()">Fuel</button>
|
||||
</div>
|
||||
</div>
|
63
ui/modules/apps/FuelStation/app.js
Normal file
63
ui/modules/apps/FuelStation/app.js
Normal file
@ -0,0 +1,63 @@
|
||||
var app = angular.module('beamng.apps');
|
||||
app.directive('fuelstation', ['UiUnits', function (UiUnits) {
|
||||
return {
|
||||
templateUrl: 'modules/apps/FuelStation/app.html',
|
||||
replace: true,
|
||||
restrict: 'EA',
|
||||
scope: true
|
||||
}
|
||||
}]);
|
||||
app.controller("fuelstation", ['$scope', 'bngApi', '$interval', function ($scope, bngApi, $interval) {
|
||||
$scope.init = function() {
|
||||
|
||||
};
|
||||
|
||||
$scope.reset = function() {
|
||||
$scope.init();
|
||||
};
|
||||
|
||||
$scope.select = function() {
|
||||
bngApi.engineLua('setCEFFocus(true)');
|
||||
};
|
||||
|
||||
var promise;
|
||||
$scope.addFuel = function() {
|
||||
if(promise){
|
||||
$interval.cancel(promise);
|
||||
}
|
||||
promise = $interval(function () {
|
||||
var v = document.querySelector('#FuelValueIncreasedBy').value;
|
||||
document.querySelector('#FuelValueIncreasedBy').value = parseFloat(v) + 0.1;
|
||||
bngApi.engineLua('fuelStations.addFuel(true)');
|
||||
}, 100);
|
||||
|
||||
};
|
||||
|
||||
$scope.stopAddFuel = function () {
|
||||
$interval.cancel(promise);
|
||||
promise = null;
|
||||
};
|
||||
}]);
|
||||
|
||||
function fuelUIShowHide(b, t) {
|
||||
//console.log("fuelUIShowHide("+b+")")
|
||||
if (b == "true") {
|
||||
if (document.querySelector('#fuelstation').style.display == "none") {
|
||||
document.querySelector('#fuelstation').style.display = "block";
|
||||
document.querySelector('#FuelValueIncreasedBy').value = 0.0;
|
||||
if (t == "EV") {
|
||||
document.querySelector('#EVNote').style.display = "";
|
||||
document.querySelector('#GasNote').style.display = "none";
|
||||
document.querySelector('#FuelNote').style.display = "none";
|
||||
document.querySelector('#ActionButton').innerHTML = "Charge";
|
||||
} else {
|
||||
document.querySelector('#GasNote').style.display = "";
|
||||
document.querySelector('#EVNote').style.display = "none";
|
||||
document.querySelector('#FuelNote').style.display = "";
|
||||
document.querySelector('#ActionButton').innerHTML = "Fuel";
|
||||
}
|
||||
}
|
||||
} else if (b == "false") {
|
||||
document.querySelector('#fuelstation').style.display = "none";
|
||||
}
|
||||
}
|
14
ui/modules/apps/FuelStation/app.json
Normal file
14
ui/modules/apps/FuelStation/app.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "Fuel Station UI",
|
||||
"author": "Titch2000",
|
||||
"version": "0.2",
|
||||
"description": "Fuel Station UI",
|
||||
"directive": "fuelstation",
|
||||
"domElement": "<fuelstation></fuelstation>",
|
||||
"css": {
|
||||
"left": "180px",
|
||||
"bottom": "0px",
|
||||
"width": "471px",
|
||||
"height": "309px"
|
||||
}
|
||||
}
|
BIN
ui/modules/apps/FuelStation/app.png
Normal file
BIN
ui/modules/apps/FuelStation/app.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
x
Reference in New Issue
Block a user