Repository navigation
Expand file tree
/
Copy pathdash2.lua
More file actions
274 lines (231 loc) · 9.66 KB
/
Copy pathdash2.lua
File metadata and controls
274 lines (231 loc) · 9.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
--dash2
--- Developed using LifeBoatAPI - Stormworks Lua plugin for VSCode - https://code.visualstudio.com/download (search "Stormworks Lua with LifeboatAPI" extension)
--- If you have any issues, please report them here: https://github.com/nameouschangey/STORMWORKS_VSCodeExtension/issues - by Nameous Changey
--[====[ HOTKEYS ]====]
-- Press F6 to simulate this file
-- Press F7 to build the project, copy the output from /_build/out/ into the game to use
-- Remember to set your Author name etc. in the settings: CTRL+COMMA
--[====[ EDITABLE SIMULATOR CONFIG - *automatically removed from the F7 build output ]====]
---@section __LB_SIMULATOR_ONLY__
do
---@type Simulator -- Set properties and screen sizes here - will run once when the script is loaded
simulator = simulator
simulator:setScreen(1, "3x1")
simulator:setProperty("FONT1", "00019209B400AAAA793CA54A555690015244449415500BA0004903800009254956D4592EC54EC51C53A4F31C5354E52455545594104110490A201C7008A04504")
simulator:setProperty("FONT2", "FFFE57DAD75C7246D6DCF34EF3487256B7DAE92E64D4975A924EBEDAF6DAF6DED74856B2D75A711CE924B6D4B6A4B6FAB55AB524E54ED24C911264965400000E")
simulator:setProperty("Fuel Warn %", 20)
simulator:setProperty("Bat Warn %", 50)
simulator:setProperty("Temp Warn", 70)
simulator:setProperty("Upshift RPS", 17) --read up more on what causes automatics to shift
simulator:setProperty("Downshift RPS", 11)
simulator:setProperty("Transmission Default", true) --true for automatic
simulator:setProperty("Units", true) --true for imperial
simulator:setProperty("Theme", 3) --we dont have the "Use Drive Modes" property because that is handled by the transmission
simulator:setProperty("Car name", "SenCar 5 DEV")
simulator:setProperty("Top Speed (m/s)", 66)
simulator:setProperty("EV Mode (Do not change)", true)
simulator:setProperty("Dash Layout", 4) -- 1 - SenCar 6, 2 - SenCar 5, 3 - Round, 4 - Modern
-- Runs every tick just before onTick; allows you to simulate the inputs changing
---@param simulator Simulator Use simulator:<function>() to set inputs etc.
---@param ticks number Number of ticks since simulator started
function onLBSimulatorTick(simulator, ticks)
--[[ touchscreen defaults
local screenConnection = simulator:getTouchScreen(1)
simulator:setInputBool(1, screenConnection.isTouched)
simulator:setInputNumber(1, screenConnection.width)
simulator:setInputNumber(2, screenConnection.height)
simulator:setInputNumber(3, screenConnection.touchX)
simulator:setInputNumber(4, screenConnection.touchY)]]
-- NEW! button/slider options from the UI
simulator:setInputBool(1, true)
simulator:setInputBool(2, false)
simulator:setInputBool(3, true)
simulator:setInputBool(31, true)
simulator:setInputBool(32, true)
local screenConnection = simulator:getTouchScreen(1)
simulator:setInputNumber(1, simulator:getSlider(1)*100)
simulator:setInputNumber(2, math.floor(simulator:getSlider(2) * 7))
simulator:setInputNumber(3, simulator:getSlider(3)*25)
simulator:setInputNumber(4, simulator:getSlider(4))
simulator:setInputNumber(5, simulator:getSlider(5)*120)
simulator:setInputNumber(8, simulator:getSlider(8))
simulator:setInputNumber(9, math.floor(simulator:getSlider(9)*4))
simulator:setInputNumber(10, screenConnection.touchX)
simulator:setInputNumber(11, screenConnection.touchY)
simulator:setInputNumber(13, (ticks % 1800) / 1800) -- clock cycles every 30 seconds
end;
end
---@endsection
--[====[ IN-GAME CODE ]====]
-- try require("Folder.Filename") to include code from another file in this, so you can store code in libraries
-- the "LifeBoatAPI" is included by default in /_build/libs/ - you can use require("LifeBoatAPI") to get this, and use all the LifeBoatAPI.<functions>!
local theme = { { 47, 51, 78 }, { 86, 67, 143 }, { 128, 95, 164 } }
local info = {properties = {}}
local fuelCollected = false
local ticks = 0
local tickDir = 1
local pi = math.pi
local pi2 = pi*2
local oneDeg = pi / 180
local compIndicatorOffset = 0
local deg = 0
local degStr = ""
local oldDeg = 0
local lastClock = 0
local clockstr = ""
info.properties.fuelwarn = property.getNumber("Fuel Warn %")/100
info.properties.tempwarn = property.getNumber("Temp Warn")
info.properties.upshift = property.getNumber("Upshift RPS")
info.properties.downshift = property.getNumber("Downshift RPS")
info.properties.topspeed = property.getNumber("Top Speed (m/s)")
info.properties.ev = property.getBool("EV Mode (Do not change)")
info.properties.trans = property.getBool("Transmission")
info.properties.unit = property.getBool("Units")
local dashMode = property.getNumber("Dash Layout")
function onTick()
acc = input.getBool(1)
exist = input.getBool(3)
info.properties.unit = input.getBool(32)
info.properties.trans = input.getBool(31) --peculiar property name
if dashMode < 3 then return end
--kill me
info.speed = input.getNumber(1)
info.gear = input.getNumber(2) -- p, r, n, (1, 2, 3, 4, 5)
info.rps = math.abs(input.getNumber(3)) -- battery usage on EVs
info.fuel = input.getNumber(4) -- battery for EVs
info.temp = input.getNumber(5) -- gen power production on EVs
info.gpsX = input.getNumber(6)
info.gpsY = input.getNumber(7)
info.compass = input.getNumber(8)*(math.pi*2)
info.drivemode = input.getNumber(9)
useDimDisplay = input.getBool(6)
local clock = input.getNumber(13)
if clock ~= lastClock then
lastClock = clock
if input.getBool(32) then
clockstr = ("%02d"):format(math.floor(clock * 24) % 12) .. ("%02d"):format(math.floor((clock * 1440) % 60))
if string.sub(clockstr, 1, 2) == "00" then
clockstr = "12" .. string.sub(clockstr, 3, -1)
end
else
clockstr = ("%2d"):format(math.floor(clock * 24)) .. ("%02d"):format(math.floor((clock * 1440) % 60))
end
end
if not fuelCollected or exist then
ticks = ticks + tickDir
end
if not fuelCollected and ticks <= 20 then
info.properties.maxfuel = input.getNumber(4) or 180
fuelCollected = true
end
if ticks > 720 then -- 12 seconds
tickDir = -1
elseif ticks < 0 then
tickDir = 1
end
-- load from inputs
for i = 1, 9 do
local row = math.ceil(i / 3)
local col = (i - 1) % 3 + 1
local value = input.getNumber(i + 23)
if value ~= 0 then
if not theme[row] then theme[row] = {} end
theme[row][col] = value
end
end
deg = math.floor(math.deg(info.compass) % 360)
degStr = string.format("%.0f", (360 - deg) % 360)
if oldDeg ~= deg then
compIndicatorOffset = compIndicatorOffset == 1 and 0 or 1
end
oldDeg = deg
end
function onDraw()
if exist then
-- Heavily abusing LifeBoatAPI's ability to paste code from other files by require
-- The two dash files literally get pasted into this function
if dashMode == 3 then
require("dashes.round")
elseif dashMode == 4 then
require("dashes.modern")
end
end
end
function c(...) local _={...}
for i,v in pairs(_) do
_[i]=_[i]^2.2/255^2.2*_[i]
end
screen.setColor(table.unpack(_))
end
--dst(x,y,text,size=1,rotation=1,is_monospace=false)
--rotation can be between 1 and 4
f=screen.drawRectF
g=property.getText
--magic willy font
h=g("FONT1")..g("FONT2")
i={}j=0
for k in h:gmatch("....")do i[j+1]=tonumber(k,16)j=j+1 end
function dst(l,m,n,b,o,p)b=b or 1
o=o or 1
if o>2 then n=n:reverse()end
n=n:upper()for q in n:gmatch(".")do
r=q:byte()-31 if 0<r and r<=j then
for s=1,15 do
if o>2 then t=2^s else t=2^(16-s)end
if i[r]&t==t then
u,v=((s-1)%3)*b,((s-1)//3)*b
if o%2==1 then f(l+u,m+v,b,b)else f(l+5-v,m+u,b,b)end
end
end
if i[r]&1==1 and not p then
s=2*b
else
s=4*b
end
if o%2==1 then l=l+s else m=m+s end
end
end
end
function drawPointer(x,y,c,s)
local d = 5
local sin, pi, cos = math.sin, math.pi, math.cos
screen.drawTriangleF(sin(c - pi) * s + x + 1, cos(c - pi) * s + y +1, sin(c - pi/d) * s + x +1, cos(c - pi/d) * s + y +1, sin(c + pi/d) * s + x +1, cos(c + pi/d) * s + y +1)
end
function isPointInRectangle(rectX, rectY, rectW, rectH)
return touchX > rectX and touchY > rectY and touchX < rectX+rectW and touchY < rectY+rectH
end
function gpsSpeed(x,y,lX,lY) -- function by GOM
s=(((x-lX)^2+(y-lY)^2)^0.5)
return s,x,y
end
function clamp(v, min, max)
return math.min(math.max(v, min), max)
end
--- draws an arc around pixel coords [x], [y].
function drawCircle(x, y, outer_rad, inner_rad, step, begin_ang, arc_ang, dir)
dir = dir or 1
local step_s = pi2 / step * -dir
local ba = begin_ang * dir
local steps = math.floor(arc_ang / (pi2 / step))
local sin, cos = math.sin, math.cos
for i = 0, steps - 1 do
local step_p = ba + step_s * i
local step_n = ba + step_s * (i + 1)
-- Cache sin/cos calculations
local sin_p, cos_p = sin(step_p), cos(step_p)
local sin_n, cos_n = sin(step_n), cos(step_n)
local x1, y1 = x + sin_p * outer_rad, y + cos_p * outer_rad
local x2, y2 = x + sin_n * outer_rad, y + cos_n * outer_rad
local x3, y3 = x + sin_p * inner_rad, y + cos_p * inner_rad
local x4, y4 = x + sin_n * inner_rad, y + cos_n * inner_rad
screen.drawTriangleF(x1, y1, x2, y2, x3, y3)
screen.drawTriangleF(x2, y2, x4, y4, x3, y3)
end
end
function easeLerp(v0, v1, t)
local ease = t <= 0.5 and 2 * t * t or -1 + (4 - 2 * t) * t
return v0 + (v1 - v0) * ease
end
function lerp(v0,v1,t)
return v0+t*(v1-v0)
end