Short_Tools 1.0.11.3

dotnet add package Short_Tools --version 1.0.11.3
NuGet\Install-Package Short_Tools -Version 1.0.11.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Short_Tools" Version="1.0.11.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Short_Tools --version 1.0.11.3
#r "nuget: Short_Tools, 1.0.11.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Short_Tools as a Cake Addin
#addin nuget:?package=Short_Tools&version=1.0.11.3

// Install Short_Tools as a Cake Tool
#tool nuget:?package=Short_Tools&version=1.0.11.3

Here is a small tutorial on how to use some of the parts of this library.

The Renderer (V1.0.3):

To create a renderer, we first must create a subclass that inherits from the ShortRenderer class.

internal class Renderer : ShortRenderer
{
	public override void Render()
	{
		RenderClear(); // use at the start of the function to clear the screen
		
		// code will go here for drawing
		
		RenderDraw(); // applies Draw functions to the screen
	}
}

Now we can create an instance of this class, and set it up.

static void Main()
{
	bool Running = true;

	Renderer renderer = new Renderer();
	
	renderer.Load_Images
		(
			new Dictionary<string, string>()
			{
				{ "Background", "res\\background.png" },
				{ "image", "res\\random image.png" }
			}
		)

	renderer.Start();

	while (Running)
	{
		// your game/app code will go here
	}

	renderer.Stop();
}

This code will start up the renderer, load the images given to it, and then start rendering, but the draw function is currently empty, so all that will appear will be a purple screen, you can test this.

To change this we can now edit the Render function

public override void Render()
{
	RenderClear();
	
	Draw(0, 0, screenwidth, screenheight, "background");
	Draw(500, 500, 200, 200, "image");

	RenderDraw();
}

This code will draw the background fully covering the screen, and will then draw the image at "res\random image.png" at the coordinates given and the size given.

Setting up player inputs and closing of the game/app (V1.0.4).

The current code will never quit, and will not be able to be changed by the user, to fix this we can use the ShortHandler. To start the process, we will do that same thing as with the renderer, and create a subclass.

internal class Handler : ShortHandler
{
    public override void Handle(string inp, bool down)
    {
        switch (inp)
		{
			case ("a"):
				// do something
				break;
			
			case ("d"):
				// do something else
				break;
		}
    }
}

Then, we can create an instance and run it in the game/app loop.

Renderer renderer = new Renderer();
Handler handler = new Handler();

...

while (Running)
{
	handler.HandleInputs(ref Running);
	
	// your game/app code
}

renderer.Stop();

This will now allow quitting, but to make the "a" and "d" keys do something, we will make a public static variable.

internal class Program
{
	public static double angle { get; set; } = 0d; // sets up the angle and initiates a value
	
	static void Main()
	{
	...
	}
	...
}

Then we can edit the handle code to change angle on button press

internal class Handler : ShortHandler
{
    public override void Handle(string inp, bool down)
    {
        switch (inp)
		{
			case ("a"):
				Program.angle--;
				break;
			
			case ("d"):
				Program.angle++;
				break;
		}
    }
}

Now finally, we can apply this angle to the image drawn to screen in the Render function from the renderer.

public override void Render()
{
    RenderClear();
    
    Draw(0, 0, screenwidth, screenheight, "background");
    Draw(500, 500, 200, 200, "image", Program.angle);

    RenderDraw();
}

This will now draw the background, then the image given ontop of that and you can rotate that image via "a" and "d".

Adding buttons to make images appear and dissapear (V1.0.5).

To change the state of a drawing, we will need to make another static variable.

internal class Program
{
	public static double angle { get; set; } = 0d;
	public static bool drawImage { get; set; } = true;
	
	static void Main()
	{
	...
	}
	...
}

To add buttons, we need to create a new button and add it to the handlers list of buttons.

Renderer renderer = new Renderer();
Handler handler = new Handler();

...

ShortButton button = new(500, 500, 200, 200);  // same coordinates as the image that i am drawing, rotating buttons will be added in a later update.
handler.AddButton(ref button);

while (Running)
{
	handler.HandleInputs(ref Running);
	
	if (button.pressed)
	{
		button.pressed = false;
		if (drawImage == true) { drawImage = false; }
		else { drawImage = true; }
	}
	
	// your game/app code
}

renderer.Stop();

