Initial commit

This commit is contained in:
Eagle517
2019-01-15 12:39:35 -06:00
commit 9ae8714055
153 changed files with 29967 additions and 0 deletions

View File

@ -0,0 +1,114 @@
keyboard_strToBool = keyboard_strToBool or {
["0"] = false,
["1"] = true,
}
--Key codes may use only 7 bits, so values must be in range 00-7F
keyboard_keyToCode = keyboard_keyToCode or {
["backspace"] = 0x01,
["tab"] = 0x02,
["return"] = 0x03,
["space"] = 0x04,
["end"] = 0x05,
["home"] = 0x06,
["left"] = 0x07,
["up"] = 0x08,
["right"] = 0x09,
["down"] = 0x0A,
["insert"] = 0x0B,
["delete"] = 0x0C,
["0"] = 0x10,
["1"] = 0x11,
["2"] = 0x12,
["3"] = 0x13,
["4"] = 0x14,
["5"] = 0x15,
["6"] = 0x16,
["7"] = 0x17,
["8"] = 0x18,
["9"] = 0x19,
["a"] = 0x1A,
["b"] = 0x1B,
["c"] = 0x1C,
["d"] = 0x1D,
["e"] = 0x1E,
["f"] = 0x1F,
["g"] = 0x20,
["h"] = 0x21,
["i"] = 0x22,
["j"] = 0x23,
["k"] = 0x24,
["l"] = 0x25,
["m"] = 0x26,
["n"] = 0x27,
["o"] = 0x28,
["p"] = 0x29,
["q"] = 0x2A,
["r"] = 0x2B,
["s"] = 0x2C,
["t"] = 0x2D,
["u"] = 0x2E,
["v"] = 0x2F,
["w"] = 0x30,
["x"] = 0x31,
["y"] = 0x32,
["z"] = 0x33,
["numpad0"] = 0x40,
["numpad1"] = 0x41,
["numpad2"] = 0x42,
["numpad3"] = 0x43,
["numpad4"] = 0x44,
["numpad5"] = 0x45,
["numpad6"] = 0x46,
["numpad7"] = 0x47,
["numpad8"] = 0x48,
["numpad9"] = 0x49,
["*"] = 0x4A,
["+"] = 0x4B,
["numpadenter"] = 0x4C,
["minus"] = 0x4D,
["numpaddecimal"] = 0x4E,
["/"] = 0x4F,
["f1"] = 0x51,
["f2"] = 0x52,
["f3"] = 0x53,
["f4"] = 0x54,
["f5"] = 0x55,
["f6"] = 0x56,
["f7"] = 0x57,
["f8"] = 0x58,
["f9"] = 0x59,
["f10"] = 0x5A,
["f11"] = 0x5B,
["f12"] = 0x5C,
["lshift"] = 0x60,
["rshift"] = 0x61,
["lcontrol"] = 0x62,
["rcontrol"] = 0x63,
["lalt"] = 0x64,
["ralt"] = 0x65,
[";"] = 0x70,
[","] = 0x71,
["."] = 0x72,
["/"] = 0x73,
["`"] = 0x74,
["["] = 0x75,
["\\"] = 0x76,
["]"] = 0x77,
[" ="] = 0x78,
["apostrophe"] = 0x79,
["invalid"] = 0x7F,
}
return function(gate)
gate.queueBits = {}
end

View File

@ -0,0 +1,24 @@
return function(gate, argv)
if argv[1]=="\\:" then argv[1] = ";" end
local keycode = keyboard_keyToCode[argv[1]] or keyboard_keyToCode["invalid"]
local status = keyboard_strToBool[argv[2]]
local code = keycode+(status and 128 or 0)
local function queueBit(bit)
table.insert(gate.queueBits, 1, bit)
end
queueBit(true)
for bitidx = 1, 8 do
local val = bit.band(code, 0x80)~=0
queueBit(val)
code = bit.lshift(code, 1)
end
queueBit(false)
gate:queue(0)
end

