initial commit
This commit is contained in:
		
							
								
								
									
										31
									
								
								scripts/brickdata.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								scripts/brickdata.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
|  | ||||
| deleteVariables("$LuaLogic::BrickData::LoadedFile_*"); | ||||
|  | ||||
| function lualogic_cleanfilename(%fn){ | ||||
| 	%fn = strReplace(%fn, "\\", "/"); | ||||
| 	%fn = strReplace(%fn, "/", "_"); | ||||
| 	%fn = strReplace(%fn, ".", "_"); | ||||
| 	%fn = strReplace(%fn, "-", "_"); | ||||
| 	return %fn; | ||||
| } | ||||
|  | ||||
| function lualogic_require(%fn){ | ||||
| 	if(!$LuaLogic::BrickData::LoadedFile_[lualogic_cleanfilename(%fn)]){ | ||||
| 		exec(%fn); | ||||
| 		$LuaLogic::BrickData::LoadedFile_[lualogic_cleanfilename(%fn)] = 1; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function lualogic_execallbricks(){ | ||||
| 	%patt = $LuaLogic::Path @ "bricks/*.cs"; | ||||
| 	%fn = findFirstFile(%patt); | ||||
| 	while(%fn!$=""){ | ||||
| 		lualogic_require(%fn); | ||||
| 		 | ||||
| 		%fn = findNextFile(%patt); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| lualogic_execallbricks(); | ||||
|  | ||||
| deleteVariables("$LuaLogic::BrickData::LoadedFile_*"); | ||||
							
								
								
									
										239
									
								
								scripts/bricks.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										239
									
								
								scripts/bricks.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,239 @@ | ||||
| function lualogic_addwire(%wire) | ||||
| { | ||||
| 	%color = %wire.getColorID(); | ||||
|  | ||||
| 	%box = %wire.getWorldBox(); | ||||
|  | ||||
| 	%minX = mFloatLength(getWord(%box, 0)*2, 0)/2; | ||||
| 	%minY = mFloatLength(getWord(%box, 1)*2, 0)/2; | ||||
| 	%minZ = mFloatLength(getWord(%box, 2)*5, 0)/5; | ||||
|  | ||||
| 	%maxX = mFloatLength(getWord(%box, 3)*2, 0)/2; | ||||
| 	%maxY = mFloatLength(getWord(%box, 4)*2, 0)/2; | ||||
| 	%maxZ = mFloatLength(getWord(%box, 5)*5, 0)/5; | ||||
|  | ||||
| 	%min = lualogic_pos(%minX SPC %minY SPC %minZ); | ||||
| 	%max = lualogic_pos(%maxX SPC %maxY SPC %maxZ); | ||||
|  | ||||
| 	lualogic_send("W;" @ %wire.getID() @ ";" @ %color @ ";" @ %min @ ";" @ %max); | ||||
| 	%wire.logicIsAdded = true; | ||||
| } | ||||
|  | ||||
| function lualogic_addgate(%gate) | ||||
| { | ||||
| 	%db = %gate.getDataBlock(); | ||||
| 	%pos = lualogic_pos(%gate.getPosition()); | ||||
| 	%rot = %gate.angleId; | ||||
|  | ||||
| 	%data = "G;" @ %gate.getID() @ ";" @ %db @ ";" @ %pos @ ";" @ %rot; | ||||
|  | ||||
| 	lualogic_send(%data); | ||||
| 	%gate.logicIsAdded = true; | ||||
|  | ||||
| 	if(isFunction(%db.getName(), "Logic_onAdd")) | ||||
| 		%db.Logic_onAdd(%gate); | ||||
| } | ||||
|  | ||||
| function lualogic_removewire(%wire) | ||||
| { | ||||
| 	if(%wire.logicIsRemoved == false) | ||||
| 	{ | ||||
| 		lualogic_send("RW;" @ %wire); | ||||
| 		%wire.logicIsRemoved = true; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function lualogic_removegate(%gate) | ||||
| { | ||||
| 	if(%gate.logicIsRemoved == false) | ||||
| 	{ | ||||
| 		%db = %gate.getDataBlock(); | ||||
| 		//if(isFunction(%db.getName(), "Logic_onRemove")) | ||||
| 		//	%db.Logic_onRemove(%gate); | ||||
|  | ||||
| 		lualogic_send("RG;" @ %gate); | ||||
| 		%gate.logicIsRemoved = true; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function lualogic_sendall() | ||||
| { | ||||
| 	%groups = mainBrickGroup.getCount(); | ||||
| 	for(%i = 0; %i < %groups; %i++) | ||||
| 	{ | ||||
| 		%group = mainBrickGroup.getObject(%i); | ||||
| 		%bricks = %group.getCount(); | ||||
| 		for(%a = 0; %a < %bricks; %a++) | ||||
| 		{ | ||||
| 			%brick = %group.getObject(%a); | ||||
| 			%data = %brick.getDataBlock(); | ||||
| 			if(%data.isLogic && %brick.isPlanted() && !%brick.logicIsRemoved) | ||||
| 			{ | ||||
| 				if(%data.isLogicWire) | ||||
| 					lualogic_addwire(%brick); | ||||
| 				else if(%data.isLogicGate) | ||||
| 					lualogic_addgate(%brick); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function fxDTSBrick::Logic_SetOutput(%this, %port, %state) | ||||
| { | ||||
| 	lualogic_send("SP;" @ %this @ ";" @ %port+1 @ ";" @ %state); | ||||
| } | ||||
|  | ||||
| function fxDtsBrick::Logic_HandlePlant(%brick){ | ||||
| 	if(!%brick.Logic_HasPlanted){ | ||||
| 		%brick.Logic_HasPlanted = true; | ||||
| 		 | ||||
| 		%data = %brick.getDatablock(); | ||||
| 		if(isFunction(%data.getName(), "Logic_onPlant")){ | ||||
| 			%data.Logic_onPlant(%brick); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function fxDtsBrick::Logic_HandleRemove(%brick){ | ||||
| 	if(!%brick.Logic_HasRemoved){ | ||||
| 		%brick.Logic_HasRemoved = true; | ||||
| 		 | ||||
| 		%data = %brick.getDatablock(); | ||||
| 		if(isFunction(%data.getName(), "Logic_onRemove")){ | ||||
| 			%data.Logic_onRemove(%brick); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| package LuaLogic_Bricks | ||||
| { | ||||
| 	function fxDTSBrickData::onPlant(%data, %brick) | ||||
| 	{ | ||||
| 		parent::onPlant(%data, %brick); | ||||
|  | ||||
| 		if(isObject(%brick) && %data.isLogic) | ||||
| 		{ | ||||
| 			if(%data.isLogicWire) | ||||
| 				lualogic_addwire(%brick); | ||||
| 			else if(%data.isLogicGate) | ||||
| 				lualogic_addgate(%brick); | ||||
| 			 | ||||
| 			%brick.Logic_HandlePlant(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	function fxDTSBrickData::onLoadPlant(%this, %brick) | ||||
| 	{ | ||||
| 		parent::onLoadPlant(%this, %brick); | ||||
|  | ||||
| 		if(isObject(%brick) && %this.isLogic) | ||||
| 		{ | ||||
| 			if(%this.isLogicWire) | ||||
| 				lualogic_addwire(%brick); | ||||
| 			else if(%this.isLogicGate) | ||||
| 				lualogic_addgate(%brick); | ||||
| 			 | ||||
| 			%brick.Logic_HandlePlant(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	function fxDTSBrickData::onColorChange(%data, %obj) | ||||
| 	{ | ||||
| 		parent::onColorChange(%data, %obj); | ||||
|  | ||||
| 		if(isObject(%obj) && %obj.isPlanted() && !%obj.isDead() && %data.isLogic && %data.isLogicWire) | ||||
| 			lualogic_send("SL;" @ %obj @ ";" @ %obj.getColorID()); | ||||
| 	} | ||||
|  | ||||
| 	function fxDTSBrickData::onDeath(%this, %brick) | ||||
| 	{ | ||||
| 		if(%this.isLogic) | ||||
| 		{ | ||||
| 			%brick.Logic_HandleRemove(); | ||||
| 			 | ||||
| 			if(%this.isLogicWire) | ||||
| 				lualogic_removewire(%brick); | ||||
| 			else if(%this.isLogicGate) | ||||
| 				lualogic_removegate(%brick); | ||||
| 		} | ||||
| 		 | ||||
| 		parent::onDeath(%this, %brick); | ||||
| 	} | ||||
|  | ||||
| 	function fxDTSBrickData::onRemove(%this, %brick) | ||||
| 	{ | ||||
| 		if(%this.isLogic && %brick.logicIsAdded) | ||||
| 		{ | ||||
| 			%brick.Logic_HandleRemove(); | ||||
| 			 | ||||
| 			if(%this.isLogicWire) | ||||
| 				lualogic_removewire(%brick); | ||||
| 			else if(%this.isLogicGate) | ||||
| 				lualogic_removegate(%brick); | ||||
| 		} | ||||
| 		 | ||||
| 		parent::onRemove(%this, %brick); | ||||
| 	} | ||||
| 	 | ||||
| 	function fxDtsBrick::setColor(%brick, %color){ | ||||
| 		%data = %brick.getDatablock(); | ||||
| 		if(%data.logicForceColor!$=""){ | ||||
| 			%color = lualogic_getcolor(%data.logicForceColor); | ||||
| 		} | ||||
| 		 | ||||
| 		parent::setColor(%brick, %color); | ||||
| 	} | ||||
| 	 | ||||
| 	function fxDtsBrick::setPrint(%brick, %print){ | ||||
| 		%data = %brick.getDatablock(); | ||||
| 		if(%data.logicForcePrint!$=""){ | ||||
| 			%print = lualogic_getprint(%data.logicForcePrint); | ||||
| 		} | ||||
| 		 | ||||
| 		parent::setPrint(%brick, %print); | ||||
| 	} | ||||
| 	 | ||||
| 	function fxDtsBrickData::onUse(%data, %player, %slot){ | ||||
| 		parent::onUse(%data, %player, %slot); | ||||
| 		 | ||||
| 		if(isObject(%player.tempBrick)){ | ||||
| 			%brick = %player.tempBrick; | ||||
| 			 | ||||
| 			if(%data.logicForceColor!$=""){ | ||||
| 				%brick.setColor(); | ||||
| 			}else{ | ||||
| 				%brick.setColor(%player.client.currentColor); | ||||
| 			} | ||||
| 			if(%data.logicForcePrint!$=""){ | ||||
| 				%brick.setPrint(); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	function Player::activateStuff(%this, %a, %b) | ||||
| 	{ | ||||
| 		parent::activateStuff(%this, %a, %b); | ||||
| 		 | ||||
| 		if(isObject(%client = %this.client)) | ||||
| 		{ | ||||
| 			%eye = %this.getEyePoint(); | ||||
| 			%vec = %this.getEyeVector(); | ||||
| 			%ray = containerRayCast(%eye, vectorAdd(%eye, vectorScale(%vec, 5*getWord(%this.getScale(), 2))), $TypeMasks::FxBrickObjectType); | ||||
| 			if(isObject(%hit = firstWord(%ray))) | ||||
| 			{ | ||||
| 				%data = %hit.getDataBlock(); | ||||
| 				if(%data.isLogic) | ||||
| 				{ | ||||
| 					if(%data.isLogicInput){ | ||||
| 						%data.Logic_onInput(%hit, %hitPos, %hitNorm, %client); | ||||
| 					}else{ | ||||
| 						if(%data.isLogicWire || %data.logicUIName!$=""){ | ||||
| 							lualogic_send("GINFO;" @ %client @ ";" @ %hit); | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
| activatePackage("LuaLogic_Bricks"); | ||||
							
								
								
									
										91
									
								
								scripts/cmds.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								scripts/cmds.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | ||||
| function serverCmdLT(%client) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 	{ | ||||
| 		$Pref::Server::LuaLogic::OPT_TICK_ENABLED = !$Pref::Server::LuaLogic::OPT_TICK_ENABLED; | ||||
| 		messageAll('', '\c3%1\c6 has %2 the logic tick.', %client.name, $Pref::Server::LuaLogic::OPT_TICK_ENABLED ? "enabled":"disabled"); | ||||
| 		lualogic_sendoptions(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function serverCmdLST(%client, %time) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 	{ | ||||
| 		%time = mClampFloat(%time, 1, 10000); | ||||
| 		$Pref::Server::LuaLogic::OPT_TICK_TIME = %time/1000; | ||||
| 		messageAll('', '\c3%1\c6 has set the logic tick time to \c3%2\c6 millisecond%3.', %client.name, %time, %time == 1 ? "":"s"); | ||||
| 		lualogic_sendoptions(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function serverCmdLSM(%client, %mult){ | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin){ | ||||
| 		%mult = mFloor(mClamp(%mult, 1, 1000)); | ||||
| 		$Pref::Server::LuaLogic::OPT_TICK_MULT = %mult; | ||||
| 		messageAll('', '\c3%1\c6 has set the logic tick multiplier to \c3%2\c6.', %client.name, %mult); | ||||
| 		lualogic_sendoptions(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function serverCmdLS(%client) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 	{ | ||||
| 		commandToAll('bottomprint', "\c3" @ %client.name @ "\c6 has forced a logic tick.", 3, 1); | ||||
| 		lualogic_send("TICK"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function serverCmdLFX(%client) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 	{ | ||||
| 		$Pref::Server::LuaLogic::OPT_FX_UPDATES = !$Pref::Server::LuaLogic::OPT_FX_UPDATES; | ||||
| 		messageAll('', '\c3%1\c6 has %2 logic FX updates.', %client.name, $Pref::Server::LuaLogic::OPT_FX_UPDATES ? "enabled":"disabled"); | ||||
| 		lualogic_sendoptions(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function serverCmdLFXT(%client, %time) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 	{ | ||||
| 		%time = mClamp(%time, 0, 999999); | ||||
| 		$Pref::Server::LuaLogic::OPT_FX_TIME = %time/1000; | ||||
| 		messageAll('', '\c3%1\c6 has set the logic FX time to \c3%2\c6 millisecond%3.', %client.name, %time, %time == 1 ? "":"s"); | ||||
| 		lualogic_sendoptions(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function serverCmdLTR(%client) | ||||
| { | ||||
| 	%client.logicLTR = !%client.logicLTR; | ||||
| 	if(%client.logicLTR == false) | ||||
| 		commandToClient(%client, 'bottomPrint', "", 0, 1); | ||||
| } | ||||
|  | ||||
| function serverCmdLI(%client) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 		lualogic_send("SINFO;" @ %client); | ||||
| } | ||||
|  | ||||
| function serverCmdLG(%client, %n) | ||||
| { | ||||
| 	if(%client.isAdmin || %client.isSuperAdmin) | ||||
| 	{ | ||||
| 		if(isObject(%player = %client.player)) | ||||
| 		{ | ||||
| 			%eye = %player.getEyePoint(); | ||||
| 			%vec = %player.getEyeVector(); | ||||
| 			%ray = containerRayCast(%eye, vectorAdd(%eye, vectorScale(%vec, 5*getWord(%player.getScale(), 2))), $TypeMasks::FxBrickObjectType); | ||||
| 			if(isObject(%hit = firstWord(%ray))) | ||||
| 			{ | ||||
| 				%data = %hit.getDataBlock(); | ||||
| 				if(%data.isLogicGate) | ||||
| 					lualogic_send("TEST;" @ %hit @ ";" @ %n); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										163
									
								
								scripts/lualogic.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								scripts/lualogic.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,163 @@ | ||||
|  | ||||
| if($Pref::Server::LuaLogic::OPT_TICK_ENABLED $= "") $Pref::Server::LuaLogic::OPT_TICK_ENABLED = true; | ||||
| if($Pref::Server::LuaLogic::OPT_TICK_TIME    $= "") $Pref::Server::LuaLogic::OPT_TICK_TIME    = 0; | ||||
| if($Pref::Server::LuaLogic::OPT_FX_UPDATES   $= "") $Pref::Server::LuaLogic::OPT_FX_UPDATES   = true; | ||||
| if($Pref::Server::LuaLogic::OPT_FX_TIME      $= "") $Pref::Server::LuaLogic::OPT_FX_TIME      = 0.03; | ||||
|  | ||||
| exec("./utilities.cs"); | ||||
| exec("./tcp.cs"); | ||||
| exec("./bricks.cs"); | ||||
| exec("./brickdata.cs"); | ||||
| exec("./cmds.cs"); | ||||
|  | ||||
| function lualogic_loadprintsandcolors() | ||||
| { | ||||
| 	lualogic_definecolor("RED"   , "1 0 0 1"); | ||||
| 	lualogic_definecolor("GREEN" , "0 1 0 1"); | ||||
| 	lualogic_definecolor("YELLOW", "1 1 0 1"); | ||||
| 	 | ||||
| 	lualogic_defineprint("ARROW"    , "Add-Ons/Print_Logic_Default/prints/arrow.png"); | ||||
| 	lualogic_defineprint("UPARROW"  , "Add-Ons/Print_Logic_Default/prints/uparrow.png"); | ||||
| 	lualogic_defineprint("DOWNARROW", "Add-Ons/Print_Logic_Default/prints/downarrow.png"); | ||||
| 	lualogic_defineprint("ANDGATE"  , "Add-Ons/Print_Logic_Default/prints/AND.png"); | ||||
| 	 | ||||
| 	for(%i = 0; %i < 8; %i++) | ||||
| 	{ | ||||
| 		%a = (%i >> 2) & 1; | ||||
| 		%b = (%i >> 1) & 1; | ||||
| 		%c = (%i >> 0) & 1; | ||||
| 		lualogic_defineprint("COLOR" @ %a @ %b @ %c, "Add-Ons/Print_Logic_Default/prints/color_" @ %a @ %b @ %c @ ".png"); | ||||
| 	} | ||||
| 	 | ||||
| 	lualogic_defineprint("space"             , "Add-Ons/Print_Letters_Default/prints/-space.png"           ); | ||||
| 	 | ||||
| 	lualogic_defineprint("A"                 , "Add-Ons/Print_Letters_Default/prints/A.png"                ); | ||||
| 	lualogic_defineprint("B"                 , "Add-Ons/Print_Letters_Default/prints/B.png"                ); | ||||
| 	lualogic_defineprint("C"                 , "Add-Ons/Print_Letters_Default/prints/C.png"                ); | ||||
| 	lualogic_defineprint("D"                 , "Add-Ons/Print_Letters_Default/prints/D.png"                ); | ||||
| 	lualogic_defineprint("E"                 , "Add-Ons/Print_Letters_Default/prints/E.png"                ); | ||||
| 	lualogic_defineprint("F"                 , "Add-Ons/Print_Letters_Default/prints/F.png"                ); | ||||
| 	lualogic_defineprint("G"                 , "Add-Ons/Print_Letters_Default/prints/G.png"                ); | ||||
| 	lualogic_defineprint("H"                 , "Add-Ons/Print_Letters_Default/prints/H.png"                ); | ||||
| 	lualogic_defineprint("I"                 , "Add-Ons/Print_Letters_Default/prints/I.png"                ); | ||||
| 	lualogic_defineprint("J"                 , "Add-Ons/Print_Letters_Default/prints/J.png"                ); | ||||
| 	lualogic_defineprint("K"                 , "Add-Ons/Print_Letters_Default/prints/K.png"                ); | ||||
| 	lualogic_defineprint("L"                 , "Add-Ons/Print_Letters_Default/prints/L.png"                ); | ||||
| 	lualogic_defineprint("M"                 , "Add-Ons/Print_Letters_Default/prints/M.png"                ); | ||||
| 	lualogic_defineprint("N"                 , "Add-Ons/Print_Letters_Default/prints/N.png"                ); | ||||
| 	lualogic_defineprint("O"                 , "Add-Ons/Print_Letters_Default/prints/O.png"                ); | ||||
| 	lualogic_defineprint("P"                 , "Add-Ons/Print_Letters_Default/prints/P.png"                ); | ||||
| 	lualogic_defineprint("Q"                 , "Add-Ons/Print_Letters_Default/prints/Q.png"                ); | ||||
| 	lualogic_defineprint("R"                 , "Add-Ons/Print_Letters_Default/prints/R.png"                ); | ||||
| 	lualogic_defineprint("S"                 , "Add-Ons/Print_Letters_Default/prints/S.png"                ); | ||||
| 	lualogic_defineprint("T"                 , "Add-Ons/Print_Letters_Default/prints/T.png"                ); | ||||
| 	lualogic_defineprint("U"                 , "Add-Ons/Print_Letters_Default/prints/U.png"                ); | ||||
| 	lualogic_defineprint("V"                 , "Add-Ons/Print_Letters_Default/prints/V.png"                ); | ||||
| 	lualogic_defineprint("W"                 , "Add-Ons/Print_Letters_Default/prints/W.png"                ); | ||||
| 	lualogic_defineprint("X"                 , "Add-Ons/Print_Letters_Default/prints/X.png"                ); | ||||
| 	lualogic_defineprint("Y"                 , "Add-Ons/Print_Letters_Default/prints/Y.png"                ); | ||||
| 	lualogic_defineprint("Z"                 , "Add-Ons/Print_Letters_Default/prints/Z.png"                ); | ||||
| 	 | ||||
| 	lualogic_defineprint("Alcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Alcase.png"         ); | ||||
| 	lualogic_defineprint("Blcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Blcase.png"         ); | ||||
| 	lualogic_defineprint("Clcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Clcase.png"         ); | ||||
| 	lualogic_defineprint("Dlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Dlcase.png"         ); | ||||
| 	lualogic_defineprint("Elcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Elcase.png"         ); | ||||
| 	lualogic_defineprint("Flcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Flcase.png"         ); | ||||
| 	lualogic_defineprint("Glcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Glcase.png"         ); | ||||
| 	lualogic_defineprint("Hlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Hlcase.png"         ); | ||||
| 	lualogic_defineprint("Ilcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Ilcase.png"         ); | ||||
| 	lualogic_defineprint("Jlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Jlcase.png"         ); | ||||
| 	lualogic_defineprint("Klcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Klcase.png"         ); | ||||
| 	lualogic_defineprint("Llcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Llcase.png"         ); | ||||
| 	lualogic_defineprint("Mlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Mlcase.png"         ); | ||||
| 	lualogic_defineprint("Nlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Nlcase.png"         ); | ||||
| 	lualogic_defineprint("Olcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Olcase.png"         ); | ||||
| 	lualogic_defineprint("Plcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Plcase.png"         ); | ||||
| 	lualogic_defineprint("Qlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Qlcase.png"         ); | ||||
| 	lualogic_defineprint("Rlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Rlcase.png"         ); | ||||
| 	lualogic_defineprint("Slcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Slcase.png"         ); | ||||
| 	lualogic_defineprint("Tlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Tlcase.png"         ); | ||||
| 	lualogic_defineprint("Ulcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Ulcase.png"         ); | ||||
| 	lualogic_defineprint("Vlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Vlcase.png"         ); | ||||
| 	lualogic_defineprint("Wlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Wlcase.png"         ); | ||||
| 	lualogic_defineprint("Xlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Xlcase.png"         ); | ||||
| 	lualogic_defineprint("Ylcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Ylcase.png"         ); | ||||
| 	lualogic_defineprint("Zlcase"            , "Add-Ons/Print_Letters_Lowercase/prints/Zlcase.png"         ); | ||||
| 	 | ||||
| 	lualogic_defineprint("0"                 , "Add-Ons/Print_Letters_Default/prints/0.png"                ); | ||||
| 	lualogic_defineprint("1"                 , "Add-Ons/Print_Letters_Default/prints/1.png"                ); | ||||
| 	lualogic_defineprint("2"                 , "Add-Ons/Print_Letters_Default/prints/2.png"                ); | ||||
| 	lualogic_defineprint("3"                 , "Add-Ons/Print_Letters_Default/prints/3.png"                ); | ||||
| 	lualogic_defineprint("4"                 , "Add-Ons/Print_Letters_Default/prints/4.png"                ); | ||||
| 	lualogic_defineprint("5"                 , "Add-Ons/Print_Letters_Default/prints/5.png"                ); | ||||
| 	lualogic_defineprint("6"                 , "Add-Ons/Print_Letters_Default/prints/6.png"                ); | ||||
| 	lualogic_defineprint("7"                 , "Add-Ons/Print_Letters_Default/prints/7.png"                ); | ||||
| 	lualogic_defineprint("8"                 , "Add-Ons/Print_Letters_Default/prints/8.png"                ); | ||||
| 	lualogic_defineprint("9"                 , "Add-Ons/Print_Letters_Default/prints/9.png"                ); | ||||
| 	 | ||||
| 	lualogic_defineprint("bang"              , "Add-Ons/Print_Letters_Default/prints/-bang.png"            ); | ||||
| 	lualogic_defineprint("at"                , "Add-Ons/Print_Letters_Default/prints/-at.png"              ); | ||||
| 	lualogic_defineprint("pound"             , "Add-Ons/Print_Letters_Default/prints/-pound.png"           ); | ||||
| 	lualogic_defineprint("dollar"            , "Add-Ons/Print_Letters_Default/prints/-dollar.png"          ); | ||||
| 	lualogic_defineprint("percent"           , "Add-Ons/Print_Letters_Default/prints/-percent.png"         ); | ||||
| 	lualogic_defineprint("caret"             , "Add-Ons/Print_Letters_Default/prints/-caret.png"           ); | ||||
| 	lualogic_defineprint("and"               , "Add-Ons/Print_Letters_Default/prints/-and.png"             ); | ||||
| 	lualogic_defineprint("asterisk"          , "Add-Ons/Print_Letters_Default/prints/-asterisk.png"        ); | ||||
| 	lualogic_defineprint("minus"             , "Add-Ons/Print_Letters_Default/prints/-minus.png"           ); | ||||
| 	lualogic_defineprint("equals"            , "Add-Ons/Print_Letters_Default/prints/-equals.png"          ); | ||||
| 	lualogic_defineprint("plus"              , "Add-Ons/Print_Letters_Default/prints/-plus.png"            ); | ||||
| 	lualogic_defineprint("apostrophe"        , "Add-Ons/Print_Letters_Default/prints/-apostrophe.png"      ); | ||||
| 	lualogic_defineprint("less_than"         , "Add-Ons/Print_Letters_Default/prints/-less_than.png"       ); | ||||
| 	lualogic_defineprint("greater_than"      , "Add-Ons/Print_Letters_Default/prints/-greater_than.png"    ); | ||||
| 	lualogic_defineprint("period"            , "Add-Ons/Print_Letters_Default/prints/-period.png"          ); | ||||
| 	lualogic_defineprint("qmark"             , "Add-Ons/Print_Letters_Default/prints/-qmark.png"           ); | ||||
| 	 | ||||
| 	lualogic_defineprint("apostrophe2"       , "Add-Ons/Print_Letters_Extra/prints/-apostrophe2.png"       ); | ||||
| 	lualogic_defineprint("colon"             , "Add-Ons/Print_Letters_Extra/prints/-colon.png"             ); | ||||
| 	lualogic_defineprint("comma"             , "Add-Ons/Print_Letters_Extra/prints/-comma.png"             ); | ||||
| 	lualogic_defineprint("curlybracketleft"  , "Add-Ons/Print_Letters_Extra/prints/-curlybracketleft.png"  ); | ||||
| 	lualogic_defineprint("curlybracketright" , "Add-Ons/Print_Letters_Extra/prints/-curlybracketright.png" ); | ||||
| 	lualogic_defineprint("currencysign"      , "Add-Ons/Print_Letters_Extra/prints/-currencysign.png"      ); | ||||
| 	lualogic_defineprint("euro"              , "Add-Ons/Print_Letters_Extra/prints/-euro.png"              ); | ||||
| 	lualogic_defineprint("onehalf"           , "Add-Ons/Print_Letters_Extra/prints/-onehalf.png"           ); | ||||
| 	lualogic_defineprint("poundsymbol"       , "Add-Ons/Print_Letters_Extra/prints/-poundsymbol.png"       ); | ||||
| 	lualogic_defineprint("roundbracketleft"  , "Add-Ons/Print_Letters_Extra/prints/-roundbracketleft.png"  ); | ||||
| 	lualogic_defineprint("roundbracketright" , "Add-Ons/Print_Letters_Extra/prints/-roundbracketright.png" ); | ||||
| 	lualogic_defineprint("slashleft"         , "Add-Ons/Print_Letters_Extra/prints/-slashleft.png"         ); | ||||
| 	lualogic_defineprint("slashright"        , "Add-Ons/Print_Letters_Extra/prints/-slashright.png"        ); | ||||
| 	lualogic_defineprint("squarebracketleft" , "Add-Ons/Print_Letters_Extra/prints/-squarebracketleft.png" ); | ||||
| 	lualogic_defineprint("squarebracketright", "Add-Ons/Print_Letters_Extra/prints/-squarebracketright.png"); | ||||
| 	lualogic_defineprint("tilde"             , "Add-Ons/Print_Letters_Extra/prints/-tilde.png"             ); | ||||
| 	lualogic_defineprint("umlaut"            , "Add-Ons/Print_Letters_Extra/prints/-umlaut.png"            ); | ||||
| 	lualogic_defineprint("underscore"        , "Add-Ons/Print_Letters_Extra/prints/-underscore.png"        ); | ||||
| 	lualogic_defineprint("verticalbar"       , "Add-Ons/Print_Letters_Extra/prints/-verticalbar.png"       ); | ||||
| 	 | ||||
| 	lualogic_defineprint("semicolon"         , "Add-Ons/Print_Letters_ExtraExtended/prints/-semicolon.png" ); | ||||
| 	lualogic_defineprint("backtick"          , "Add-Ons/Print_Letters_ExtraExtended/prints/-backtick.png"  ); | ||||
| } | ||||
| schedule(0, 0, "lualogic_loadprintsandcolors"); | ||||
|  | ||||
| package LuaLogic | ||||
| { | ||||
| 	function onServerDestroyed() | ||||
| 	{ | ||||
| 		deleteVariables("$LuaLogic*"); | ||||
| 		parent::onServerDestroyed(); | ||||
| 	} | ||||
| }; | ||||
| activatePackage("LuaLogic"); | ||||
|  | ||||
| function llc(){ | ||||
| 	lualogic_connect(25000); | ||||
| } | ||||
|  | ||||
| function llr(){ | ||||
| 	%path = $LuaLogic::Path; | ||||
| 	deleteVariables("$LuaLogic*"); | ||||
| 	$LuaLogic::Path = %path; | ||||
| 	 | ||||
| 	//resetAllOpCallFunc(); | ||||
| 	exec("./lualogic.cs"); | ||||
| 	schedule(1000, 0, llc); | ||||
| } | ||||
							
								
								
									
										122
									
								
								scripts/tcp.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								scripts/tcp.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,122 @@ | ||||
| function LuaLogicTCP::sendData(%this) | ||||
| { | ||||
| 	cancel(%this.lualogicTick); | ||||
| 	%this.lualogicTick = %this.schedule(1, "sendData"); | ||||
|  | ||||
| 	if(%this.data !$= "") | ||||
| 	{ | ||||
| 		%data = %this.data; | ||||
| 		while(strpos(%data, ";;") != -1) | ||||
| 			%data = strReplace(%data, ";;", "; ;"); | ||||
| 		 | ||||
| 		%this.send(%data @ "\n"); | ||||
| 		%this.data = ""; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function LuaLogicTCP::onConnected(%this) | ||||
| { | ||||
| 	lualogic_print("tcp connected"); | ||||
| 	 | ||||
| 	%this.data = ""; | ||||
| 	%this.sendData(); | ||||
| 	%this.isConnected = true; | ||||
|  | ||||
| 	lualogic_sendoptions(); | ||||
| 	lualogic_sendgatedefinitions(); | ||||
| 	lualogic_sendall(); | ||||
| } | ||||
|  | ||||
| function LuaLogicTCP::onLine(%this, %line) | ||||
| { | ||||
| 	%cmd = getField(%line, 0); | ||||
| 	switch$(%cmd) | ||||
| 	{ | ||||
| 		case "WU": | ||||
| 			%state = getField(%line, 1)|0; | ||||
| 			%count = getFieldCount(%line); | ||||
|  | ||||
| 			if(%state) | ||||
| 			{ | ||||
| 				for(%i = 2; %i < %count; %i++) | ||||
| 				{ | ||||
| 					%brick = getField(%line, %i); | ||||
| 					if(isObject(%brick)) | ||||
| 						%brick.setColorFX(3); | ||||
| 				} | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				for(%i = 2; %i < %count; %i++) | ||||
| 				{ | ||||
| 					%brick = getField(%line, %i); | ||||
| 					if(isObject(%brick)) | ||||
| 						%brick.setColorFX(0); | ||||
| 				} | ||||
| 			} | ||||
| 		case "TPS": | ||||
| 			%tz = getField(%line, 1); | ||||
|  | ||||
| 			%count = ClientGroup.getCount(); | ||||
| 			for(%i = 0; %i < %count; %i++) | ||||
| 			{ | ||||
| 				%client = ClientGroup.getObject(%i); | ||||
| 				if(%client.logicLTR) | ||||
| 					commandToClient(%client, 'bottomPrint', "\c3Logic Tick Rate\c6: " @ %tz, 2, 1); | ||||
| 			} | ||||
| 		case "GINFO": | ||||
| 			%client = getField(%line, 1); | ||||
| 			if(isObject(%client)) | ||||
| 			{ | ||||
| 				%info = getField(%line, 2); | ||||
| 				%info = lualogic_collapseescape(%info); | ||||
| 				%info = strReplace(%info, "\\c0", "\c0"); | ||||
| 				%info = strReplace(%info, "\\c2", "\c2"); | ||||
| 				%info = strReplace(%info, "\\c5", "\c5"); | ||||
| 				%client.centerPrint(%info, 5); | ||||
| 			} | ||||
| 		case "SINFO": | ||||
| 			if(isObject(%client = getField(%line, 1))) | ||||
| 			{ | ||||
| 				%wires = getField(%line, 2); | ||||
| 				%gates = getField(%line, 3); | ||||
| 				%inports = getField(%line, 4); | ||||
| 				%outports = getField(%line, 5); | ||||
|  | ||||
| 				messageClient(%client, '', '\c3Wires\c6: %1', %wires); | ||||
| 				messageClient(%client, '', '\c3Gates\c6: %1', %gates); | ||||
| 				messageClient(%client, '', '\c3Ports\c6: %1 inputs | %2 outputs (%3 total)', %inports, %outports, %inports + %outports); | ||||
| 			} | ||||
| 		case "CB": | ||||
| 			%data = getFields(%line, 1, getFieldCount(%line)); | ||||
| 			%data = nextToken(%data, brick, "\t"); | ||||
| 			while(%brick !$= ""){ | ||||
| 				%data = nextToken(%data, argc, "\t"); | ||||
| 				 | ||||
| 				for(%i=0; %i<%argc; %i++){ | ||||
| 					%data = nextToken(%data, av, "\t"); | ||||
| 					%argv[%i] = lualogic_collapseescape(%av); | ||||
| 				} | ||||
| 				 | ||||
| 				if(isObject(%brick)){ | ||||
| 					%brick.getDatablock().LuaLogic_Callback(%brick, %argv0, %argv1, %argv2, %argv3, %argv4, %argv5, %argv6, %argv7, %argv8, %argv9); | ||||
| 				} | ||||
| 				 | ||||
| 				%data = nextToken(%data, brick, "\t"); | ||||
| 			} | ||||
| 		case "TEST": | ||||
| 			talk("Time: " @ getField(%line, 1)); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function LuaLogicTCP::onConnectFailed(%this) | ||||
| { | ||||
| 	lualogic_print("tcp failed to connect"); | ||||
| } | ||||
|  | ||||
| function LuaLogicTCP::onDisconnect(%this) | ||||
| { | ||||
| 	lualogic_print("tcp disconnected"); | ||||
| 	%this.isConnected = false; | ||||
| 	cancel(%this.lualogicTick); | ||||
| } | ||||
							
								
								
									
										292
									
								
								scripts/utilities.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										292
									
								
								scripts/utilities.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,292 @@ | ||||
|  | ||||
| function mClampFloat(%x, %min, %max){ | ||||
| 	return %x<%min ? %min : (%x>%max ? %max : %x); | ||||
| } | ||||
|  | ||||
| function lualogic_registergatedefinition(%data){ | ||||
| 	//lualogic_registergatedefinition_auto(%data); | ||||
| 	 | ||||
| 	//handled automatically now | ||||
| } | ||||
|  | ||||
| function lualogic_registergatedefinition_auto(%data){ | ||||
| 	if(!isObject(%data)) | ||||
| 		return; | ||||
| 	 | ||||
| 	%id = %data.getID(); | ||||
| 	 | ||||
| 	if((%idx = $LuaLogic::GateDefinitionIDX[%id]) $= "") | ||||
| 	{ | ||||
| 		%idx = $LuaLogic::NumGateDefintions+0; | ||||
| 		$LuaLogic::GateDefinitionIDX[%id] = %idx; | ||||
| 		$LuaLogic::NumGateDefintions++; | ||||
| 	} | ||||
| 	 | ||||
| 	%numports = %data.numLogicPorts; | ||||
| 	 | ||||
| 	%def = %id @ ";" @ | ||||
| 		lualogic_expandescape(%data.logicUIName) @ ";" @ | ||||
| 		lualogic_expandescape(%data.logicUIDesc) @ ";" @ | ||||
| 		lualogic_expandescape(%data.logicInit) @ ";" @ | ||||
| 		lualogic_expandescape(%data.logicUpdate) @ ";" @ | ||||
| 		lualogic_expandescape(%data.logicInput) @ ";" @ | ||||
| 		lualogic_expandescape(%data.logicGlobal) @ ";" @ | ||||
| 		%numports | ||||
| 	; | ||||
| 	 | ||||
| 	for(%i = 0; %i < %numports; %i++) | ||||
| 	{ | ||||
| 		%def = %def @ ";" @ %data.logicPortType[%i] @ ";" @ %data.logicPortPos[%i] @ ";" @ %data.logicPortDir[%i] | ||||
| 				@ ";" @ (%data.logicPortCauseUpdate[%i] == true) @ ";" @ %data.logicPortUIName[%i]; | ||||
| 	} | ||||
| 	 | ||||
| 	$LuaLogic::GateDefintion[%idx] = %def; | ||||
| } | ||||
|  | ||||
| function lualogic_registerAllGateDefinitions(){ | ||||
| 	echo("LuaLogic: Registering gate definitions"); | ||||
| 	 | ||||
| 	for(%dbidx=0; %dbidx<DatablockGroup.getCount(); %dbidx++){ | ||||
| 		%db = DatablockGroup.getObject(%dbidx); | ||||
| 		if(%db.isLogic && %db.isLogicGate){ | ||||
| 			lualogic_registergatedefinition_auto(%db); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| schedule(1, 0, lualogic_registerAllGateDefinitions); | ||||
|  | ||||
| function lualogic_print(%text) | ||||
| { | ||||
| 	echo("LuaLogic -> ", %text); | ||||
| } | ||||
|  | ||||
| function lualogic_roundpos(%pos) | ||||
| { | ||||
| 	return mFloor(getWord(%pos, 0)*4)/4 SPC mFloor(getWord(%pos, 1)*4)/4 SPC mFloor(getWord(%pos, 2)*10)/10; | ||||
| } | ||||
|  | ||||
| function lualogic_roundstudpos(%pos) | ||||
| { | ||||
| 	return mFloor(getWord(%pos, 0)*2)/2 SPC mFloor(getWord(%pos, 1)*2)/2 SPC mFloor(getWord(%pos, 2)*5)/5; | ||||
| } | ||||
|  | ||||
| function lualogic_pos(%pos) | ||||
| { | ||||
| 	%pos = lualogic_roundpos(%pos); | ||||
| 	return getWord(%pos, 0)/0.25 SPC getWord(%pos, 1)/0.25 SPC getWord(%pos, 2)/0.1; | ||||
| } | ||||
|  | ||||
| function lualogic_studpos(%pos) | ||||
| { | ||||
| 	%pos = lualogic_roundstudpos(%pos); | ||||
| 	return getWord(%pos, 0)/0.5*2 + 1 SPC getWord(%pos, 1)/0.5*2 + 1 SPC getWord(%pos, 2)/0.2*2; | ||||
| } | ||||
|  | ||||
| function lualogic_postobrick(%pos) | ||||
| { | ||||
| 	return getWord(%pos, 0)*0.25 SPC getWord(%pos, 1)*0.25 SPC getWord(%pos, 2)*0.1; | ||||
| } | ||||
|  | ||||
| function lualogic_connect(%port) | ||||
| { | ||||
| 	if(isObject(LuaLogicTCP)) | ||||
| 		LuaLogicTCP.delete(); | ||||
| 	%tcp = new TCPObject(LuaLogicTCP); | ||||
| 	%tcp.connect("127.0.0.1:" @ %port); | ||||
| } | ||||
|  | ||||
| function lualogic_send(%data) | ||||
| { | ||||
| 	if(isObject(LuaLogicTCP) && LuaLogicTCP.isConnected) | ||||
| 	{ | ||||
| 		//while(strpos(%data, ";;") != -1) | ||||
| 		//	%data = strReplace(%data, ";;", "; ;"); | ||||
| 		 | ||||
| 		if(strlen(LuaLogicTCP.data) + strlen(%data) >= 1024) | ||||
| 			LuaLogicTCP.sendData(); | ||||
| 		 | ||||
| 		if(LuaLogicTCP.data $= "") | ||||
| 			LuaLogicTCP.data = %data; | ||||
| 		else | ||||
| 			LuaLogicTCP.data = LuaLogicTCP.data @ ";" @ %data; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function lualogic_sendgatedefinitions() | ||||
| { | ||||
| 	for(%i = 0; %i < $LuaLogic::NumGateDefintions; %i++) | ||||
| 		lualogic_send("GD;" @ $LuaLogic::GateDefintion[%i]); | ||||
| } | ||||
|  | ||||
| function lualogic_sendoptions(){ | ||||
| 	lualogic_send("OPT;TICK_ENABLED;" @ $Pref::Server::LuaLogic::OPT_TICK_ENABLED); | ||||
| 	lualogic_send("OPT;TICK_TIME;"    @ $Pref::Server::LuaLogic::OPT_TICK_TIME   ); | ||||
| 	lualogic_send("OPT;FX_UPDATES;"   @ $Pref::Server::LuaLogic::OPT_FX_UPDATES  ); | ||||
| 	lualogic_send("OPT;FX_TIME;"      @ $Pref::Server::LuaLogic::OPT_FX_TIME     ); | ||||
| 	lualogic_send("OPT;TICK_MULT;"    @ $Pref::Server::LuaLogic::OPT_TICK_MULT   ); | ||||
| } | ||||
|  | ||||
| function lualogic_savedata(){ | ||||
| 	lualogic_send("SAVE"); | ||||
| } | ||||
|  | ||||
| function lualogic_sendinput(%gate, %argc, %arg0, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12, %arg13, %arg14, %arg15) | ||||
| { | ||||
| 	%args = %arg0; | ||||
| 	for(%i = 1; %i < %argc; %i++) | ||||
| 		%args = %args @ ";" @ lualogic_expandescape(%arg[%i]); | ||||
| 	 | ||||
| 	if(%argc > 0) | ||||
| 		lualogic_send("IN;" @ %gate.getID() @ ";" @ %argc @ ";" @ %args); | ||||
| 	else | ||||
| 		lualogic_send("IN;" @ %gate.getID() @ ";" @ %argc); | ||||
| } | ||||
|  | ||||
| function lualogic_ss(%obj, %state) | ||||
| { | ||||
| 	lualogic_send("SG;" @ %obj @ ";" @ (%state == true)); | ||||
| } | ||||
|  | ||||
| function lualogic_definecolor(%color, %rgb, %allowTransparency) | ||||
| { | ||||
| 	%r = getWord(%rgb, 0); | ||||
| 	%g = getWord(%rgb, 1); | ||||
| 	%b = getWord(%rgb, 2); | ||||
|  | ||||
| 	%alpha = %allowTransparency ? 0.001 : 1; | ||||
|  | ||||
| 	%bestDist = 9e9; | ||||
|  | ||||
| 	for(%i = 0; %i < 64; %i++) | ||||
| 	{ | ||||
| 		%crgba = getColorIDTable(%i); | ||||
| 		if(getWord(%crgba, 3) >= %alpha) | ||||
| 		{ | ||||
| 			%dr = getWord(%crgba, 0) - %r; | ||||
| 			%dg = getWord(%crgba, 1) - %g; | ||||
| 			%db = getWord(%crgba, 2) - %b; | ||||
| 			%dist = %dr*%dr + %dg*%dg + %db*%db; | ||||
|  | ||||
| 			if(%dist < %bestDist) | ||||
| 			{ | ||||
| 				%bestDist = %dist; | ||||
| 				%bestColor = %i; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	$LuaLogic::Color[%color] = %bestColor; | ||||
| 	return %bestColor; | ||||
| } | ||||
|  | ||||
| function lualogic_iscolor(%color) | ||||
| { | ||||
| 	return $LuaLogic::Color[%color] !$= ""; | ||||
| } | ||||
|  | ||||
| function lualogic_getcolor(%color) | ||||
| { | ||||
| 	if($LuaLogic::Color[%color] !$= "") | ||||
| 		return $LuaLogic::Color[%color]; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| function lualogic_defineprint(%print, %file) | ||||
| { | ||||
| 	%count = getNumPrintTextures(); | ||||
| 	for(%i = 0; %i < %count; %i++) | ||||
| 	{ | ||||
| 		if(getPrintTexture(%i) $= %file) | ||||
| 		{ | ||||
| 			$LuaLogic::Print[%print] = %i; | ||||
| 			return %i; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return ""; | ||||
| } | ||||
|  | ||||
| function lualogic_isprint(%print) | ||||
| { | ||||
| 	return $LuaLogic::Print[%print] !$= ""; | ||||
| } | ||||
|  | ||||
| function lualogic_getprint(%print) | ||||
| { | ||||
| 	if($LuaLogic::Print[%print] !$= "") | ||||
| 		return $LuaLogic::Print[%print]; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| function lualogic_readfile(%filename){ | ||||
| 	%filestr=""; | ||||
| 	 | ||||
| 	%file=new FileObject(); | ||||
| 	%success=%file.openForRead(%filename); | ||||
| 	 | ||||
| 	if(%success){ | ||||
| 		while(!%file.isEOF()){ | ||||
| 			%line = %file.readLine(); | ||||
| 			%filestr = %filestr @ %line @ "\n"; | ||||
| 		} | ||||
| 	}else{ | ||||
| 		echo("LuaLogic: Failed to read file \"" @ %filename @ "\""); | ||||
| 	} | ||||
| 	%file.close(); | ||||
| 	%file.delete(); | ||||
| 	 | ||||
| 	return %filestr; | ||||
| } | ||||
|  | ||||
| $LuaLogic::EscapeCount = 0; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\\"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "b"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\t"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "t"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\n"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "n"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\r"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "r"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\'"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "a"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\""; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "q"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = ";" ; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "s"; $LuaLogic::EscapeCount++; | ||||
| $LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = ":" ; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "c"; $LuaLogic::EscapeCount++; | ||||
|  | ||||
| function lualogic_expandescape(%str){ | ||||
| 	%ostr = ""; | ||||
| 	 | ||||
| 	%len = strLen(%str); | ||||
| 	for(%i=0; %i<%len; %i++){ | ||||
| 		%ci = getSubStr(%str, %i, 1); | ||||
| 		 | ||||
| 		%co = %ci; | ||||
| 		for(%j=0; %j<$LuaLogic::EscapeCount; %j++){ | ||||
| 			if(%ci$=$LuaLogic::EscapeIn[%j]){ %co = "\\" @ $LuaLogic::EscapeOut[%j]; } | ||||
| 		} | ||||
| 		 | ||||
| 		%ostr = %ostr @ %co; | ||||
| 	} | ||||
| 	 | ||||
| 	return %ostr; | ||||
| } | ||||
|  | ||||
| function lualogic_collapseescape(%str){ | ||||
| 	%ostr = ""; | ||||
| 	 | ||||
| 	%i = 0; | ||||
| 	%len = strLen(%str); | ||||
| 	while(%i<%len){ | ||||
| 		%ci = getSubStr(%str, %i, 1); | ||||
| 		 | ||||
| 		%co = %ci; | ||||
| 		if(%ci$="\\" && %i<%len-1){ | ||||
| 			%i++; | ||||
| 			%ci = getSubStr(%str, %i, 1); | ||||
| 			for(%j=0; %j<$LuaLogic::EscapeCount; %j++){ | ||||
| 				if(%ci$=$LuaLogic::EscapeOut[%j]){ %co = $LuaLogic::EscapeIn[%j]; } | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		%ostr = %ostr @ %co; | ||||
| 		%i++; | ||||
| 	} | ||||
| 	 | ||||
| 	return %ostr; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Redo
					Redo