Skip to content

Commit

Permalink
Reorganized file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Bloomer authored Nov 9, 2022
1 parent fef1293 commit 0c73a2f
Show file tree
Hide file tree
Showing 30 changed files with 3,631 additions and 0 deletions.
1 change: 1 addition & 0 deletions Construct ID License Plate/Dynamic License Plate - PB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"slot1.setScriptInput(construct.getId())","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":1}],"methods":[],"events":[]}
156 changes: 156 additions & 0 deletions Construct ID License Plate/Dynamic License Plate - renderscript.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
local atlas = require("atlas")
--user configurable variables
local bgplanet = 2
local planetsize = 400
local outlinecolor1R, outlinecolor1G, outlinecolor1B = 0, 1.5, 1.75
local outlinecolor2R, outlinecolor2G, outlinecolor2B = 0, 0.25, 0.5
local outlinecolor3R, outlinecolor3G, outlinecolor3B = 0, 0.25, 0.5
local textcolor1R, textcolor1G, textcolor1B = 1, 1, 1
local textcolor2R, textcolor2G, textcolor2B = 3, 3, 3
local spacebg = loadImage("assets.prod.novaquark.com/66839/ea555f35-0b6a-4c15-a4d4-d0d0b1e26927.png")
local drawspacebg = 1
--# Local rendering preparation
-- Create layers
local rear = createLayer()
local back = createLayer()
local front = createLayer()
local fore = createLayer()

local layer2 = createLayer()
local platetextsize = 200
local font1 = loadFont("Play",platetextsize)
local font2 = loadFont("Play",platetextsize/2)

local system = atlas[0]
local rx,ry = getResolution()

if drawspacebg == 1 then
addImage(rear, spacebg, 0, 0, rx, ry)
end

local images = {}
local function loadImages(src)
for k,img in pairs(images) do
if k == src then return img end
end
images[src] = loadImage(src)
return images[src]
end

local function contains(t, u)
for i,v in pairs(t) do
if v == u then return true, i end
end
return false
end

_planets = _planets or {}
local input, dist = getInput(), 0

