public float API_Connect(string name) { //Console.WriteLine(_caller + " connecting to " + name); MimanTing maybeTing = ConnectionAPI_Optimized.GetTingFromNameOrSourceCodeName(_tingRunner, name); // _tingRunner.GetTingUnsafe (name) as MimanTing; if (maybeTing != null) { return(_caller.AddConnectionToTing(maybeTing)); } else { string msg = "Can't find " + name + " to connect to"; if (_caller is Computer) { (_caller as Computer).API_Print(msg); } else { _caller.Say(msg, ""); } return(-1f); } }
void GenerateProgramAPI(Program pProgram) { var defs = new List<FunctionDefinition> (FunctionDefinitionCreator.CreateDefinitions (this, typeof(Computer))); if (hasGraphicsAPI) { var graphicsApi = new GraphicsAPI (this); defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (graphicsApi, typeof(GraphicsAPI))); var linesFn = new FunctionDefinition ( "void", "Lines", new string[] { "array" }, new string[] { "points" }, new ExternalFunctionCreator.OnFunctionCall (graphicsApi.Lines), FunctionDocumentation.Default ()); defs.Add(linesFn); } if (hasInternetAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new InternetAPI (this, _tingRunner), typeof(InternetAPI))); ConnectionAPI_Optimized connectionApi = new ConnectionAPI_Optimized(this, _tingRunner, pProgram); defs.Add(new FunctionDefinition( "number", "Connect", new string[] {"string"}, new string[] {"name"}, new ExternalFunctionCreator.OnFunctionCall(connectionApi.Connect), FunctionDocumentation.Default())); defs.Add(new FunctionDefinition( "void", "DisconnectAll", new string[] {}, new string[] {}, new ExternalFunctionCreator.OnFunctionCall(connectionApi.DisconnectAll), new FunctionDocumentation("Remove all connections", new string[] {}))); var rfc = new FunctionDefinition ( "number", "RemoteFunctionCall", new string[] { "number", "string", "array" }, new string[] { "receiverIndex", "functionName", "arguments" }, new ExternalFunctionCreator.OnFunctionCall (connectionApi.RemoteFunctionCall), FunctionDocumentation.Default ()); rfc.hideInModifier = true; defs.Add(rfc); } if (hasWeatherAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new WeatherAPI (this, _worldSettings), typeof(WeatherAPI))); } if (hasLampAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new LampAPI (this, _tingRunner), typeof(LampAPI))); } if (hasDoorAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new DoorAPI (this, _tingRunner, _roomRunner), typeof(DoorAPI))); } if (hasMemoryAPI) { MemoryAPI memoryApi = new MemoryAPI(this, _tingRunner); defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (memoryApi, typeof(MemoryAPI))); // Are these added manually because they can take any kind of argument..? defs.Add(new FunctionDefinition( "void", "SaveMemory", new string[] {"string", "var"}, new string[] {"key", "value"}, new ExternalFunctionCreator.OnFunctionCall(memoryApi.SaveMemory), FunctionDocumentation.Default())); defs.Add(new FunctionDefinition( "var", "LoadMemory", new string[] {"string"}, new string[] {"key"}, new ExternalFunctionCreator.OnFunctionCall(memoryApi.LoadMemory), FunctionDocumentation.Default())); } if (hasVoiceAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new VoiceAPI (this, _tingRunner, _dialogueRunner), typeof(VoiceAPI))); } if (hasElevatorAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new ElevatorAPI (this, _tingRunner), typeof(ElevatorAPI))); } if (hasTingrunnerAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new TingrunnerAPI (this, _tingRunner, _roomRunner), typeof(TingrunnerAPI))); } if (hasTrapAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new TrapAPI (this, _tingRunner, _dialogueRunner), typeof(TrapAPI))); } if (hasHeartAPI) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new HeartAPI (this, _tingRunner, _dialogueRunner), typeof(HeartAPI))); } if (true /*hasArcadeMachineAPI*/) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new ArcadeMachineAPI (this), typeof(ArcadeMachineAPI))); } if (true /*hasFloppyAPI*/) { defs.AddRange (FunctionDefinitionCreator.CreateDefinitions (new FloppyAPI (this, _tingRunner), typeof(FloppyAPI))); } pProgram.FunctionDefinitions = defs; }