View File

@ -0,0 +1,10 @@
return function(gate)
if #gate.queueBits~=0 then
local bit = table.remove(gate.queueBits, #gate.queueBits)
gate.ports[1]:setstate(bit)
gate:queue(1)
else
gate.ports[1]:setstate(false)
end
end

49
bricks/inputs/keyboard.cs Normal file
View File

@ -0,0 +1,49 @@
datablock fxDTSBrickData(LogicGate_Keyboard_Data){
brickFile = $LuaLogic::Path @ "bricks/blb/keyboardgate.blb";
category = "Logic Bricks";
subCategory = "Inputs";
uiName = "Input Keyboard";
iconName = $LuaLogic::Path @ "icons/Input Keyboard";
orientationFix = 3;
isLogic = true;
isLogicGate = true;
isLogicInput = true;
logicUIName = "Input Keyboard";
logicUIDesc = "";
logicInit = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/keyboard-init.lua" );
logicInput = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/keyboard-input.lua" );
logicUpdate = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/keyboard-update.lua");
numLogicPorts = 1;
logicPortType[0] = 0;
logicPortPos[0] = "2 0 0";
logicPortDir[0] = 1;
logicPortUIName[0] = "R";
};
lualogic_registergatedefinition("LogicGate_Keyboard_Data");
function LogicGate_Keyboard_Data::LuaLogic_PressKey(%data, %brick, %key, %state){
%key = strReplace(%key, ";", "\\:");
lualogic_sendInput(%brick, 2, %key, %state);
}
function serverCmdLInputKey(%client, %key, %state){
%brick = %client.Logic_InputKeyboard;
if(isObject(%brick) && %client.Logic_InputActive){
%brick.getDatablock().LuaLogic_PressKey(%brick, %key, %state);
}
}
function LogicGate_Keyboard_Data::Logic_OnInput(%data, %brick, %pos, %norm, %client){
if(isObject(%client)){
%client.Logic_InputKeyboard = %brick;
%client.Logic_InputActive = true;
commandToClient(%client, 'LStartInput');
}
}

View File

@ -0,0 +1,11 @@
return function(gate, argv)
if #argv == 1 then
gate.ports[1]:setstate(toboolean(argv[1]))
gate.ports[2]:setstate(toboolean(argv[1]))
else
gate.ports[1]:setstate(not gate.ports[1].state)
gate.ports[2]:setstate(not gate.ports[2].state)
end
gate:cb("1\t" .. bool_to_int[gate.ports[1].state])
end

44
bricks/inputs/switch.cs Normal file
View File

@ -0,0 +1,44 @@
datablock fxDTSBrickData(LogicGate_Switch_Data)
{
category = "Logic Bricks";
subCategory = "Inputs";
uiName = "Switch";
iconName = $LuaLogic::Path @ "icons/Switch";
brickFile = $LuaLogic::Path @ "bricks/blb/switch.blb";
hasPrint = 1;
printAspectRatio = "Logic";
orientationFix = 3;
isLogic = 1;
isLogicGate = 1;
isLogicInput = 1;
logicInput = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/switch-input.lua");
numLogicPorts = 2;
logicPortType[0] = 0;
logicPortPos[0] = "0 1 0";
logicPortDir[0] = "1";
logicPortType[1] = 0;
logicPortPos[1] = "0 -1 0";
logicPortDir[1] = "3";
};
lualogic_registergatedefinition("LogicGate_Switch_Data");
function LogicGate_Switch_Data::Logic_onInput(%this, %obj, %pos, %norm)
{
lualogic_sendinput(%obj, 0);
}
function LogicGate_Switch_Data::Logic_onAdd(%this, %obj)
{
lualogic_sendinput(%obj, 1, %obj.getColorFXID() == 3);
}
function LogicGate_Switch_Data::LuaLogic_Callback(%this, %obj, %data)
{
%obj.setColorFX(getField(%data, 0) == 1 ? 3 : 0);
}