Then we just have to change the rendering code.

public override void Render()
{
    RenderClear();
    
    Draw(0, 0, screenwidth, screenheight, "background");
	if (Program.drawImage)
	{
		Draw(500, 500, 200, 200, "image", Program.angle);
	}

    RenderDraw();
}

Now you have a renderer, an input handler, and an image that dissapears and reappears if you click it.

You can also make Sockets easily in (V1.0.6)

Here we will do some simple code to pass hello world between a client and a server.

Client code:

// using static Short_Tools.Sockets; 

static void Main()
{
	ShortListener listener = new ShortListener("127.0.0.1", 1234);
    listener.SendMessage("Hello Server!");
    Console.WriteLine("XX " + listener.GetMessage());
}

Server code:

// using static Short_Tools.Sockets;



public class Manager : ShortSocketHandler
{
	public Manager() : base(1234, 10) {}
	
	public override bool ValidateClient(Socket socket)
	{
		return true; // no validation required for this.
	}s
}

...

static void Main()
{
	Manager manager = new Manager();
	
	bool Running = true;
	
	while (Running)
	{
		if (manager.NewConnection())
		{
			Console.WriteLine("\nNew Connection:");
			Socket newPerson = manager.GetClient();
			ShortListener listener = new ShortListener(newPerson);
			string message = listener.GetMessage();
			
			Console.WriteLine("CC " + message);
			listener.SendMessage("Hello Client!");
			
			listener.Stop();				
		}
	}
}

This code will allow the server to host multiple clients, and each one will send a message of "Hello Server" and recieve a reply of "Hello Client" before having their connection terminated.

V1.0.9: Animations Added

To make an animation, have a player class which you render like

public class Player
{
    public Vector2 pos;
    public Player(Vector2 pos)
    {
        this.pos = pos; 
    }
}

And draw that in your renderer, then you can add an animation in your main function

renderer.AddAnimation(new Renderer.Animation(player.pos, new Vector2() { X = 1000, Y = 500 }, ref player.pos, 0.1f, Renderer.Animation.Flags.Linear));

And the player will move to the point (1000, 500) with a speed of 0.1

Flags:

    Object     |       Name         |         Description         |         Version Added    
---------------|--------------------|-----------------------------|-------------------------------
               |                    |  Automatically calls the    |                               
 ShortRenderer |  Auto_Draw_Clear   |  RenderClear() function     |            V1.0.8 
               |                    |  before renderering and the |                             
               |                    |  RenderDraw() function after|                        
---------------|--------------------|-----------------------------|-------------------------------
               |                    |                             |
 ShortRenderer |       Debug        |  Displays nothing for now   |            V1.0.8
               |                    |                             |
---------------|--------------------|-----------------------------|-------------------------------
               |                    |  Displays what inputs have  |
 ShortHandler  |       Debug        |  been registered in the     |            V1.0.8
               |                    |  Console                    |
---------------|--------------------|-----------------------------|-------------------------------
               |                    |                             |
 ShortListener |       Debug        |   Displays nothing for now  |	           V1.0.8
               |                    |                             |
---------------|--------------------|-----------------------------|-------------------------------
               |                    |                             |
 ShortSocket-  |       Debug        |   Displays nothing for now  |	           V1.0.8
   Handler     |                    |                             |
---------------|--------------------|-----------------------------|-------------------------------
               |                    | Changes the movement curve  | 
 ShortRenderer.|Linear, Exponential,| of the animation, interact- |            V1.0.9
  Animation    |    Root, Sigmoid   | ive graph @ https://www.desm|
               |                    | os.com/calculator/kpldcor3nt|

If you find any issues or have any questions, feel free to email me at matthew.short.nh@gmail.com.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.11.3 47 5/3/2024
1.0.11.2 47 5/3/2024
1.0.11.1 40 5/2/2024
1.0.11 42 5/2/2024
1.0.10 98 4/8/2024
1.0.9 98 3/27/2024
1.0.8.1 113 3/20/2024
1.0.8 103 3/20/2024
1.0.7 98 2/21/2024
1.0.6 98 2/1/2024
1.0.5 87 1/30/2024
1.0.4 80 1/29/2024
1.0.3 80 1/28/2024
1.0.2 66 1/28/2024
1.0.1 67 1/26/2024
1.0.0 67 1/25/2024