Skip to content

Commit

Permalink
Additional included scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Jun 12, 2022
1 parent 7efe055 commit 070fd4c
Show file tree
Hide file tree
Showing 164 changed files with 21,229 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode
.vscode
*.kn5
data.zip
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

Some Lua internals for reference.

- `included-cars`: shared car scripts shipped with CSP builds (look for readme for information on how to include those in your car config);
- `included-tools`: shared tools shipped with CSP builds (can be accessed with Objects Inspector);
- `lua-module`: code used by Small Tweaks module adding all sorts of small things, too small to be kept in C++ code (feel free to use those modules as examples);
- `lua-shared`: shared libraries available by any Lua script running with CSP. To include, use “shared/” prefix, like `require('shared/socket')`.
18 changes: 18 additions & 0 deletions included-cars/android_auto/apps/car_info/app.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local carDir = ac.getFolder(ac.FolderID.ContentCars)..'/'..ac.getCarID(car.index)
local info = io.load(carDir..'/ui/ui_car.json')
local description = string.match(info, 'description".-"(.-)"'):gsub('<br>', '\n'):gsub('[\r\t]', ''):gsub('\n\n\n', '\n\n'):trim()

local skinsDir = carDir..'/skins'
local firstSkin = skinsDir..'/'..ac.getCarSkinID(0)..'/preview.jpg'

return function (dt)
ui.drawRectFilled(0, ui.windowSize(), rgbm.colors.black)
system.scrollList(dt, function ()
ui.image(firstSkin, vec2(1022, 575) * (math.min(400, ui.availableSpaceX()) / 1022))
ui.offsetCursorY(40)
ui.dwriteText(string.format('Driven distance: %.1f km', car.distanceDrivenTotalKm), 18)
ui.dwriteText(string.format('Fuel: %.0f L', car.fuel), 18)
ui.offsetCursorY(30)
ui.dwriteTextWrapped(description, 14)
end)
end
Binary file added included-cars/android_auto/apps/car_info/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions included-cars/android_auto/apps/car_info/manifest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ABOUT]
NAME = Car Info
AUTHOR = x4fab
VERSION = 1.0
DESCRIPTION = Information about car
26 changes: 26 additions & 0 deletions included-cars/android_auto/apps/car_info/service.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local brand = ac.getCarBrand(0)
if car.year < 2015 or #brand < 3 or #brand > 9 or brand:sub(1, 1):upper() ~= brand:sub(1, 1) or brand:match('[^A-Za-z ]') then
error('Might not be fitting app for this car')
end

local brandColors = {
['Audi'] = rgbm.colors.black
}

system.runningApp().name = 'My '..brand

-- Alternative way of making a dynamic icon: just set it to an extra canvas. Works well here,
-- because it only needs to be updated once.
system.runningApp().icon = ui.ExtraCanvas(64):clear(rgbm.colors.transparent):update(function (dt)
ui.setAsynchronousImagesLoading(false)
ui.drawCircleFilled(32, 30.3, brandColors[brand] or rgbm.colors.white, 30)
ui.renderTexture({
filename = ac.getFolder(ac.FolderID.ContentCars)..'/'..ac.getCarID(0)..'/ui/badge.png',
p1 = vec2(0, 0),
p2 = vec2(64, 64),
uv1 = vec2(-0.15, -0.15),
uv2 = vec2(1.3, 1.3),
mask1 = io.relative('icon.png'),
mask1Flags = render.TextureMaskFlags.UseAlpha
})
end)
Loading

0 comments on commit 070fd4c

Please sign in to comment.