:3
This commit is contained in:
parent
491112768c
commit
68ec37f994
66 changed files with 6591 additions and 10096 deletions
107
computer/0/apis/bitreader.lua
Normal file
107
computer/0/apis/bitreader.lua
Normal file
|
@ -0,0 +1,107 @@
|
|||
local bit = bit
|
||||
|
||||
local function readBit_b8(self)
|
||||
if (self.current > 8) then
|
||||
return false, false
|
||||
end
|
||||
|
||||
self.current = self.current + 1
|
||||
local v = bit.band(self._value, self._bits[self.current])
|
||||
|
||||
return self.current < 8, v > 0
|
||||
|
||||
end
|
||||
|
||||
local function new(self, value)
|
||||
self.current = 0
|
||||
self._value = value
|
||||
|
||||
end
|
||||
|
||||
function Bits8()
|
||||
-- Represents a byte, allows reading a bit at a time.
|
||||
local self = {}
|
||||
|
||||
self.current = 0
|
||||
self._value = 0
|
||||
self._bits = {128, 64, 32, 16, 8, 4, 2, 1}
|
||||
|
||||
self.readBit = readBit_b8
|
||||
self.new = new
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function readBit_br(self)
|
||||
local s, v = self.cb:readBit()
|
||||
if (not s) then
|
||||
self.pointer = self.pointer + 1
|
||||
self.cb:new(self.data[self.pointer])
|
||||
|
||||
end
|
||||
|
||||
return v
|
||||
|
||||
end
|
||||
|
||||
local function readBits(self, n)
|
||||
local bt = self._bittable
|
||||
for i = 1, n do
|
||||
bt[i] = self:readBit()
|
||||
|
||||
end
|
||||
for i = n+1, #bt do
|
||||
bt[i] = nil
|
||||
|
||||
end
|
||||
|
||||
return bt
|
||||
|
||||
end
|
||||
|
||||
local function readNumber(self, n)
|
||||
local m = 0
|
||||
|
||||
local t = self:readBits(n)
|
||||
for i = 1, #t do
|
||||
m = m * 2
|
||||
if (t[i]) then
|
||||
m = m + 1
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return m
|
||||
|
||||
end
|
||||
|
||||
local function reset(self)
|
||||
self.cb = Bits8()
|
||||
self.pointer = 1
|
||||
self.cb:new(self.data[self.pointer])
|
||||
|
||||
end
|
||||
|
||||
function BitReader(data)
|
||||
-- Class to read bits individually from a table of bytes.
|
||||
local self = {}
|
||||
|
||||
self.data = data
|
||||
self.cb = Bits8()
|
||||
self.pointer = 1
|
||||
self.cb:new(self.data[self.pointer])
|
||||
|
||||
self.readBit = readBit_br
|
||||
self.readBits = readBits
|
||||
self.readNumber = readNumber
|
||||
self.reset = reset
|
||||
|
||||
self._bittable = {}
|
||||
|
||||
return self
|
||||
|
||||
end
|
144
computer/0/apis/hexscreen.lua
Normal file
144
computer/0/apis/hexscreen.lua
Normal file
|
@ -0,0 +1,144 @@
|
|||
local table = table
|
||||
local string = string
|
||||
local term = term
|
||||
|
||||
local function draw(self)
|
||||
-- Draws the entire visible buffer.
|
||||
local te = self.term
|
||||
for y=1, self.height do
|
||||
te.setCursorPos(1, y)
|
||||
c0, c1, c2 = self:getLine(y)
|
||||
|
||||
te.blit(c0, c1, c2)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local n
|
||||
local b
|
||||
|
||||
local function getCharAt(self, x, y)
|
||||
n = 0
|
||||
b = self.buffer
|
||||
for i=y*3,y*3-2,-1 do
|
||||
for j=x*2,x*2-1,-1 do
|
||||
n = n * 2
|
||||
if (b[i][j]) then
|
||||
n = n + 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return n
|
||||
|
||||
end
|
||||
|
||||
local _t
|
||||
local _c
|
||||
local _bg
|
||||
local _cl
|
||||
local cs
|
||||
|
||||
local c
|
||||
|
||||
local function getLine(self, y)
|
||||
_t = self._text
|
||||
_c = self._color
|
||||
_bg = self._bgcolor
|
||||
_cl = self._charList
|
||||
|
||||
cs = self.colors
|
||||
|
||||
for x=1,self.width do
|
||||
c = self:getCharAt(x, y)
|
||||
_t[x] = _cl[c]
|
||||
|
||||
if (c >= 32) then
|
||||
_c[x] = cs[2]
|
||||
_bg[x] = cs[1]
|
||||
else
|
||||
_c[x] = cs[1]
|
||||
_bg[x] = cs[2]
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return table.concat(_t), table.concat(_c), table.concat(_bg)
|
||||
|
||||
end
|
||||
|
||||
local tb
|
||||
local function setSize(self, w, h)
|
||||
self.width, self.height = w, h
|
||||
self.b_width = self.height * 2
|
||||
self.b_height = self.height * 3
|
||||
|
||||
self.buffer = {}
|
||||
|
||||
for i=1, self.b_height do
|
||||
tb = {}
|
||||
for j=1, self.b_height do
|
||||
tb[j] = false
|
||||
end
|
||||
self.buffer[i] = tb
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function setSizeBuffer(self, w, h)
|
||||
self:setSize(math.floor(w/2), math.floor(h/3))
|
||||
|
||||
end
|
||||
|
||||
function HexScreen(customTerm)
|
||||
local self = {}
|
||||
|
||||
self.term = customTerm or term
|
||||
|
||||
self.width, self.height = self.term.getSize()
|
||||
self.b_width = self.width * 2
|
||||
self.b_height = self.height * 3
|
||||
|
||||
self.buffer = {}
|
||||
|
||||
for i=1, self.b_height do
|
||||
local t = {}
|
||||
for j=1, self.b_height do
|
||||
table.insert(t, false)
|
||||
end
|
||||
table.insert(self.buffer, t)
|
||||
end
|
||||
|
||||
self._text = {}
|
||||
self._color = {}
|
||||
self._bgcolor = {}
|
||||
|
||||
self.colors = {"0", "f"}
|
||||
|
||||
self._charList = {}
|
||||
for i=0,63 do
|
||||
if (i < 32) then
|
||||
c = string.char(128 + i)
|
||||
|
||||
else
|
||||
c = string.char(191 - i)
|
||||
|
||||
end
|
||||
|
||||
self._charList[i] = c
|
||||
|
||||
end
|
||||
|
||||
self.draw = draw
|
||||
self.getCharAt = getCharAt
|
||||
self.getLine = getLine
|
||||
self.setSize = setSize
|
||||
self.setSizeBuffer = setSizeBuffer
|
||||
|
||||
return self
|
||||
|
||||
end
|
427
computer/0/apis/wave.lua
Normal file
427
computer/0/apis/wave.lua
Normal file
|
@ -0,0 +1,427 @@
|
|||
--[[
|
||||
wave version 0.1.5
|
||||
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2020 CrazedProgrammer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
-- I'm so happy I don't have to write or understand this code, thanks! - ax.
|
||||
|
||||
|
||||
local wave = { }
|
||||
wave.version = "0.1.5"
|
||||
|
||||
wave._oldSoundMap = {"harp", "bassattack", "bd", "snare", "hat"}
|
||||
wave._newSoundMap = {"harp", "bass", "basedrum", "snare", "hat"}
|
||||
wave._defaultThrottle = 99
|
||||
wave._defaultClipMode = 1
|
||||
wave._maxInterval = 1
|
||||
wave._isNewSystem = false
|
||||
if _HOST then
|
||||
-- Redoing this, the correct and boring way, otherwise it doesn't work with versions above 1.100 until 1.800. - axisok
|
||||
-- Likely to break only if CC:Tweaked changes how it writes versions.
|
||||
local _matches = {}
|
||||
for s in string.gmatch(_HOST, "%S+") do
|
||||
_matches[#_matches + 1] = s
|
||||
end
|
||||
|
||||
local _v = _matches[2]
|
||||
_matches = {}
|
||||
for s in string.gmatch(_v, "%P+") do
|
||||
_matches[#_matches + 1] = s
|
||||
end
|
||||
|
||||
local _new = {1, 80}
|
||||
wave._isNewSystem = true
|
||||
for i=1, #_new, 1 do
|
||||
if (i <= #_matches and _new[i] < tonumber(_matches[i])) then
|
||||
break
|
||||
|
||||
elseif (i <= #_matches and _new[i] > tonumber(_matches[i])) then
|
||||
wave._isNewSystem = false
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
wave.context = { }
|
||||
wave.output = { }
|
||||
wave.track = { }
|
||||
wave.instance = { }
|
||||
|
||||
function wave.createContext(clock, volume)
|
||||
clock = clock or os.clock()
|
||||
volume = volume or 1.0
|
||||
|
||||
local context = setmetatable({ }, {__index = wave.context})
|
||||
context.outputs = { }
|
||||
context.instances = { }
|
||||
context.vs = {0, 0, 0, 0, 0}
|
||||
context.prevClock = clock
|
||||
context.volume = volume
|
||||
return context
|
||||
end
|
||||
|
||||
function wave.context:addOutput(...)
|
||||
local output = wave.createOutput(...)
|
||||
self.outputs[#self.outputs + 1] = output
|
||||
return output
|
||||
end
|
||||
|
||||
function wave.context:addOutputs(...)
|
||||
local outs = {...}
|
||||
if #outs == 1 then
|
||||
if not getmetatable(outs) then
|
||||
outs = outs[1]
|
||||
else
|
||||
if getmetatable(outs).__index ~= wave.outputs then
|
||||
outs = outs[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
for i = 1, #outs do
|
||||
self:addOutput(outs[i])
|
||||
end
|
||||
end
|
||||
|
||||
function wave.context:removeOutput(out)
|
||||
if type(out) == "number" then
|
||||
table.remove(self.outputs, out)
|
||||
return
|
||||
elseif type(out) == "table" then
|
||||
if getmetatable(out).__index == wave.output then
|
||||
for i = 1, #self.outputs do
|
||||
if out == self.outputs[i] then
|
||||
table.remove(self.outputs, i)
|
||||
return
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
for i = 1, #self.outputs do
|
||||
if out == self.outputs[i].native then
|
||||
table.remove(self.outputs, i)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wave.context:addInstance(...)
|
||||
local instance = wave.createInstance(...)
|
||||
self.instances[#self.instances + 1] = instance
|
||||
return instance
|
||||
end
|
||||
|
||||
function wave.context:removeInstance(instance)
|
||||
if type(instance) == "number" then
|
||||
table.remove(self.instances, instance)
|
||||
else
|
||||
for i = 1, #self.instances do
|
||||
if self.instances == instance then
|
||||
table.remove(self.instances, i)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wave.context:playNote(note, pitch, volume)
|
||||
volume = volume or 1.0
|
||||
|
||||
self.vs[note] = self.vs[note] + volume
|
||||
for i = 1, #self.outputs do
|
||||
self.outputs[i]:playNote(note, pitch, volume * self.volume)
|
||||
end
|
||||
end
|
||||
|
||||
function wave.context:update(interval)
|
||||
local clock = os.clock()
|
||||
interval = interval or (clock - self.prevClock)
|
||||
|
||||
self.prevClock = clock
|
||||
if interval > wave._maxInterval then
|
||||
interval = wave._maxInterval
|
||||
end
|
||||
for i = 1, #self.outputs do
|
||||
self.outputs[i].notes = 0
|
||||
end
|
||||
for i = 1, 5 do
|
||||
self.vs[i] = 0
|
||||
end
|
||||
if interval > 0 then
|
||||
for i = 1, #self.instances do
|
||||
local notes = self.instances[i]:update(interval)
|
||||
for j = 1, #notes / 3 do
|
||||
self:playNote(notes[j * 3 - 2], notes[j * 3 - 1], notes[j * 3])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function wave.createOutput(out, volume, filter, throttle, clipMode)
|
||||
volume = volume or 1.0
|
||||
filter = filter or {true, true, true, true, true}
|
||||
throttle = throttle or wave._defaultThrottle
|
||||
clipMode = clipMode or wave._defaultClipMode
|
||||
|
||||
local output = setmetatable({ }, {__index = wave.output})
|
||||
output.native = out
|
||||
output.volume = volume
|
||||
output.filter = filter
|
||||
output.notes = 0
|
||||
output.throttle = throttle
|
||||
output.clipMode = clipMode
|
||||
if type(out) == "function" then
|
||||
output.nativePlayNote = out
|
||||
output.type = "custom"
|
||||
return output
|
||||
elseif type(out) == "string" then
|
||||
if peripheral.getType(out) == "iron_noteblock" then
|
||||
if wave._isNewSystem then
|
||||
local nb = peripheral.wrap(out)
|
||||
output.type = "iron_noteblock"
|
||||
function output.nativePlayNote(note, pitch, vol)
|
||||
if output.volume * vol > 0 then
|
||||
nb.playSound("minecraft:block.note."..wave._newSoundMap[note], vol, math.pow(2, (pitch - 12) / 12))
|
||||
end
|
||||
end
|
||||
return output
|
||||
end
|
||||
elseif peripheral.getType(out) == "speaker" then
|
||||
if wave._isNewSystem then
|
||||
local nb = peripheral.wrap(out)
|
||||
output.type = "speaker"
|
||||
function output.nativePlayNote(note, pitch, vol)
|
||||
if output.volume * vol > 0 then
|
||||
nb.playNote(wave._newSoundMap[note], vol, pitch)
|
||||
end
|
||||
end
|
||||
return output
|
||||
end
|
||||
end
|
||||
elseif type(out) == "table" then
|
||||
if out.execAsync then
|
||||
output.type = "commands"
|
||||
if wave._isNewSystem then
|
||||
function output.nativePlayNote(note, pitch, vol)
|
||||
out.execAsync("playsound minecraft:block.note."..wave._newSoundMap[note].." record @a ~ ~ ~ "..tostring(vol).." "..tostring(math.pow(2, (pitch - 12) / 12)))
|
||||
end
|
||||
else
|
||||
function output.nativePlayNote(note, pitch, vol)
|
||||
out.execAsync("playsound note."..wave._oldSoundMap[note].." @a ~ ~ ~ "..tostring(vol).." "..tostring(math.pow(2, (pitch - 12) / 12)))
|
||||
end
|
||||
end
|
||||
return output
|
||||
elseif getmetatable(out) then
|
||||
if getmetatable(out).__index == wave.output then
|
||||
return out
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wave.scanOutputs()
|
||||
local outs = { }
|
||||
if commands then
|
||||
outs[#outs + 1] = wave.createOutput(commands)
|
||||
end
|
||||
local sides = peripheral.getNames()
|
||||
for i = 1, #sides do
|
||||
if peripheral.getType(sides[i]) == "iron_noteblock" then
|
||||
outs[#outs + 1] = wave.createOutput(sides[i])
|
||||
elseif peripheral.getType(sides[i]) == "speaker" then
|
||||
outs[#outs + 1] = wave.createOutput(sides[i])
|
||||
end
|
||||
end
|
||||
return outs
|
||||
end
|
||||
|
||||
function wave.output:playNote(note, pitch, volume)
|
||||
volume = volume or 1.0
|
||||
|
||||
if self.clipMode == 1 then
|
||||
if pitch < 0 then
|
||||
pitch = 0
|
||||
elseif pitch > 24 then
|
||||
pitch = 24
|
||||
end
|
||||
elseif self.clipMode == 2 then
|
||||
if pitch < 0 then
|
||||
while pitch < 0 do
|
||||
pitch = pitch + 12
|
||||
end
|
||||
elseif pitch > 24 then
|
||||
while pitch > 24 do
|
||||
pitch = pitch - 12
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.filter[note] and self.notes < self.throttle then
|
||||
self.nativePlayNote(note, pitch, volume * self.volume)
|
||||
self.notes = self.notes + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function wave.loadTrack(path)
|
||||
local track = setmetatable({ }, {__index = wave.track})
|
||||
local handle = fs.open(path, "rb")
|
||||
if not handle then return end
|
||||
|
||||
local function readInt(size)
|
||||
local num = 0
|
||||
for i = 0, size - 1 do
|
||||
local byte = handle.read()
|
||||
if not byte then -- dont leave open file handles no matter what
|
||||
handle.close()
|
||||
return
|
||||
end
|
||||
num = num + byte * (256 ^ i)
|
||||
end
|
||||
return num
|
||||
end
|
||||
local function readStr()
|
||||
local length = readInt(4)
|
||||
if not length then return end
|
||||
local data = { }
|
||||
for i = 1, length do
|
||||
data[i] = string.char(handle.read())
|
||||
end
|
||||
return table.concat(data)
|
||||
end
|
||||
|
||||
-- Part #1: Metadata
|
||||
track.length = readInt(2) -- song length (ticks)
|
||||
track.height = readInt(2) -- song height
|
||||
track.name = readStr() -- song name
|
||||
track.author = readStr() -- song author
|
||||
track.originalAuthor = readStr() -- original song author
|
||||
track.description = readStr() -- song description
|
||||
track.tempo = readInt(2) / 100 -- tempo (ticks per second)
|
||||
track.autoSaving = readInt(1) == 0 and true or false -- auto-saving
|
||||
track.autoSavingDuration = readInt(1) -- auto-saving duration
|
||||
track.timeSignature = readInt(1) -- time signature (3 = 3/4)
|
||||
track.minutesSpent = readInt(4) -- minutes spent
|
||||
track.leftClicks = readInt(4) -- left clicks
|
||||
track.rightClicks = readInt(4) -- right clicks
|
||||
track.blocksAdded = readInt(4) -- blocks added
|
||||
track.blocksRemoved = readInt(4) -- blocks removed
|
||||
track.schematicFileName = readStr() -- midi/schematic file name
|
||||
|
||||
-- Part #2: Notes
|
||||
track.layers = { }
|
||||
for i = 1, track.height do
|
||||
track.layers[i] = {name = "Layer "..i, volume = 1.0}
|
||||
track.layers[i].notes = { }
|
||||
end
|
||||
|
||||
local tick = 0
|
||||
while true do
|
||||
local tickJumps = readInt(2)
|
||||
if tickJumps == 0 then break end
|
||||
tick = tick + tickJumps
|
||||
local layer = 0
|
||||
while true do
|
||||
local layerJumps = readInt(2)
|
||||
if layerJumps == 0 then break end
|
||||
layer = layer + layerJumps
|
||||
if layer > track.height then -- nbs can be buggy
|
||||
for i = track.height + 1, layer do
|
||||
track.layers[i] = {name = "Layer "..i, volume = 1.0}
|
||||
track.layers[i].notes = { }
|
||||
end
|
||||
track.height = layer
|
||||
end
|
||||
local instrument = readInt(1)
|
||||
local key = readInt(1)
|
||||
if instrument <= 4 then -- nbs can be buggy
|
||||
track.layers[layer].notes[tick * 2 - 1] = instrument + 1
|
||||
track.layers[layer].notes[tick * 2] = key - 33
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Part #3: Layers
|
||||
for i = 1, track.height do
|
||||
local name = readStr()
|
||||
if not name then break end -- if layer data doesnt exist, abort
|
||||
track.layers[i].name = name
|
||||
track.layers[i].volume = readInt(1) / 100
|
||||
end
|
||||
|
||||
handle.close()
|
||||
return track
|
||||
end
|
||||
|
||||
|
||||
|
||||
function wave.createInstance(track, volume, playing, loop)
|
||||
volume = volume or 1.0
|
||||
playing = (playing == nil) or playing
|
||||
loop = (loop ~= nil) and loop
|
||||
|
||||
if getmetatable(track).__index == wave.instance then
|
||||
return track
|
||||
end
|
||||
local instance = setmetatable({ }, {__index = wave.instance})
|
||||
instance.track = track
|
||||
instance.volume = volume or 1.0
|
||||
instance.playing = playing
|
||||
instance.loop = loop
|
||||
instance.tick = 1
|
||||
return instance
|
||||
end
|
||||
|
||||
function wave.instance:update(interval)
|
||||
local notes = { }
|
||||
if self.playing then
|
||||
local dticks = interval * self.track.tempo
|
||||
local starttick = self.tick
|
||||
local endtick = starttick + dticks
|
||||
local istarttick = math.ceil(starttick)
|
||||
local iendtick = math.ceil(endtick) - 1
|
||||
for i = istarttick, iendtick do
|
||||
for j = 1, self.track.height do
|
||||
if self.track.layers[j].notes[i * 2 - 1] then
|
||||
notes[#notes + 1] = self.track.layers[j].notes[i * 2 - 1]
|
||||
notes[#notes + 1] = self.track.layers[j].notes[i * 2]
|
||||
notes[#notes + 1] = self.track.layers[j].volume
|
||||
end
|
||||
end
|
||||
end
|
||||
self.tick = self.tick + dticks
|
||||
|
||||
if endtick > self.track.length then
|
||||
self.tick = 1
|
||||
self.playing = self.loop
|
||||
end
|
||||
end
|
||||
return notes
|
||||
end
|
||||
|
||||
|
||||
|
||||
return wave
|
BIN
computer/0/badapple.nbs
Normal file
BIN
computer/0/badapple.nbs
Normal file
Binary file not shown.
BIN
computer/0/badapple.qtv
Normal file
BIN
computer/0/badapple.qtv
Normal file
Binary file not shown.
55
computer/0/sounds.lua
Normal file
55
computer/0/sounds.lua
Normal file
|
@ -0,0 +1,55 @@
|
|||
noteblock = peripheral.wrap("right")
|
||||
sfx = require("sfx")
|
||||
speaker = peripheral.wrap("left")
|
||||
instruments = {
|
||||
"harp",
|
||||
"bass",
|
||||
"didgeridoo",
|
||||
"xylophone",
|
||||
"iron_xylophone",
|
||||
"snare",
|
||||
"hat",
|
||||
"basedrum",
|
||||
"bit",
|
||||
"bit",
|
||||
"bit",
|
||||
"bit"
|
||||
}
|
||||
mobs = {
|
||||
"skeleton",
|
||||
"zombie",
|
||||
"pig",
|
||||
"cow",
|
||||
"spider"
|
||||
}
|
||||
function sound()
|
||||
while true do
|
||||
if math.random(10)>5 then
|
||||
speaker.playSound("entity."..mobs[math.random(#mobs)]..".ambient",10)
|
||||
elseif math.random(100) < 95 then
|
||||
noteblock.setInstrument(instruments[math.random(#instruments)])
|
||||
noteblock.play()
|
||||
noteblock.setNote(math.random(24))
|
||||
elseif math.random(100) < 50 then
|
||||
for i = 1,5 do
|
||||
speaker.playSound("entity.creeper.step")
|
||||
sleep(0.05)
|
||||
end
|
||||
speaker.playSound("entity.creeper.primed")
|
||||
else
|
||||
--speaker.playSound("BOOM")
|
||||
end
|
||||
sleep(math.random(1,20))
|
||||
--os.reboot()
|
||||
end
|
||||
end
|
||||
while false and true do
|
||||
--sound()
|
||||
if math.random(100) then
|
||||
sfx.success()
|
||||
sleep(math.random(1,4))
|
||||
end
|
||||
end
|
||||
parallel.waitForAll(sound,sound,sound,sound,sound)
|
||||
peripheral.call("top","turnOn")
|
||||
os.reboot()
|
|
@ -1,55 +1,22 @@
|
|||
noteblock = peripheral.wrap("right")
|
||||
sfx = require("sfx")
|
||||
speaker = peripheral.wrap("left")
|
||||
instruments = {
|
||||
"harp",
|
||||
"bass",
|
||||
"didgeridoo",
|
||||
"xylophone",
|
||||
"iron_xylophone",
|
||||
"snare",
|
||||
"hat",
|
||||
"basedrum",
|
||||
"bit",
|
||||
"bit",
|
||||
"bit",
|
||||
"bit"
|
||||
}
|
||||
mobs = {
|
||||
"skeleton",
|
||||
"zombie",
|
||||
"pig",
|
||||
"cow",
|
||||
"spider"
|
||||
}
|
||||
function sound()
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
|
||||
speaker = peripheral.wrap("right")
|
||||
while true do
|
||||
if math.random(10)>5 then
|
||||
speaker.playSound("entity."..mobs[math.random(#mobs)]..".ambient")
|
||||
elseif math.random(100) < 95 then
|
||||
noteblock.setInstrument(instruments[math.random(#instruments)])
|
||||
noteblock.play()
|
||||
noteblock.setNote(math.random(24))
|
||||
elseif math.random(100) < 50 then
|
||||
for i = 1,5 do
|
||||
speaker.playSound("entity.creeper.step")
|
||||
sleep(0.05)
|
||||
end
|
||||
speaker.playSound("entity.creeper.primed")
|
||||
else
|
||||
--speaker.playSound("BOOM")
|
||||
for i = 1,100 do
|
||||
pitch = math.random()*0.4+0.8
|
||||
volume = math.random()*.5+1.5
|
||||
--print("pitch: "..pitch,"volume: "..volume)
|
||||
speaker.playSound(
|
||||
"entity.wandering_trader.ambient",
|
||||
volume,
|
||||
pitch
|
||||
)
|
||||
--sleep(math.random()*3+1)
|
||||
end
|
||||
sleep(math.random(1,20))
|
||||
--os.reboot()
|
||||
--sleep(math.random(300,600))
|
||||
shell.run("pastebin", "run", "KMRmKTc1")
|
||||
sleep(math.random(300,600))
|
||||
end
|
||||
end
|
||||
while true do
|
||||
--sound()
|
||||
if math.random(100) > 97 or true then
|
||||
sfx.success()
|
||||
sleep(math.random(1,4))
|
||||
end
|
||||
end
|
||||
parallel.waitForAll(sound,sound,sound,sound,sound)
|
||||
peripheral.call("top","turnOn")
|
||||
-- os.reboot()
|
||||
|
||||
|
||||
|
|
283
computer/0/videoplayer.lua
Normal file
283
computer/0/videoplayer.lua
Normal file
|
@ -0,0 +1,283 @@
|
|||
require("apis.hexscreen")
|
||||
require("apis.bitreader")
|
||||
local wave = require("apis.wave")
|
||||
|
||||
local math = math
|
||||
local sleep = sleep
|
||||
local string = string
|
||||
local screen = term
|
||||
|
||||
local data
|
||||
local frame
|
||||
|
||||
local reader
|
||||
|
||||
local width
|
||||
local height
|
||||
local sleep_ticks
|
||||
|
||||
local _width_bits
|
||||
local _height_bits
|
||||
|
||||
local fi
|
||||
|
||||
local arg = {...}
|
||||
|
||||
local function findPer(pName)
|
||||
if (peripheral.getName) then
|
||||
local p = peripheral.find(pName)
|
||||
local n
|
||||
|
||||
if (p) then
|
||||
n = peripheral.getName(p)
|
||||
end
|
||||
|
||||
return n, p
|
||||
|
||||
else
|
||||
local d = {"top", "bottom", "right", "left", "front", "back"}
|
||||
for i=1, #d do
|
||||
if (peripheral.getType(d[i]) == pName) then
|
||||
local p = peripheral.wrap(d[i])
|
||||
local n = d[i]
|
||||
return n, p
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function invertQuad(x, y, w, h)
|
||||
for i=y, y+h-1 do
|
||||
fi = frame[i]
|
||||
for j=x, x+w-1 do
|
||||
fi[j] = not fi[j]
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
return frame
|
||||
|
||||
end
|
||||
|
||||
local function readQuad(x, y, w, h)
|
||||
if (w * h == 0) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if (reader:readBit()) then
|
||||
-- Splits into 4 more quads.
|
||||
|
||||
local cw = math.ceil(w/2)
|
||||
local ch = math.ceil(h/2)
|
||||
local fw = math.floor(w/2)
|
||||
local fh = math.floor(h/2)
|
||||
|
||||
readQuad(x, y, cw, ch)
|
||||
readQuad(x+cw, y, fw, ch)
|
||||
readQuad(x, y+ch, cw, fh)
|
||||
readQuad(x+cw, y+ch, fw, fh)
|
||||
|
||||
else
|
||||
-- Doesn't split.
|
||||
if (reader:readBit()) then
|
||||
-- Inverts the region of this quad.
|
||||
invertQuad(x, y, w, h)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local fx
|
||||
local fy
|
||||
|
||||
local w_bits
|
||||
local h_bits
|
||||
|
||||
local frw
|
||||
local frh
|
||||
|
||||
local function readFrame()
|
||||
fx = reader:readNumber(_width_bits)
|
||||
fy = reader:readNumber(_height_bits)
|
||||
|
||||
w_bits = 0
|
||||
h_bits = 0
|
||||
|
||||
while (2^w_bits <= width - fx) do
|
||||
w_bits = w_bits + 1
|
||||
end
|
||||
|
||||
while (2^h_bits <= height - fy) do
|
||||
h_bits = h_bits + 1
|
||||
end
|
||||
|
||||
frw = reader:readNumber(w_bits)
|
||||
|
||||
if (frw == 0) then
|
||||
return
|
||||
end
|
||||
frh = reader:readNumber(h_bits)
|
||||
|
||||
|
||||
|
||||
|
||||
readQuad(fx+1, fy+1, frw, frh)
|
||||
|
||||
end
|
||||
|
||||
local loop = false
|
||||
for i=1, #arg do
|
||||
if (arg[i] == "loop") then
|
||||
loop = true
|
||||
table.remove(arg, i)
|
||||
break
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
print("Reading files...")
|
||||
|
||||
local videofile = arg[1]
|
||||
local audiofile
|
||||
|
||||
local dPos = videofile:find("%.")
|
||||
if (dPos) then
|
||||
audiofile = videofile:sub(1, dPos-1) .. ".nbs"
|
||||
|
||||
else
|
||||
audiofile = videofile .. ".nbs"
|
||||
videofile = videofile .. ".qtv"
|
||||
|
||||
end
|
||||
|
||||
-- Read the audio file
|
||||
local wc
|
||||
if (audiofile and fs.exists(audiofile)) then
|
||||
local dir, speaker = findPer("speaker")
|
||||
|
||||
if (speaker ~= nil) then
|
||||
wc = wave.createContext()
|
||||
wc:addOutput(dir)
|
||||
local t = wave.loadTrack(audiofile)
|
||||
wc:addInstance(wave.createInstance(t))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- Read the video file
|
||||
if (not fs.exists(videofile)) then
|
||||
error("video file '" .. videofile .. "' not found.")
|
||||
|
||||
end
|
||||
|
||||
local f = fs.open(videofile, "rb")
|
||||
local fileString = f.readAll()
|
||||
data = {string.byte(fileString, 1, -1)}
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
reader = BitReader(data)
|
||||
|
||||
sleep_ticks = reader:readNumber(5)+1
|
||||
width = reader:readNumber(10)+1
|
||||
height = reader:readNumber(9)+1
|
||||
|
||||
_width_bits = 0
|
||||
_height_bits = 0
|
||||
|
||||
while (2^_width_bits <= width) do
|
||||
_width_bits = _width_bits + 1
|
||||
end
|
||||
|
||||
while (2^_height_bits <= height) do
|
||||
_height_bits = _height_bits + 1
|
||||
end
|
||||
|
||||
local mon = peripheral.find("monitor")
|
||||
|
||||
if (mon ~= nil) then
|
||||
screen = mon
|
||||
|
||||
for s=5,0.5,-0.5 do
|
||||
screen.setTextScale(s)
|
||||
w, h = screen.getSize()
|
||||
if (width <= (w+1)*2 or height <= (h+1)*3) then
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local hs = HexScreen(screen)
|
||||
hs:setSizeBuffer(width, height)
|
||||
|
||||
local fri
|
||||
|
||||
frame = {}
|
||||
for i=1, height do
|
||||
frame[i] = {}
|
||||
fri = frame[i]
|
||||
for j=1, width do
|
||||
fri[j] = false
|
||||
end
|
||||
end
|
||||
|
||||
hs.buffer = frame
|
||||
local status, err
|
||||
while true do
|
||||
status, err = pcall(readFrame)
|
||||
|
||||
if (not status) then
|
||||
if (not loop) then
|
||||
break
|
||||
end
|
||||
|
||||
reader:reset()
|
||||
reader:readNumber(5)
|
||||
reader:readNumber(10)
|
||||
reader:readNumber(9)
|
||||
|
||||
frame = {}
|
||||
for i=1, height do
|
||||
frame[i] = {}
|
||||
fri = frame[i]
|
||||
for j=1, width do
|
||||
fri[j] = false
|
||||
end
|
||||
end
|
||||
|
||||
hs.buffer = frame
|
||||
|
||||
if (wc) then
|
||||
for i = 1, #wc.instances do
|
||||
wc.instances[i].playing = true
|
||||
wc.instances[i].tick = 1
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
hs:draw()
|
||||
|
||||
if (wc) then
|
||||
pcall(wc.update, wc, 0.05)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
sleep(0.05 * sleep_ticks)
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue