Jump to content

Paint API


liverare

Recommended Posts

Bob Ross would be so proud!

Example code:

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.List;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import com.liverare.api.PaintAPI;

@ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0)
public class Test extends Script {

	PaintAPI paint;

	Area safeSpace;
	List<NPC> guards;

	@Override
	public void onStart() throws InterruptedException {
		paint = new PaintAPI();
		paint.exchangeContext(bot);
		
		safeSpace = myPlayer().getArea(5);
	}

	@Override
	public int onLoop() throws InterruptedException {
		
		guards = npcs.filter(Test::isGuard);
		
		return 100;
	}

	private static boolean isGuard(NPC npc) {
		return npc.getName().equals("Guard");
	}

	@Override
	public void onPaint(Graphics2D g) {
		
		g.setColor(Color.BLACK);
		g.setBackground(Color.PINK);
		
		// dont worry bout checks fam, i do dat
		paint.drawMinimapArea(g, safeSpace);
		paint.drawEntities(g, guards, Test::guardToString, true, false, false, false, false, false, true);
	}
	
	private static String guardToString(NPC npc) {
		return "Health: " + npc.getHealthPercent() + ", xyz: " + npc.getPosition().toString();
	}
}

mDSjady.png

Functions:

public void drawLink(Graphics2D g, Entity entity1, Entity entity2)
public void drawMinimapArea(Graphics2D g, org.osbot.rs07.api.map.Area area)
public <T extends Position> void drawString(Graphics2D g, Function<T, String> toString, T position)
public void drawString(Graphics2D g, String aString, Position position)
public void drawString(Graphics2D g, String aString, Entity entity)
public void drawEntity(Graphics2D g, Entity entity, String aString, boolean labelTile, boolean click, boolean cube, boolean minimap, boolean tile, boolean box, boolean wireframe)
public void drawEntity(Graphics2D g, Entity entity, Function<T, String> getDescription, boolean labelTile, boolean click, boolean cube, boolean minimap, boolean tile, boolean box, boolean wireframe)
public <T extends Entity> void drawEntities(Graphics2D g, Collection<T> entities, Function<T, String> getDescription, boolean labelTile, boolean click, boolean cube, boolean minimap, boolean tile, boolean tileCube, boolean wireframe)
private void drawBox(Graphics2D g, Entity entity)
private void drawBox(Graphics2D g, Position bottomTile, Position topTile)
private void drawWireframe(Graphics2D g, Entity entity)
private void drawClickBounds(Graphics2D g, Entity entity)
private void drawCube(Graphics2D g, Entity entity)
public void drawMinimapPoint(Graphics2D g, Vector3D v)
public void drawMinimapLink(Graphics2D g, Vector3D a, Vector3D b)
public void drawTile(Graphics2D g, Entity entity)
public void drawTile(Graphics2D g, Position position)
public static void drawPoint(Graphics2D g, Point point, int size)
public static void drawPoint(Graphics2D g, int x, int y, int size)
public static void drawShape(Graphics2D g, Shape shape)
public static void drawString(Graphics2D g, String aString, int x, int y)
public static void drawString(Graphics2D g, String aString, Point point)
public static void drawString(Graphics2D g, String aString, Rectangle rectangle)

Source:

  Reveal hidden contents
Edited by liverare
pesky little function apparently didn't want commenting :(
  • Like 11
Link to comment
Share on other sites

  On 9/23/2017 at 11:59 PM, TheWind said:

My question is why did @Alek depreciate the method exchangeContext(Bot bot)?

Expand  

Deprecated for internal use only. Building APIs is more of a developer's job than it is a scripters, so it's likely deprecated just to ward of those who don't know what they're doing. :)

Link to comment
Share on other sites

  On 9/24/2017 at 8:54 AM, liverare said:

Deprecated for internal use only. Building APIs is more of a developer's job than it is a scripters, so it's likely deprecated just to ward of those who don't know what they're doing. :)

Expand  

I guess that means me :(, but I really do want to learn. I have a few questions:

1) Why did you extend the class API instead of MethodProvider and not use the initializeModule() method?

2) Why even call the method exchangeContext(getBot()) when the class you made would work without it? I guess I'm not really understanding what it does unless it's doing something behind the scenes which may be harder to understand unless you know how the bot itself works...

Link to comment
Share on other sites

  On 9/26/2017 at 3:00 AM, TheWind said:

I guess that means me :(, but I really do want to learn. I have a few questions:

1) Why did you extend the class API instead of MethodProvider and not use the initializeModule() method?

2) Why even call the method exchangeContext(getBot()) when the class you made would work without it? I guess I'm not really understanding what it does unless it's doing something behind the scenes which may be harder to understand unless you know how the bot itself works...

Expand  
  1. Semantics. I wrote and released an API, not a MethodProvider. The initializeModule function doesn't need to be used, but I've used it in my other APIs. For instance, in my hunting API, I use it to reset values and variables, but also to find some other entities, so that I can completely reset the hunt each time I finish one.
  2. exchangeContext is required to be called, so the MethodProvider can capture an instance of your bot and work in relation to it. If you look at the methods I listed and look for the ones that don't contain "static" in their deceleration, that's because, for one reason or another, it depends on having access to the bot instance. If I only had static variables then I wouldn't need to pass in the bot instance, but I'd still call it, if only because I've got OCD and instantiating a new API and not giving it the bot context would trigger me.
Edited by liverare
  • Like 1
Link to comment
Share on other sites

  On 9/26/2017 at 9:30 AM, liverare said:
  • Semantics. I wrote and released an API, not a MethodProvider. The initializeModule function doesn't need to be used, but I've used it in my other APIs. For instance, in my hunting API, I use it to reset values and variables, but also to find some other entities, so that I can completely reset the hunt each time I finish one.
  • exchangeContext is required to be called, so the MethodProvider can capture an instance of your bot and work in relation to it. If you look at the methods I listed and look for the ones that don't contain "static" in their deceleration, that's because, for one reason or another, it depends on having access to the bot instance. If I only had static variables then I wouldn't need to pass in the bot instance, but I'd still call it, if only because I've got OCD and instantiating a new API and not giving it the bot context would trigger me.
Expand  
 

Thank you for answering with such detail. As for your answer to the second question, it really raises more questions as opposed to satisfying my curiosity, but I'll leave it with just those two questions for now.

  • Like 1
Link to comment
Share on other sites

I've made a minor change to the drawEntity function, because it would only render the entity on the minimap if it was also visible. Now it'll render it so long as it's on the minimap.

There's one thing I dislike and that's when something will render, but it'll be stretched to the top-left of the screen because it's partially visible, like a partially visible tile. That's down to some core OSBot functions. :/ I'll have to add in some checks to avoid rendering those later. :)

Edited by liverare
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...