private void SetupAnimations() { if (Animate) { foreach (var animator in part.FindModelAnimators("workshop_emissive")) { _heatAnimation = animator["workshop_emissive"]; if (_heatAnimation != null) { _heatAnimation.speed = 0; _heatAnimation.enabled = true; _heatAnimation.wrapMode = WrapMode.ClampForever; animator.Blend("workshop_emissive"); break; } WorkshopUtils.LogError("Unable to load workshop_emissive animation"); } foreach (var animator in part.FindModelAnimators(WorkAnimationName)) { _workAnimation = animator[WorkAnimationName]; if (_workAnimation != null) { _workAnimation.speed = 0; _workAnimation.enabled = true; _workAnimation.wrapMode = WrapMode.ClampForever; animator.Blend(WorkAnimationName); break; } WorkshopUtils.LogError("Unable to load work animation"); } } }
private void LoadAvailableParts() { WorkshopUtils.LogVerbose(PartLoader.LoadedPartsList.Count + " loaded parts"); WorkshopUtils.LogVerbose(PartLoader.LoadedPartsList.Count(WorkshopUtils.PartResearched) + " unlocked parts"); var items = new List <WorkshopItem>(); foreach (var loadedPart in PartLoader.LoadedPartsList.Where(p => p.name != "flag" && !p.name.StartsWith("kerbalEVA"))) { try { if (IsValid(loadedPart)) { items.Add(new WorkshopItem(loadedPart)); } } catch (Exception ex) { WorkshopUtils.LogError("Part " + loadedPart.name + " could not be added to available parts list", ex); } } _availableItems = items.OrderBy(i => i.Part.title).ToArray(); if (string.IsNullOrEmpty(_searchFilter.FilterText)) { _filteredItems = _filters[_activeFilterId].Filter(_availableItems, 0); } else { _filteredItems = _searchFilter.Filter(_availableItems, 0); } }
public double GetDeltaTime() { try { if (Time.timeSinceLevelLoad < 1.0f || !FlightGlobals.ready) { return(0); } if (Math.Abs(_lastUpdateTime) < 0.000000001d) { // Just started running _lastUpdateTime = Planetarium.GetUniversalTime(); return(0); } var deltaTime = Math.Min(Planetarium.GetUniversalTime() - _lastUpdateTime, 86400); _lastUpdateTime += deltaTime; return(deltaTime); } catch (Exception e) { WorkshopUtils.LogError("OseClock_GetDeltaTime - ", e); return(0); } }
private void SubCategories() { var icon = PartCategorizer.Instance.iconLoader.GetIcon(IconName); var filter = PartCategorizer.Instance.filters.Find(f => f.button.categorydisplayName == CategoryButtonLocalizationId); if (filter == null) { WorkshopUtils.LogError($"Cannot find 'Filter by function' button for category: {SubCategoryTitle}"); return; } PartCategorizer.AddCustomSubcategoryFilter(filter, SubCategoryTitle, SubCategoryTitle, icon, p => AvPartItems.Contains(p.name)); }
public override void OnAwake() { base.OnAwake(); try { IsKISAvailable = KISWrapper.Initialize(); } catch (Exception ex) { IsKISAvailable = false; WorkshopUtils.LogError("Error while checking for KIS. Workshop will be disabled", ex); } }
public override void OnUpdate() { try { UpdateProductivity(); ApplyPaging(); ProcessItem(); } catch (Exception ex) { WorkshopUtils.LogError("OseModuleWorkshop_OnUpdate", ex); } base.OnUpdate(); }
public void FixedUpdate() { if (!HighLogic.LoadedSceneIsFlight) { return; } try { UpdateProductivity(); ApplyFilter(); updateKACAlarm(); if (lastUpdateTime == 0) { lastUpdateTime = Planetarium.GetUniversalTime(); ProcessItem(TimeWarp.deltaTime); return; } //Get elapsed time double elapsedTime = Planetarium.GetUniversalTime() - lastUpdateTime; //Update last update time lastUpdateTime = Planetarium.GetUniversalTime(); //If our elapsed time is > the background process interval, then we'll need to do some multiple processings. double timeRemaining = 0; while (elapsedTime > kBackgroundProcessInterval) { timeRemaining = ProcessItem(kBackgroundProcessInterval); elapsedTime += timeRemaining; elapsedTime -= kBackgroundProcessInterval; } //Process the remaining delta time if (elapsedTime > 0f) { ProcessItem(elapsedTime); } } catch (Exception ex) { WorkshopUtils.LogError("OseModuleWorkshop_OnUpdate", ex); } }
private void LoadMaxVolume() { try { var inventories = KISWrapper.GetInventories(vessel); if (inventories.Count == 0) { WorkshopUtils.LogError("No Inventories found on this vessel!"); } else { WorkshopUtils.Log(inventories.Count + " inventories found on this vessel!"); _maxVolume = inventories.Max(i => i.maxVolume); } } catch (Exception ex) { WorkshopUtils.LogError("Error while determing maximum volume of available inventories!", ex); } WorkshopUtils.Log($"Max volume is: {_maxVolume} liters"); }
public void FixedUpdate() { if (!HighLogic.LoadedSceneIsFlight) { return; } maxGeeForce = Math.Max(maxGeeForce, FlightGlobals.ActiveVessel.geeForce); if (_showGui) { Events["ContextMenuOpenWorkbench"].guiName = "Close OSE Workbench"; } else { Events["ContextMenuOpenWorkbench"].guiName = "Open OSE Workbench"; } if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().requireUnpacking || WorkshopUtils.PreLaunch()) { if (wag != null) { if (!wag.packed && !wag.Packing) { Events["ContextMenuOpenWorkbench"].guiActive = true; // (_processedItem == null); } else { Events["ContextMenuOpenWorkbench"].guiActive = false; } } } if (wag != null) { wag.Busy = (_processedItem != null); } if (wag != null && wag.packed) { Status = "Packed"; } else { Status = "Online"; } try { UpdateProductivity(); ApplyFilter(); if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_Settings>().setPrintKAC) { updateKACAlarm(); } if (lastUpdateTime == 0) { lastUpdateTime = Planetarium.GetUniversalTime(); ProcessItem(TimeWarp.deltaTime); return; } //Get elapsed time double elapsedTime = Planetarium.GetUniversalTime() - lastUpdateTime; //Update last update time lastUpdateTime = Planetarium.GetUniversalTime(); //If our elapsed time is > the background process interval, then we'll need to do some multiple processings. double timeRemaining = 0; while (elapsedTime > 0.1f) //kBackgroundProcessInterval) { timeRemaining = ProcessItem(elapsedTime); if (_processedItem == null) { return; } if (elapsedTime == timeRemaining) { break; } elapsedTime = timeRemaining; //elapsedTime -= kBackgroundProcessInterval; } //Process the remaining delta time if (elapsedTime > 0f) { ProcessItem(elapsedTime); } } catch (Exception ex) { WorkshopUtils.LogError("OseModuleWorkshop_OnUpdate", ex); } }
private void LoadFilters() { var filters = new List <FilterBase>(); var filterTextures = new List <Texture>(); if (this.part.partInfo.partConfig == null) { return; } ConfigNode[] nodes = this.part.partInfo.partConfig.GetNodes("MODULE"); ConfigNode node = null; ConfigNode workshopNode = null; PartCategories category; //Get the nodes we're interested in for (int index = 0; index < nodes.Length; index++) { node = nodes[index]; if (node.HasValue("name")) { moduleName = node.GetValue("name"); if (moduleName == this.ClassName) { workshopNode = node; break; } } } if (workshopNode == null) { return; } //Each category represets one of the tab buttons from the KSP editor. //Mods have the ability to specify which categories that the workshop can produce. //If there are no CATEGORY nodes specified then the defaults are used instead. nodes = workshopNode.GetNodes("CATEGORY"); //If we have no category nodes then just load the defaults. if (nodes.Length == 0) { //Pods filters.Add(new FilterCategory(PartCategories.Pods)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/RDicon_commandmodules")); //FuelTank filters.Add(new FilterCategory(PartCategories.FuelTank)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/RDicon_fuelSystems-advanced")); //Engine filters.Add(new FilterCategory(PartCategories.Engine)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/RDicon_propulsionSystems")); //Control filters.Add(new FilterCategory(PartCategories.Control)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_largecontrol")); //Structural filters.Add(new FilterCategory(PartCategories.Structural)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_generalconstruction")); //Aero filters.Add(new FilterCategory(PartCategories.Aero)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advaerodynamics")); //Utility filters.Add(new FilterCategory(PartCategories.Utility)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_generic")); //Electrical filters.Add(new FilterCategory(PartCategories.Electrical)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_electrics")); //Ground filters.Add(new FilterCategory(PartCategories.Ground)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advancedmotors")); //Payload filters.Add(new FilterCategory(PartCategories.Payload)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_composites")); //Communications filters.Add(new FilterCategory(PartCategories.Communication)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advunmanned")); //Coupling filters.Add(new FilterCategory(PartCategories.Coupling)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/cs_size3")); //Thermal filters.Add(new FilterCategory(PartCategories.Thermal)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/fuels_monopropellant")); //Science filters.Add(new FilterCategory(PartCategories.Science)); filterTextures.Add(WorkshopUtils.LoadTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advsciencetech")); if (HighLogic.CurrentGame.Parameters.CustomParams <Workshop_MiscSettings>().showMiscCategory) { //Misc (catchall for parts not in other categories) filters.Add(new FilterCategory(PartCategories.none)); filterTextures.Add(WorkshopUtils.LoadTexture("Workshop/Assets/Icons/Misc")); } } else //Load all the specified CATEGORY nodes. { //Load the categories for (int index = 0; index < nodes.Length; index++) { node = nodes[index]; if (!node.HasValue("name") && !node.HasValue("iconPath")) { continue; } try { category = (PartCategories)Enum.Parse(typeof(PartCategories), node.GetValue("name")); filters.Add(new FilterCategory(category)); filterTextures.Add(WorkshopUtils.LoadTexture(node.GetValue("iconPath"))); } catch (Exception ex) { WorkshopUtils.LogError("Error during LoadFilters: " + ex.ToString()); continue; } } } _filters = filters.ToArray(); _filterTextures = filterTextures.ToArray(); _searchFilter = new FilterSearch(); }