Skip to content

Commit

Permalink
Merge pull request #130 from SpaceWarpDev/experimental-bepinex-library
Browse files Browse the repository at this point in the history
v0.4.0 Release | Experimental BepInEx library ➡️ Main
  • Loading branch information
cheese3660 authored Mar 5, 2023
2 parents 3171188 + b6e9405 commit 8447261
Show file tree
Hide file tree
Showing 111 changed files with 10,691 additions and 3,799 deletions.
Binary file removed Bundles/swconsoleui.bundle
Binary file not shown.
47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Contributing to Space Warp

Thank you for your interest in contributing to Space Warp! This document outlines the guidelines for contributing to this project.

## Getting Started

To get started, you will need to have [Git](https://git-scm.com/) and a legit copy of [Kerbal Space Program 2](https://www.kerbalspaceprogram.com/games-kerbal-space-program-2) installed on your machine. You will also need to have a GitHub account.

## Contributing to Issues

We welcome contributions from the community to help us improve Space Warp. You can contribute by submitting bug reports, feature requests, or code changes.

### Issue Tracker

All contributions to Space Warp are tracked on the [GitHub issue tracker](https://github.com/SpaceWarpDev/SpaceWarp/issues). Before you start working on a feature or issue, please check the issue tracker to make sure that it has not already been reported.

### Reporting Bugs

If you encounter a bug while using Space Warp, please report it on the issue tracker. When submitting a bug report, please include as much information as possible, including the steps to reproduce the bug and any error messages that you received.

### Feature Requests

If you have an idea for a new feature or improvement to Space Warp, please submit it on the issue tracker. We encourage you to discuss your idea with the community before submitting a feature request.

### Contributing Code

If you would like to contribute code to Space Warp, please follow these guidelines:

1. Create a fork of the Space Warp repository.
2. Clone your fork onto your local machine.
3. Create a new branch for your changes.
4. Make your changes on the new branch.
5. Test your changes to make sure they work as expected.
6. Commit your changes and push them to your fork.
7. Create a pull request on the main Space Warp repository.

### Good First Issues

We mark some issues as "good first issue" to help new contributors get started with the project. These issues are usually relatively simple and don't require a lot of experience with the project.

## Code of Conduct

We expect all contributors to follow our [Code of Conduct](CODE_OF_CONDUCT.md). Please review this document before contributing to Space Warp.

## License

Space Warp is licensed under the [MIT License](LICENSE). By contributing to this project, you agree to license your contributions under the same license.
1 change: 0 additions & 1 deletion Doorstop/.doorstop_version

This file was deleted.

45 changes: 0 additions & 45 deletions Doorstop/doorstop_config.ini

This file was deleted.

Binary file removed Doorstop/winhttp.dll
Binary file not shown.
77 changes: 46 additions & 31 deletions ExampleMod/ExampleMod.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using SpaceWarp.API.Mods;
using SpaceWarp.API.AssetBundles;
using SpaceWarp.API;
using BepInEx;
using BepInEx.Logging;
using SpaceWarp.API.Mods;
using SpaceWarp.API.Assets;
using KSP.UI.Binding;
using KSP.Sim.impl;
using SpaceWarp;
using SpaceWarp.API.UI;
using SpaceWarp.API.UI.Appbar;
using UnityEngine;

namespace ExampleMod;

[MainMod]
public class ExampleMod : Mod
[BepInPlugin("com.SpaceWarpAuthorName.ExampleMod", "ExampleMod", "3.0.0")]
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
public class ExampleMod : BaseSpaceWarpPlugin
{
public GUISkin _spaceWarpUISkin;

private bool drawUI;
private Rect windowRect;
private bool loaded;

private static ExampleMod Instance { get; set; }

Expand All @@ -25,30 +28,22 @@ public class ExampleMod : Mod
public override void OnInitialized()
{
base.OnInitialized();

if (loaded)
{
Destroy(this);
}

loaded = true;
Instance = this;

// Example of using the logger, Were going to log a message to the console, ALT + C to open the console.
Logger.Info("Hello World, Im a spacewarp Mod.");
Logger.LogInfo("Hello World, Im a spacewarp Mod.");

// Example of using the asset loader, were going to load the SpaceWarp GUI skin.
// [FORMAT]: space_warp/[assetbundle_name]/[folder_in_assetbundle]/[file.type]
ResourceManager.TryGetAsset(
"space_warp/swconsoleui/swconsoleUI/spacewarpConsole.guiskin",
out _spaceWarpUISkin
);

// Register the mod's button on the SpaceWarp application bar.
SpaceWarpManager.RegisterAppButton(
// Register the mod's button in KSP 2s app.bar
// This requires an `icon.png` file to exist under [plugin_folder]/assets/images
Appbar.RegisterAppButton(
"Example Mod",
"BTN-ExampleMod",
SpaceWarpManager.LoadIcon(),
// Example of using the asset loader, were going to load the apps icon
// Path format [mod_id]/images/filename
// for bundles its [mod_id]/[bundle_name]/[path to file in bundle with out assets/bundle]/filename.extension
// There is also a try get asset function, that returns a bool on whether or not it could grab the asset
AssetManager.GetAsset<Texture2D>($"{SpaceWarpMetadata.ModID}/images/icon.png"),
ToggleButton
);
}
Expand All @@ -72,7 +67,7 @@ private void ToggleButton(bool toggle)
public void OnGUI()
{
// Set the GUI skin to the SpaceWarp GUI skin.
GUI.skin = _spaceWarpUISkin;
GUI.skin = Skins.ConsoleSkin;

if (drawUI)
{
Expand All @@ -96,30 +91,50 @@ private static void FillWindow(int windowID)
GUILayout.Label("Example Mod - Built with Space-Warp");
GUI.DragWindow(new Rect(0, 0, 10000, 500));
}

private float lastUpdateTime = 0.0f;
private float updateInterval = 1.0f;

/// <summary>
/// Runs every frame and performs various tasks based on the game state.
/// </summary>
private void LateUpdate()
{
// Now lets play with some Game objects
if (Instance.Game.GlobalGameState.GetState() == KSP.Game.GameState.MainMenu)
// Check if the specified interval has elapsed
if (Time.time - lastUpdateTime >= updateInterval)
{
KSP.Audio.KSPAudioEventManager.SetMasterVolume(Mathf.Sin(Time.time) * 100);
// Update the last update time to the current time
lastUpdateTime = Time.time;

// Now lets play with some Game objects
if (Game.GlobalGameState.GetState() == KSP.Game.GameState.MainMenu)
{
Logger.Log(LogLevel.None, "This is log level none");
Logger.Log(LogLevel.Debug, "This is log level debug");
Logger.Log(LogLevel.Info, "This is log level info");
Logger.Log(LogLevel.Warning, "This is log level warning");
Logger.Log(LogLevel.Error, "This is log level error");
Logger.Log(LogLevel.Fatal, "This is log level fatal");
Logger.Log(LogLevel.Message, "This is log level message");
Logger.Log(LogLevel.All, "This is log level all");

KSP.Audio.KSPAudioEventManager.SetMasterVolume(Mathf.Sin(Time.time) * 100);
}
}
else if (Instance.Game.GlobalGameState.GetState() == KSP.Game.GameState.FlightView)
else if (Game.GlobalGameState.GetState() == KSP.Game.GameState.FlightView)
{
// Getting the active vessel, staging it over and over and printing out all the parts.
VesselComponent _activeVessel = Instance.Game.ViewController.GetActiveSimVessel();
VesselComponent _activeVessel = Game.ViewController.GetActiveSimVessel();

if (_activeVessel != null)
{
_activeVessel.ActivateNextStage();
Logger.Warn("Stagin Active Vessel: " + _activeVessel.Name);
Logger.LogWarning("Stagin Active Vessel: " + _activeVessel.Name);
VesselBehavior behavior = Game.ViewController.GetBehaviorIfLoaded(_activeVessel);
foreach (PartBehavior pb in behavior.parts)
{
Logger.Warn(pb.name);
Logger.LogWarning(pb.name);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions ExampleMod/ExampleMod.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net472</TargetFramework>
<LangVersion>11</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SpaceWarp\SpaceWarp.csproj" />
<PackageReference Include="UnityEngine.Modules" Version="2020.3.33" />
<Reference Include="Assembly-CSharp">
<HintPath>..\external_dlls\Assembly-CSharp.dll</HintPath>
<Publicize>true</Publicize>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SpaceWarp\SpaceWarp.csproj" Private="false" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="UnityEngine.Modules" Version="2020.3.33" />
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.0" PrivateAssets="all" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions ExampleMod/modInfo.json → ExampleMod/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"author": "Space-Warp Team",
"description": "A Example Mod for Space-Warp",
"source": "https://github.com/SpaceWarpDev/SpaceWarp/tree/main/ExampleMod",
"version": "v0.3.0",
"version": "0.4.0",
"dependencies": [],
"ksp2_version": {
"min": "0",
"max": "1"
}
}
}
Loading

0 comments on commit 8447261

Please sign in to comment.