if not _init then
if not system[_select] then
_select = 1
end
for _,b in pairs(system) do
if b.systemId == 0 then
if b.satellites then
table.sort (b.satellites, function (b1, b2) return system[b1].positionInSystem < system[b1].positionInSystem end )
end
_planets[#_planets+1] = b
end
end
table.sort (_planets, function (b1, b2) return b1.positionInSystem < b2.positionInSystem end )
_init = true
end

local planet = system[_select]
local vignette = loadImages(planet.iconPath)


--- Draw all planets
for i,body in pairs(_planets) do
-- For each planet load the icon from the atlas data
if i == bgplanet then
local img = loadImages(body.iconPath)
local hover = false
local r = planetsize
local bx, by = 450,350
local mbx = 224+(i*350)/6

if body.hasAtmosphere then
local atm = body.atmosphereRadius/900

setNextStrokeWidth( rear, 0.1)
setNextStrokeColor( rear, 1, 1, 1, 0.03)
setNextShadow( rear, 80, 1, 1, 1, 0.035)
setNextFillColor( rear, 1, 1, 1, 0.025)
addCircle( rear, bx, by, r)
end
--Draw planet image
addImage( back, img, bx-r, by-r, 2*r, 2*r)
--draw border
setNextShadow(fore,25,outlinecolor1R, outlinecolor1G, outlinecolor1B,1)
setNextStrokeWidth(fore,5)
setNextFillColor(fore,0,0,0,0)
addBoxRounded(fore, 25, 25, rx - 50, ry - 50, 20)

setNextShadow(fore,25,outlinecolor2R, outlinecolor2G, outlinecolor2B,1)
setNextFillColor(fore,textcolor1R, textcolor1G, textcolor1B,1)
local bndx,bndy = getTextBounds(font2,body.name[1])
addText(fore,font2,body.name[1],rx/2-(bndx/2),ry/2-(bndy/2)-100)
end
end

local baseCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
local baseLength = #baseCharacters

local floor = math.floor
local abs = math.abs
local sub = string.sub
function baseEncode(x, base)
assert(base, "Argument 2 missing or nil")
assert(not (base > baseLength or base < 2), "Base not in range of 2 - " .. baseLength)
local returnString = ""
local negative = x < 0
if negative then
x = abs(x)
end
local i = 0
local remainder
while x ~= 0 do
i = i + 1
x, remainder = floor(x / base), x % base + 1
returnString = sub(baseCharacters, remainder, remainder) .. returnString
end
return (negative and "-" or "") .. returnString
end
local find = string.find
function baseDecode(s, encodedBase)
if encodedBase <= 36 then
s = s:upper()
end

local positive = true
if sub(s, 1, 1) == "-" then
positive = false
s = sub(s, 2, -1)
end

local returnNumber = 0
local length = #s

for i = 1, length do
local currentCharacter = sub(s, i, i)
local characterValue = (find(baseCharacters, currentCharacter) - 1) * encodedBase ^ (length - i)
returnNumber = returnNumber + characterValue
end
return positive and returnNumber or -returnNumber
end
function convertBase(s, encodedBase, newBase)
return baseEncode(baseDecode(s, encodedBase), newBase)
end
local platetext = convertBase(getInput(), 10, 36)
local bndw, bndh = getTextBounds(font1,platetext)
setNextShadow(layer2,50,outlinecolor3R, outlinecolor3G, outlinecolor3B,1)
setNextFillColor(layer2,textcolor2R, textcolor2G, textcolor2B,1)
addText(layer2,font1,platetext,rx/2-(bndw/2),(ry/2)+100)
24 changes: 24 additions & 0 deletions Construct ID License Plate/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dynamic Ship License Plate

### Installation

Copy the content of renderscript.txt into the screen you wish to use to display the license plate.
You may either use a standalone programming board, or a control seat to set the input to the script.

To use a Programming Board: Paste PB.txt into a Programming Board as a config, and link it to the screen.
Any time the construct is compactified, the ID is regenerated, and the script input will need to be reset.
For this reason it may be preferable to use your control seat.

To use your Control Seat: Link the seat to the screen, edit the seat's Lua with CTRL+L, click Unit on the left, and then click the onStart filter.
Paste this line into the very bottom of the onStart filter's code;

[screenslot].setScriptInput(construct.getId())

where [screenslot] is replaced with the slot corresponding to the screen you linked earlier.

### Configuration

The colors and images are all customizable. Check the first couple lines of code.
To change the planet name and image displayed, simply change the "bgplanet" variable.
The values of this variable correspond to the entries in atlas.json.
For example, a value of 1 displays Madis, 2 displays Alioth, and 3 for Thades.
122 changes: 122 additions & 0 deletions Conway's Game of Life/Conways Game Of Life - Renderscript.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
if not init then
l1fontsize = 8
l1xoffset = -20
l1yoffset = 0
rx, ry = getResolution()
cx1, cy1 = math.floor(rx/l1fontsize-1), math.floor(ry/l1fontsize)
mem1 = {}
mem2 = {}
refresh = 1
for ix=1,cx1 do
mem1[ix] = {}
for iy=1,cy1 do
mem1[ix][iy] = math.random(math.floor(2))-1
if mem1[ix][iy] == 1 then
mem1[ix][iy] = math.random(math.floor(2))-1
if mem1[ix][iy] == 1 then
mem1[ix][iy] = math.random(math.floor(2))-1
if mem1[ix][iy] == 1 then
mem1[ix][iy] = math.random(math.floor(2))-1
end
end
end
end
end
for ix1=1,cx1 do
mem2[ix1] = {}
for iy1=1,cy1 do
mem2[ix1][iy1] = 0
end
end
init = true
end

fontL = loadFont("Play", 15)
layer1 = createLayer()
layer2 = createLayer()
cursorx, cursory = getCursor()
curx2 = math.floor(cursorx/8)+2
cury2 = math.floor(cursory/8)+1

setNextFillColor(layer2, 0.4, 0.4, 0.4, 0.3)
addBox(layer2, 100, 100, 100, 25)
if refresh == 1 then
setNextFillColor(layer2, 0, 1, 0, 0.3)
else
setNextFillColor(layer2, 1, 0, 0, 1)
end
addText(layer2,fontL,"Pause",125,115)

function updateStates()
for dx=1,cx1 do
for dy=1,cy1 do
--rules, in order
--mem2[dx][dy] = 0
--neighbors = 0
if dx > 1 and dx < cx1 then
if dy > 1 and dy < cy1 then
dx0 = dx - 1
dx2 = dx + 1
dy0 = dy - 1
dy2 = dy + 1
neighbors = mem1[dx0][dy0] + mem1[dx][dy0] + mem1[dx2][dy0] + mem1[dx0][dy] + mem1[dx2][dy] + mem1[dx0][dy2] + mem1[dx][dy2] + mem1[dx2][dy2]
if mem1[dx][dy] == 1 then
if neighbors == 2 or neighbors == 3 then
mem2[dx][dy] = 1
else
mem2[dx][dy] = 0
end
else
if neighbors == 3 then
mem2[dx][dy] = 1
else
mem2[dx][dy] = 0
end
end
end
end
end
end
mem1 = mem2
end

function DrawAllBoxes()
for bx=2,cx1 - 1 do
for by=2,cy1 - 1 do
if mem1[bx][by] == 1 then
setNextFillColor(layer1, 1, 1, 1, 1)
addBox(layer1, (bx*l1fontsize)+l1xoffset, (by*l1fontsize)+l1yoffset, l1fontsize, l1fontsize)
--addText(layer1,fontL,mem1[bx - 1][by - 1] + mem1[bx][by - 1] + mem1[bx + 1][by - 1] + mem1[bx - 1][by] + mem1[bx + 1][by] + mem1[bx - 1][by + 1] + mem1[bx][by + 1] + mem1[bx + 1][by + 1],(l1fontsize*bx)+l1xoffset, (l1fontsize*by)+l1yoffset)

--addText(layer1,fontL,mem2[bx][by],(l1fontsize*bx)+l1xoffset, (l1fontsize*by)+l1yoffset)
end
end
end
end

if refresh == 1 then
updateStates()
end


if getCursorReleased() then
if cursorx > 100 and cursorx < 200 then
if cursory > 100 and cursory < 125 then
if refresh == 1 then
refresh = 0
else
refresh = 1
end
end
end
if curx2 > 0 and cury2 > 0 then
if mem1[curx2][cury2] == 1 then
mem1[curx2][cury2] = 0
else
mem1[curx2][cury2] = 1
end
end
end

DrawAllBoxes()
requestAnimationFrame(1)
23 changes: 23 additions & 0 deletions Custom Font From Image/Custom Font.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local customfontimage = loadImage("assets.prod.novaquark.com/66839/e294a1f0-11ae-4fa1-a5f8-aeb02288eb24.png")
local layer1 = createLayer()
local layer2 = createLayer()
local font1 = loadFont("Play",20)
local rx,ry = getResolution()

setBackgroundColor(0.5,0.5,0.5)

function addCustomText(drawlayer, imagehandle, textstring, xpos, ypos, size, colorr, colorg, colorb, colora)
destructstring = textstring
for ix=1,#textstring do
nextletter = string.sub(destructstring,1,1)
destructstring = string.sub(destructstring,2,string.len(destructstring))
nextascii = string.byte(nextletter) - 33

local subxpos = math.fmod(nextascii,32)
local subypos = math.floor(nextascii / 32)
setNextFillColor(drawlayer, colorr, colorg, colorb, colora)
addImageSub(drawlayer, imagehandle, xpos+(ix * (size/2)), ypos, size, size, 0 + (68*subxpos), 0 + (68 * subypos), 68, 68)
end
end

addCustomText(layer1, customfontimage, "This is a custom font, rendered from an image file.", 50, 150, 28, 0,0,0,1)
Binary file added Custom Font From Image/customfont1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0c73a2f

Please sign in to comment.