Re-engineer the tech stack
This commit is contained in:
parent
8bfc345258
commit
34200373d7
2
minetest-api.d.ts
vendored
2
minetest-api.d.ts
vendored
@ -1245,7 +1245,7 @@ declare global {
|
||||
get_physics_override(): PhysicsOverride
|
||||
hud_add(definition: HudDefinition): number
|
||||
hud_remove(id: number): void
|
||||
hud_change(id: number, stat: HudElementType, value: any): void
|
||||
hud_change(id: number, stat: string, value: any): void
|
||||
hud_get(id: number): HudDefinition
|
||||
hud_set_flags(flags: HudFlags): void
|
||||
hud_get_flags(): HudFlags
|
||||
|
@ -34,9 +34,6 @@ do
|
||||
})
|
||||
player:set_moon({visible = false})
|
||||
player:set_sun({visible = false, sunrise_visible = false})
|
||||
minetest.register_on_player_receive_fields(function(_, __, fields)
|
||||
mineos.getSystem():triggerCallbacks(fields)
|
||||
end)
|
||||
end)
|
||||
function mineos.osFrameBufferPoll()
|
||||
local monitorInformation = minetest.get_player_window_information("singleplayer")
|
||||
@ -50,59 +47,60 @@ do
|
||||
function mineos.osKeyboardPoll(key)
|
||||
local a = minetest.get_player_by_name("singleplayer"):get_player_control()
|
||||
repeat
|
||||
local ____switch8 = key
|
||||
local ____cond8 = ____switch8 == "up"
|
||||
if ____cond8 then
|
||||
local ____switch7 = key
|
||||
local ____cond7 = ____switch7 == "up"
|
||||
if ____cond7 then
|
||||
return a.up
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "down"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "down"
|
||||
if ____cond7 then
|
||||
return a.down
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "left"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "left"
|
||||
if ____cond7 then
|
||||
return a.left
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "right"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "right"
|
||||
if ____cond7 then
|
||||
return a.right
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "jump"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "jump"
|
||||
if ____cond7 then
|
||||
return a.jump
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "aux1"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "aux1"
|
||||
if ____cond7 then
|
||||
return a.aux1
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "sneak"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "sneak"
|
||||
if ____cond7 then
|
||||
return a.sneak
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "dig"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "dig"
|
||||
if ____cond7 then
|
||||
return a.dig
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "place"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "place"
|
||||
if ____cond7 then
|
||||
return a.place
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "LMB"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "LMB"
|
||||
if ____cond7 then
|
||||
return a.LMB
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "RMB"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "RMB"
|
||||
if ____cond7 then
|
||||
return a.RMB
|
||||
end
|
||||
____cond8 = ____cond8 or ____switch8 == "zoom"
|
||||
if ____cond8 then
|
||||
____cond7 = ____cond7 or ____switch7 == "zoom"
|
||||
if ____cond7 then
|
||||
return a.zoom
|
||||
end
|
||||
until true
|
||||
return false
|
||||
end
|
||||
minetest.register_on_joinplayer(function()
|
||||
minetest.register_on_joinplayer(function(driver)
|
||||
mineos.initializeSystem(driver)
|
||||
mineos.getSystem():triggerBoot()
|
||||
end)
|
||||
mineos.System.out:println("hacks loaded.")
|
||||
|
@ -1,10 +1,5 @@
|
||||
namespace mineos {
|
||||
|
||||
// Oh yeah we're taking it that far
|
||||
export type Driver = ObjectRef;
|
||||
export type GUIComponent = HudDefinition;
|
||||
export type GUIType = HudElementType;
|
||||
|
||||
minetest.register_on_joinplayer((player: ObjectRef) => {
|
||||
player.set_physics_override({
|
||||
gravity: 0
|
||||
@ -55,9 +50,9 @@ namespace mineos {
|
||||
})
|
||||
|
||||
// "OS sends the program things" or some nonsense
|
||||
minetest.register_on_player_receive_fields((_: ObjectRef, __: string, fields: {[id: string] : any}) => {
|
||||
getSystem().triggerCallbacks(fields)
|
||||
})
|
||||
// minetest.register_on_player_receive_fields((_: ObjectRef, __: string, fields: {[id: string] : any}) => {
|
||||
// // getSystem().triggerCallbacks(fields)
|
||||
// })
|
||||
|
||||
|
||||
})
|
||||
@ -94,10 +89,9 @@ namespace mineos {
|
||||
}
|
||||
|
||||
// Automatically start mineos when the player loads in.
|
||||
minetest.register_on_joinplayer(() => {
|
||||
minetest.register_on_joinplayer((driver: ObjectRef) => {
|
||||
mineos.initializeSystem(driver)
|
||||
getSystem().triggerBoot()
|
||||
})
|
||||
|
||||
|
||||
System.out.println("hacks loaded.")
|
||||
}
|
@ -20,8 +20,10 @@ do
|
||||
"programs/programs",
|
||||
"hacks"
|
||||
})
|
||||
local system = __TS__New(mineos.System)
|
||||
minetest.register_globalstep(function(delta)
|
||||
system:main(delta)
|
||||
end)
|
||||
function mineos.initializeSystem(driver)
|
||||
local system = __TS__New(mineos.System, driver)
|
||||
minetest.register_globalstep(function(delta)
|
||||
system:main(delta)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
@ -16,10 +16,13 @@ namespace mineos {
|
||||
// Computer turns on. Beep boop.
|
||||
|
||||
// Hard drive spins up.
|
||||
const system = new System();
|
||||
export function initializeSystem(driver: Driver) {
|
||||
|
||||
// Now begins mineos.
|
||||
minetest.register_globalstep((delta: number) => {
|
||||
system.main(delta)
|
||||
})
|
||||
const system = new System(driver);
|
||||
|
||||
// Now begins mineos.
|
||||
minetest.register_globalstep((delta: number) => {
|
||||
system.main(delta)
|
||||
})
|
||||
}
|
||||
}
|
@ -48,13 +48,6 @@ do
|
||||
local color = colors.color
|
||||
local colorRGB = colors.colorRGB
|
||||
local colorScalar = colors.colorScalar
|
||||
local function sendStartMenuSignal(_)
|
||||
print("hi")
|
||||
local system = mineos.getSystem()
|
||||
local currProg = system.currentProgram
|
||||
currProg.startMenuFlag = true
|
||||
system.audioController:playSound("mouseClick", 1)
|
||||
end
|
||||
local RunProcedure = __TS__Class()
|
||||
RunProcedure.name = "RunProcedure"
|
||||
__TS__ClassExtends(RunProcedure, mineos.Program)
|
||||
@ -90,10 +83,8 @@ do
|
||||
function RunProcedure.prototype.loadDesktop(self)
|
||||
mineos.System.out:println("loading desktop environment")
|
||||
self.audioController:playSound("osStartup", 0.9)
|
||||
self.system:clearCallbacks()
|
||||
self.renderer:clearMemory()
|
||||
self.renderer:setClearColor(0, 0, 0)
|
||||
self.system:registerCallback("startButton", sendStartMenuSignal)
|
||||
self.desktopLoaded = true
|
||||
mineos.System.out:println("desktop environment loaded")
|
||||
end
|
||||
|
@ -7,13 +7,13 @@ namespace mineos {
|
||||
|
||||
|
||||
// Callback to actually start the menu.
|
||||
function sendStartMenuSignal(_: any): void {
|
||||
print("hi")
|
||||
const system = getSystem()
|
||||
const currProg = system.currentProgram as RunProcedure
|
||||
currProg.startMenuFlag = true
|
||||
system.audioController.playSound("mouseClick", 1)
|
||||
}
|
||||
// function sendStartMenuSignal(_: any): void {
|
||||
// print("hi")
|
||||
// const system = getSystem()
|
||||
// const currProg = system.currentProgram as RunProcedure
|
||||
// currProg.startMenuFlag = true
|
||||
// system.audioController.playSound("mouseClick", 1)
|
||||
// }
|
||||
|
||||
class RunProcedure extends Program {
|
||||
|
||||
@ -53,23 +53,6 @@ namespace mineos {
|
||||
|
||||
this.renderer.setClearColor(48,48,48)
|
||||
|
||||
// Causes things to randomly overlap
|
||||
// this.renderer.addElement("startMenuBackground", new gui.Box({
|
||||
// position: create2d(0.25,5.5),
|
||||
// size: create2d(6,10),
|
||||
// color: colorScalar(65)
|
||||
// }))
|
||||
|
||||
// We have to shift the entire wallpaper to the right so it doesn't blend
|
||||
// const background = this.renderer.getElement("background") as gui.Box
|
||||
// background.position.x = 6.25
|
||||
// Then we gotta patch the space
|
||||
// this.renderer.addElement("backgroundDuctTape", new gui.Box({
|
||||
// position: create2d(0,0),
|
||||
// size: create2d(6.25,5.5),
|
||||
// color: colorRGB(1,130,129,255)
|
||||
// }))
|
||||
|
||||
// Now duct tape on the buttons that randomly won't be clickable
|
||||
let i = 0
|
||||
for (const [name,progNameNice] of Object.entries(this.menuComponents)) {
|
||||
@ -104,7 +87,7 @@ namespace mineos {
|
||||
|
||||
this.audioController.playSound("osStartup", 0.9)
|
||||
|
||||
this.system.clearCallbacks()
|
||||
// this.system.clearCallbacks()
|
||||
this.renderer.clearMemory()
|
||||
|
||||
this.renderer.setClearColor(0,0,0)
|
||||
@ -129,7 +112,7 @@ namespace mineos {
|
||||
// label: "Start"
|
||||
// }))
|
||||
|
||||
this.system.registerCallback("startButton", sendStartMenuSignal);
|
||||
// this.system.registerCallback("startButton", sendStartMenuSignal);
|
||||
|
||||
this.desktopLoaded = true
|
||||
System.out.println("desktop environment loaded")
|
||||
|
@ -5,6 +5,165 @@ local function __TS__Class(self)
|
||||
c.prototype.constructor = c
|
||||
return c
|
||||
end
|
||||
|
||||
local function __TS__StringIncludes(self, searchString, position)
|
||||
if not position then
|
||||
position = 1
|
||||
else
|
||||
position = position + 1
|
||||
end
|
||||
local index = string.find(self, searchString, position, true)
|
||||
return index ~= nil
|
||||
end
|
||||
|
||||
local function __TS__New(target, ...)
|
||||
local instance = setmetatable({}, target.prototype)
|
||||
instance:____constructor(...)
|
||||
return instance
|
||||
end
|
||||
|
||||
local function __TS__ClassExtends(target, base)
|
||||
target.____super = base
|
||||
local staticMetatable = setmetatable({__index = base}, base)
|
||||
setmetatable(target, staticMetatable)
|
||||
local baseMetatable = getmetatable(base)
|
||||
if baseMetatable then
|
||||
if type(baseMetatable.__index) == "function" then
|
||||
staticMetatable.__index = baseMetatable.__index
|
||||
end
|
||||
if type(baseMetatable.__newindex) == "function" then
|
||||
staticMetatable.__newindex = baseMetatable.__newindex
|
||||
end
|
||||
end
|
||||
setmetatable(target.prototype, base.prototype)
|
||||
if type(base.prototype.__index) == "function" then
|
||||
target.prototype.__index = base.prototype.__index
|
||||
end
|
||||
if type(base.prototype.__newindex) == "function" then
|
||||
target.prototype.__newindex = base.prototype.__newindex
|
||||
end
|
||||
if type(base.prototype.__tostring) == "function" then
|
||||
target.prototype.__tostring = base.prototype.__tostring
|
||||
end
|
||||
end
|
||||
|
||||
local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
|
||||
do
|
||||
local function getErrorStack(self, constructor)
|
||||
if debug == nil then
|
||||
return nil
|
||||
end
|
||||
local level = 1
|
||||
while true do
|
||||
local info = debug.getinfo(level, "f")
|
||||
level = level + 1
|
||||
if not info then
|
||||
level = 1
|
||||
break
|
||||
elseif info.func == constructor then
|
||||
break
|
||||
end
|
||||
end
|
||||
if __TS__StringIncludes(_VERSION, "Lua 5.0") then
|
||||
return debug.traceback(("[Level " .. tostring(level)) .. "]")
|
||||
else
|
||||
return debug.traceback(nil, level)
|
||||
end
|
||||
end
|
||||
local function wrapErrorToString(self, getDescription)
|
||||
return function(self)
|
||||
local description = getDescription(self)
|
||||
local caller = debug.getinfo(3, "f")
|
||||
local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0") or _VERSION == "Lua 5.1"
|
||||
if isClassicLua or caller and caller.func ~= error then
|
||||
return description
|
||||
else
|
||||
return (description .. "\n") .. tostring(self.stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function initErrorClass(self, Type, name)
|
||||
Type.name = name
|
||||
return setmetatable(
|
||||
Type,
|
||||
{__call = function(____, _self, message) return __TS__New(Type, message) end}
|
||||
)
|
||||
end
|
||||
local ____initErrorClass_1 = initErrorClass
|
||||
local ____class_0 = __TS__Class()
|
||||
____class_0.name = ""
|
||||
function ____class_0.prototype.____constructor(self, message)
|
||||
if message == nil then
|
||||
message = ""
|
||||
end
|
||||
self.message = message
|
||||
self.name = "Error"
|
||||
self.stack = getErrorStack(nil, self.constructor.new)
|
||||
local metatable = getmetatable(self)
|
||||
if metatable and not metatable.__errorToStringPatched then
|
||||
metatable.__errorToStringPatched = true
|
||||
metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
|
||||
end
|
||||
end
|
||||
function ____class_0.prototype.__tostring(self)
|
||||
return self.message ~= "" and (self.name .. ": ") .. self.message or self.name
|
||||
end
|
||||
Error = ____initErrorClass_1(nil, ____class_0, "Error")
|
||||
local function createErrorClass(self, name)
|
||||
local ____initErrorClass_3 = initErrorClass
|
||||
local ____class_2 = __TS__Class()
|
||||
____class_2.name = ____class_2.name
|
||||
__TS__ClassExtends(____class_2, Error)
|
||||
function ____class_2.prototype.____constructor(self, ...)
|
||||
____class_2.____super.prototype.____constructor(self, ...)
|
||||
self.name = name
|
||||
end
|
||||
return ____initErrorClass_3(nil, ____class_2, name)
|
||||
end
|
||||
RangeError = createErrorClass(nil, "RangeError")
|
||||
ReferenceError = createErrorClass(nil, "ReferenceError")
|
||||
SyntaxError = createErrorClass(nil, "SyntaxError")
|
||||
TypeError = createErrorClass(nil, "TypeError")
|
||||
URIError = createErrorClass(nil, "URIError")
|
||||
end
|
||||
|
||||
local function __TS__ObjectGetOwnPropertyDescriptors(object)
|
||||
local metatable = getmetatable(object)
|
||||
if not metatable then
|
||||
return {}
|
||||
end
|
||||
return rawget(metatable, "_descriptors") or ({})
|
||||
end
|
||||
|
||||
local function __TS__Delete(target, key)
|
||||
local descriptors = __TS__ObjectGetOwnPropertyDescriptors(target)
|
||||
local descriptor = descriptors[key]
|
||||
if descriptor then
|
||||
if not descriptor.configurable then
|
||||
error(
|
||||
__TS__New(
|
||||
TypeError,
|
||||
((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. "."
|
||||
),
|
||||
0
|
||||
)
|
||||
end
|
||||
descriptors[key] = nil
|
||||
return true
|
||||
end
|
||||
target[key] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
local function __TS__ObjectEntries(obj)
|
||||
local result = {}
|
||||
local len = 0
|
||||
for key in pairs(obj) do
|
||||
len = len + 1
|
||||
result[len] = {key, obj[key]}
|
||||
end
|
||||
return result
|
||||
end
|
||||
-- End of Lua Library inline imports
|
||||
mineos = mineos or ({})
|
||||
do
|
||||
@ -14,12 +173,31 @@ do
|
||||
Renderer.name = "Renderer"
|
||||
function Renderer.prototype.____constructor(self, system)
|
||||
self.clearColor = vector.create(0, 0, 0)
|
||||
self.memory = {}
|
||||
self.shouldDraw = true
|
||||
self.frameBufferSize = create(0, 0)
|
||||
self.frameBufferScale = 1
|
||||
self.system = system
|
||||
self.system:getDriver():hud_add({
|
||||
name = "background",
|
||||
hud_elem_type = HudElementType.image,
|
||||
position = create(0, 0)
|
||||
})
|
||||
end
|
||||
function Renderer.prototype.clearMemory(self)
|
||||
for ____, ____value in ipairs(__TS__ObjectEntries(self.memory)) do
|
||||
local name = ____value[1]
|
||||
local elementID = ____value[2]
|
||||
do
|
||||
if name == "background" then
|
||||
goto __continue5
|
||||
end
|
||||
local driver = self.system:getDriver()
|
||||
driver:hud_remove(elementID)
|
||||
__TS__Delete(self.memory, name)
|
||||
end
|
||||
::__continue5::
|
||||
end
|
||||
end
|
||||
function Renderer.prototype.removeComponent(self, name)
|
||||
end
|
||||
@ -31,5 +209,31 @@ do
|
||||
self.clearColor.z = b
|
||||
self:internalUpdateClearColor()
|
||||
end
|
||||
function Renderer.prototype.addElement(self, name, component)
|
||||
local driver = self.system:getDriver()
|
||||
self.memory[name] = driver:hud_add(component)
|
||||
end
|
||||
function Renderer.prototype.getElement(self, name)
|
||||
local driver = self.system:getDriver()
|
||||
local elementID = self.memory[name]
|
||||
if elementID == nil then
|
||||
error(
|
||||
__TS__New(Error, ("renderer: component " .. name) .. " does not exist."),
|
||||
0
|
||||
)
|
||||
end
|
||||
return driver:hud_get(elementID)
|
||||
end
|
||||
function Renderer.prototype.setElementComponentValue(self, name, component, value)
|
||||
local driver = self.system:getDriver()
|
||||
local elementID = self.memory[name]
|
||||
if elementID == nil then
|
||||
error(
|
||||
__TS__New(Error, ("renderer: component " .. name) .. " does not exist."),
|
||||
0
|
||||
)
|
||||
end
|
||||
driver:hud_change(elementID, component, value)
|
||||
end
|
||||
print("renderer loaded.")
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
namespace mineos {
|
||||
|
||||
const create = vector.create2d
|
||||
|
||||
export class Renderer {
|
||||
@ -13,13 +14,20 @@ namespace mineos {
|
||||
|
||||
constructor(system: System) {
|
||||
this.system = system
|
||||
this.system.getDriver().hud_add({
|
||||
name: "background",
|
||||
hud_elem_type: HudElementType.image,
|
||||
position: create(0,0)
|
||||
})
|
||||
}
|
||||
|
||||
clearMemory(): void {
|
||||
// for (const [name, _] of Object.entries(this.memory)) {
|
||||
// if (name == "backgroundColor") continue
|
||||
// delete this.memory[name]
|
||||
// }
|
||||
for (const [name, elementID] of Object.entries(this.memory)) {
|
||||
if (name == "background") continue
|
||||
const driver = this.system.getDriver()
|
||||
driver.hud_remove(elementID)
|
||||
delete this.memory[name]
|
||||
}
|
||||
}
|
||||
|
||||
removeComponent(name: string) {
|
||||
@ -41,12 +49,12 @@ namespace mineos {
|
||||
this.internalUpdateClearColor()
|
||||
}
|
||||
|
||||
addElement(name: string, component: GUIComponent): void {
|
||||
addElement(name: string, component: HudDefinition): void {
|
||||
const driver = this.system.getDriver()
|
||||
this.memory[name] = driver.hud_add(component)
|
||||
}
|
||||
|
||||
getElement(name: string): GUIComponent {
|
||||
getElement(name: string): HudDefinition {
|
||||
const driver = this.system.getDriver()
|
||||
const elementID = this.memory[name]
|
||||
if (elementID == null) throw new Error("renderer: component " + name + " does not exist.")
|
||||
@ -54,9 +62,10 @@ namespace mineos {
|
||||
}
|
||||
|
||||
setElementComponentValue(name: string, component: string, value: any): void {
|
||||
const driver = this.system.getDriver()
|
||||
const elementID = this.memory[name]
|
||||
if (elementID == null) throw new Error("renderer: component " + name + " does not exist.")
|
||||
|
||||
driver.hud_change(elementID, component, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,44 +126,6 @@ do
|
||||
TypeError = createErrorClass(nil, "TypeError")
|
||||
URIError = createErrorClass(nil, "URIError")
|
||||
end
|
||||
|
||||
local function __TS__ObjectEntries(obj)
|
||||
local result = {}
|
||||
local len = 0
|
||||
for key in pairs(obj) do
|
||||
len = len + 1
|
||||
result[len] = {key, obj[key]}
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function __TS__ObjectGetOwnPropertyDescriptors(object)
|
||||
local metatable = getmetatable(object)
|
||||
if not metatable then
|
||||
return {}
|
||||
end
|
||||
return rawget(metatable, "_descriptors") or ({})
|
||||
end
|
||||
|
||||
local function __TS__Delete(target, key)
|
||||
local descriptors = __TS__ObjectGetOwnPropertyDescriptors(target)
|
||||
local descriptor = descriptors[key]
|
||||
if descriptor then
|
||||
if not descriptor.configurable then
|
||||
error(
|
||||
__TS__New(
|
||||
TypeError,
|
||||
((("Cannot delete property " .. tostring(key)) .. " of ") .. tostring(target)) .. "."
|
||||
),
|
||||
0
|
||||
)
|
||||
end
|
||||
descriptors[key] = nil
|
||||
return true
|
||||
end
|
||||
target[key] = nil
|
||||
return true
|
||||
end
|
||||
-- End of Lua Library inline imports
|
||||
mineos = mineos or ({})
|
||||
do
|
||||
@ -192,16 +154,15 @@ do
|
||||
mineos.System = __TS__Class()
|
||||
local System = mineos.System
|
||||
System.name = "System"
|
||||
function System.prototype.____constructor(self)
|
||||
self.renderer = __TS__New(mineos.Renderer, self)
|
||||
function System.prototype.____constructor(self, driver)
|
||||
self.audioController = __TS__New(mineos.AudioController, self)
|
||||
self.driver = nil
|
||||
self.skipToDesktopHackjob = true
|
||||
self.booting = true
|
||||
self.bootProcess = 0
|
||||
self.running = false
|
||||
self.quitReceived = false
|
||||
self.programs = {}
|
||||
self.callbacks = {}
|
||||
self.currentProgram = nil
|
||||
self.currentProgramName = ""
|
||||
self.mousePos = vector.create2d(0, 0)
|
||||
@ -212,31 +173,31 @@ do
|
||||
)
|
||||
end
|
||||
currentSystem = self
|
||||
self.driver = driver
|
||||
self.renderer = __TS__New(mineos.Renderer, self)
|
||||
self:receivePrograms()
|
||||
end
|
||||
function System.prototype.getRenderer(self)
|
||||
return self.renderer
|
||||
end
|
||||
function System.prototype.setDriver(self, driver)
|
||||
self.driver = driver
|
||||
end
|
||||
function System.prototype.getDriver(self)
|
||||
if self.driver == nil then
|
||||
error(
|
||||
__TS__New(Error, "Attempted to get driver before available."),
|
||||
0
|
||||
)
|
||||
end
|
||||
return self.driver
|
||||
end
|
||||
function System.prototype.getAudioController(self)
|
||||
return self.audioController
|
||||
end
|
||||
function System.prototype.isKeyDown(self, keyName)
|
||||
return mineos.osKeyboardPoll(keyName)
|
||||
end
|
||||
function System.prototype.registerCallback(self, name, callback)
|
||||
self.callbacks[name] = callback
|
||||
end
|
||||
function System.prototype.triggerCallbacks(self, fields)
|
||||
for ____, ____value in ipairs(__TS__ObjectEntries(fields)) do
|
||||
local name = ____value[1]
|
||||
local thing = ____value[2]
|
||||
local pulledCallback = self.callbacks[name]
|
||||
if pulledCallback == nil then
|
||||
return
|
||||
end
|
||||
pulledCallback(thing)
|
||||
end
|
||||
end
|
||||
function System.prototype.receivePrograms(self)
|
||||
while #registrationQueue > 0 do
|
||||
local name, prog = unpack(table.remove(registrationQueue))
|
||||
@ -266,13 +227,6 @@ do
|
||||
mineos.System.out:println("power button pushed.")
|
||||
mineos.System.out:println("starting computer.")
|
||||
end
|
||||
function System.prototype.clearCallbacks(self)
|
||||
for ____, ____value in ipairs(__TS__ObjectEntries(self.callbacks)) do
|
||||
local name = ____value[1]
|
||||
local _ = ____value[2]
|
||||
__TS__Delete(self.callbacks, name)
|
||||
end
|
||||
end
|
||||
function System.prototype.doBoot(self, delta)
|
||||
if self.bootProcess == 0 then
|
||||
if self.currentProgramName ~= "BiosProcedure" then
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace mineos {
|
||||
|
||||
export type Driver = ObjectRef;
|
||||
|
||||
let currentSystem: System | null = null;
|
||||
let registrationQueue: [string, typeof Program][] = []
|
||||
|
||||
@ -21,7 +23,7 @@ namespace mineos {
|
||||
|
||||
export class System {
|
||||
|
||||
renderer = new Renderer(this);
|
||||
renderer: Renderer;
|
||||
audioController = new AudioController(this)
|
||||
driver: Driver | null = null
|
||||
|
||||
@ -38,17 +40,19 @@ namespace mineos {
|
||||
|
||||
programs: {[id: string] : typeof Program} = {}
|
||||
|
||||
callbacks: {[id: string]: (fields: any) => void} = {}
|
||||
// callbacks: {[id: string]: (fields: any) => void} = {}
|
||||
|
||||
currentProgram: Program | null = null
|
||||
currentProgramName = ""
|
||||
mousePos = vector.create2d(0,0)
|
||||
|
||||
constructor() {
|
||||
constructor(driver: Driver) {
|
||||
if (currentSystem != null) {
|
||||
throw new Error("Cannot create more than one instance of mineos.");
|
||||
}
|
||||
currentSystem = this
|
||||
this.driver = driver
|
||||
this.renderer = new Renderer(this)
|
||||
this.receivePrograms()
|
||||
}
|
||||
|
||||
@ -73,17 +77,17 @@ namespace mineos {
|
||||
return osKeyboardPoll(keyName)
|
||||
}
|
||||
|
||||
registerCallback(name: string, callback: (fields: any) => void): void {
|
||||
this.callbacks[name] = callback
|
||||
}
|
||||
// registerCallback(name: string, callback: (fields: any) => void): void {
|
||||
// this.callbacks[name] = callback
|
||||
// }
|
||||
|
||||
triggerCallbacks(fields: {[id: string] : any}): void {
|
||||
for (const [name, thing] of Object.entries(fields)) {
|
||||
const pulledCallback = this.callbacks[name]
|
||||
if (pulledCallback == null) return
|
||||
pulledCallback(thing);
|
||||
}
|
||||
}
|
||||
// triggerCallbacks(fields: {[id: string] : any}): void {
|
||||
// for (const [name, thing] of Object.entries(fields)) {
|
||||
// const pulledCallback = this.callbacks[name]
|
||||
// if (pulledCallback == null) return
|
||||
// pulledCallback(thing);
|
||||
// }
|
||||
// }
|
||||
|
||||
receivePrograms() {
|
||||
while (registrationQueue.length > 0) {
|
||||
@ -122,11 +126,11 @@ namespace mineos {
|
||||
System.out.println("starting computer.")
|
||||
}
|
||||
|
||||
clearCallbacks() {
|
||||
for (const [name,_] of Object.entries(this.callbacks)) {
|
||||
delete this.callbacks[name]
|
||||
}
|
||||
}
|
||||
// clearCallbacks() {
|
||||
// for (const [name,_] of Object.entries(this.callbacks)) {
|
||||
// delete this.callbacks[name]
|
||||
// }
|
||||
// }
|
||||
|
||||
doBoot(delta: number): void {
|
||||
if (this.bootProcess == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user