public void Update(float deltaTime) { if (updateActions != null) { //updateActions(this, deltaTime); FurnitureActions.CallFunctionsWithFurniture(updateActions.ToArray(), this, deltaTime); } }
void LoadFurnitureLua(string filePath) { string myLuaCode = System.IO.File.ReadAllText(filePath); // Instantiate the singleton FurnitureActions.addScript(myLuaCode); }
public void LoadPrototypes() { PrototypeManager.Furniture.LoadModPrototypesFromFile(mods); PrototypeManager.Inventory.LoadModPrototypesFromFile(mods); PrototypeManager.Need.LoadModPrototypesFromFile(mods); PrototypeManager.Trader.LoadModPrototypesFromFile(mods); FurnitureActions.LoadModsScripts(mods); NeedActions.LoadModsScripts(mods); }
public void DoWork(float workTime) { // We don't know if the Job can actually be worked, but still call the callbacks // so that animations and whatnot can be updated. if (cbJobWorked != null) { cbJobWorked(this); } if (cbJobWorkedLua != null) { foreach (string luaFunction in cbJobWorkedLua.ToList()) { FurnitureActions.CallFunction(luaFunction, this); } } // Check to make sure we actually have everything we need. // If not, don't register the work time. if (HasAllMaterial() == false) { ////Debug.LogError("Tried to do work on a job that doesn't have all the material."); return; } jobTime -= workTime; if (jobTime <= 0) { // Do whatever is supposed to happen with a job cycle completes. if (cbJobCompleted != null) { cbJobCompleted(this); } foreach (string luaFunction in cbJobCompletedLua.ToList()) { FurnitureActions.CallFunction(luaFunction, this); } if (jobRepeats == false) { // Let everyone know that the job is officially concluded if (cbJobStopped != null) { cbJobStopped(this); } } else { // This is a repeating job and must be reset. jobTime += jobTimeRequired; } } }
public string GetSpriteName() { if (getSpriteNameAction == null || getSpriteNameAction.Length == 0) { return(objectType); } DynValue ret = FurnitureActions.CallFunction(getSpriteNameAction, this); return(ret.String); }
/// <summary> /// Fire the event named actionName, resulting in all lua functions being called. /// </summary> /// <param name="actionName">Name of the action being triggered.</param> /// <param name="target">Object, passed to LUA function as 1-argument (TODO: make it an object).</param> /// <param name="deltaTime">Time since last Trigger of this event.</param> public void Trigger(string actionName, Furniture target, float deltaTime = 0f) { if (!actionsList.ContainsKey(actionName) || actionsList[actionName] == null) { return; } else { FurnitureActions.CallFunctionsWithFurniture(actionsList[actionName].ToArray(), target, deltaTime); } }
public ENTERABILITY IsEnterable() { if (isEnterableAction == null || isEnterableAction.Length == 0) { return(ENTERABILITY.Yes); } //FurnitureActions.CallFunctionsWithFurniture(isEnterableActions.ToArray(), this); DynValue ret = FurnitureActions.CallFunction(isEnterableAction, this); return((ENTERABILITY)ret.Number); }
/// <summary> /// "Fire" the event named actionName, resulting in all lua functions being called. /// </summary> /// <param name="actionName">Name of the action being triggered.</param> /// <param name="target">Object, passed to LUA function as 1-argument (TODO: make it an object).</param> /// <param name="deltaTime">Time since last Trigger of this event.</param> public void Trigger(string actionName, Furniture target, float deltaTime = 0f) { if (!actionsList.ContainsKey(actionName) || actionsList[actionName] == null) { ////Debug.LogWarning(string.Format("The action \"{0}\" is associated with no LUA function.", actionName)); return; } else { FurnitureActions.CallFunctionsWithFurniture(actionsList[actionName].ToArray(), target, deltaTime); } }
public void LoadPrototypes() { PrototypeManager.Furniture.LoadPrototypes(mods); PrototypeManager.Inventory.LoadPrototypes(mods); PrototypeManager.Need.LoadPrototypes(mods); PrototypeManager.Trader.LoadPrototypes(mods); PrototypeManager.SchedulerEvent.LoadPrototypes(mods); PrototypeManager.Stat.LoadPrototypes(mods); PrototypeManager.Quest.LoadPrototypes(mods); FurnitureActions.LoadModsScripts(mods); NeedActions.LoadModsScripts(mods); }
// Checks whether the given floor type is allowed to be built on the tile. // TODO Export this kind of check to an XML/LUA file for easier modding of floor types. private bool CanBuildTileTypeHere(Tile t, TileType tileType) { DynValue value = FurnitureActions.CallFunction(tileType.CanBuildHereLua, t); if (value != null) { return(value.Boolean); } else { Debug.ULogChannel("Lua", "Found no lua function " + tileType.CanBuildHereLua); return(false); } }
public void Update(float deltaTime) { if (updateActions != null) { //updateActions(this, deltaTime); if (powerValue > 0 && isPowerGenerator == false) { if (World.current.powerSystem.RequestPower(this) == false) { World.current.powerSystem.RegisterPowerConsumer(this); return; } } FurnitureActions.CallFunctionsWithFurniture(updateActions.ToArray(), this, deltaTime); } }
public FurnitureActions() { // Tell the LUA interpreter system to load all the classes // that we have marked as [MoonSharpUserData] UserData.RegisterAssembly(); _Instance = this; myLuaScript = new Script(); // If we want to be able to instantiate a new object of a class // i.e. by doing SomeClass.__new() // We need to make the base type visible. myLuaScript.Globals["Inventory"] = typeof(Inventory); myLuaScript.Globals["Job"] = typeof(Job); // Also to access statics/globals myLuaScript.Globals["World"] = typeof(World); }
/// <summary> /// Loads all TileType definitions in Data\ and Data\Mods /// </summary> public static void LoadTileTypes() { // Load lua code string luaPath = System.IO.Path.Combine(Application.streamingAssetsPath, "LUA"); string luaFilePath = System.IO.Path.Combine(luaPath, "Tile.lua"); string luaCode = System.IO.File.ReadAllText(luaFilePath); FurnitureActions.addScript(luaCode); // Load all mod defined lua code foreach (DirectoryInfo mod in WorldController.Instance.modsManager.GetMods()) { foreach (FileInfo file in mod.GetFiles("Tiles.lua")) { Debug.ULogChannel("TileType", "Loading mod " + mod.Name + " TileType definitions!"); luaCode = System.IO.File.ReadAllText(file.FullName); FurnitureActions.addScript(luaCode); } } // Load TileType xml definitions string dataPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Data"); string xmlPath = System.IO.Path.Combine(dataPath, "Tiles.xml"); string xmlText = System.IO.File.ReadAllText(xmlPath); readTileTypesFromXml(xmlText); // Load all mod defined TileType definitions foreach (DirectoryInfo mod in WorldController.Instance.modsManager.GetMods()) { foreach (FileInfo file in mod.GetFiles("Tiles.xml")) { Debug.ULogChannel("TileType", "Loading mod " + mod.Name + " TileType definitions!"); xmlText = System.IO.File.ReadAllText(file.FullName); readTileTypesFromXml(xmlText); } } }
public FurnitureActions(string rawLuaCode) { // Tell the Lua interpreter system to load all the classes // that we have marked as [MoonSharpUserData] UserData.RegisterAssembly(); _Instance = this; myLuaScript = new Script(); // If we want to be able to instantiate a new object of a class // i.e. by doing SomeClass.__new() (in the Lua script) // We need to make the base type visible // UserData.RegisterType<Job>(); to not need [MoonSharpUserData] annotations myLuaScript.Globals["Inventory"] = typeof(Inventory); myLuaScript.Globals["Job"] = typeof(Job); //Also to access statics/ globals myLuaScript.Globals["World"] = typeof(World); //ActivateRemoteDebugger(myLuaScript); myLuaScript.DoString(rawLuaCode); }
public void Deconstruct() { Debug.Log("Deconstruct"); int x = tile.X; int y = tile.Y; int fwidth = 1; int fheight = 1; bool linksToNeighbour = false; if (tile.Furniture != null) { Furniture f = tile.Furniture; fwidth = f.Width; fheight = f.Height; linksToNeighbour = f.linksToNeighbour; f.CancelJobs(); } // We call lua to decostruct if (uninstallActions != null) { FurnitureActions.CallFunctionsWithFurniture(uninstallActions.ToArray(), this, 0); } // Update thermalDiffusifity to default value World.current.temperature.SetThermalDiffusivity(tile.X, tile.Y, Temperature.defaultThermalDiffusivity); tile.UnplaceFurniture(); if (cbOnRemoved != null) { cbOnRemoved(this); } // Do we need to recalculate our rooms? if (roomEnclosure) { Room.DoRoomFloodFill(this.tile); } ////World.current.InvalidateTileGraph(); if (World.current.tileGraph != null) { World.current.tileGraph.RegenerateGraphAtTile(tile); } // We should inform our neighbours that they have just lost a // neighbour regardless of objectType. // Just trigger their OnChangedCallback. if (linksToNeighbour == true) { for (int xpos = x - 1; xpos < (x + fwidth + 1); xpos++) { for (int ypos = y - 1; ypos < (y + fheight + 1); ypos++) { Tile t = World.current.GetTileAt(xpos, ypos); if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null) { t.Furniture.cbOnChanged(t.Furniture); } } } } // At this point, no DATA structures should be pointing to us, so we // should get garbage-collected. }
static public Furniture PlaceInstance(Furniture proto, Tile tile) { if (proto.funcPositionValidation(tile) == false) { Debug.LogError("PlaceInstance -- Position Validity Function returned FALSE."); return(null); } // We know our placement destination is valid. Furniture obj = proto.Clone(); obj.tile = tile; // FIXME: This assumes we are 1x1! if (tile.PlaceFurniture(obj) == false) { // For some reason, we weren't able to place our object in this tile. // (Probably it was already occupied.) // Do NOT return our newly instantiated object. // (It will be garbage collected.) return(null); } if (obj.linksToNeighbour) { // This type of furniture links itself to its neighbours, // so we should inform our neighbours that they have a new // buddy. Just trigger their OnChangedCallback. Tile t; int x = tile.X; int y = tile.Y; for (int xpos = x - 1; xpos < (x + proto.Width + 1); xpos++) { for (int ypos = y - 1; ypos < (y + proto.Height + 1); ypos++) { t = World.current.GetTileAt(xpos, ypos); if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null) { t.Furniture.cbOnChanged(t.Furniture); } } } } // Call LUA install scripts if (obj.installActions != null) { FurnitureActions.CallFunctionsWithFurniture(obj.installActions.ToArray(), obj, 0); } // Update thermalDiffusifity using coefficient float thermalDiffusivity = Temperature.defaultThermalDiffusivity; if (obj.furnParameters.ContainsKey("thermal_diffusivity")) { thermalDiffusivity = obj.furnParameters["thermal_diffusivity"]; } World.current.temperature.SetThermalDiffusivity(tile.X, tile.Y, thermalDiffusivity); return(obj); }
private void InvokeContextMenuLuaAction(string luaFunction, Character character) { FurnitureActions.CallFunction(luaFunction, this, character); }