setCurrentMap() switches to hidden map for players

The RPTools applications are written in Java. If you're interested in contributing to any project here by submitting patches to the source code, this is the forum to ask questions about how to do so. Please put the two-letter tool name abbreviation in your thread Title. To enter this group, go to the Usergroups page of your User Control Panel and join the Java Developer group.

Moderators: dorpond, trevor, Azhrei

Post Reply
User avatar
aku
Dragon
Posts: 856
Joined: Wed Nov 15, 2006 9:03 am
Contact:

setCurrentMap() switches to hidden map for players

Post by aku »

So, i was reading this thread, and thought it would possibly be withing my limited skills to at least take a look into, i sent the following pm to az, but appreciate how busy he is (especially compared to my unemployed self), seeking a little nudging in the right direction:
Subject: Bug (?): setCurrentMap() switches to hidden map for players

Ok, so I said i'd take a look, and see if i can solve this for you, since it seems like it should be "simple enough", and i know you dont have time for too much hand holding :D But i wanted to make sure that i wasnt aiming for the moon, and shooting for the sun, so to speak.

So far, I've found IsVisible() is set from maptool.model.zone,but thats the global function, and im still searching for where it's switched for the individual maps...

I'm almost certain that I need to be working in

Code: Select all

	@Override
	public Object childEvaluate(Parser parser, String functionName, List<Object> parameters) throws ParserException {
		if (functionName.equals("getCurrentMapName")) {
			return MapTool.getFrame().getCurrentZoneRenderer().getZone().getName();
		} else if (functionName.equals("setCurrentMap")) {
			if (parameters.isEmpty())
				throw new ParserException(I18N.getText("macro.function.general.notEnoughParam", functionName, 1, parameters.size()));
			String mapName = parameters.get(0).toString();
			for (ZoneRenderer zr : MapTool.getFrame().getZoneRenderers()) {
				if (mapName.equals(zr.getZone().getName())) {
					MapTool.getFrame().setCurrentZoneRenderer(zr);
					return mapName;
				} // endif
			} // endfor
so, if im going the right way, feel free to give me a nudge closer :D

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: setCurrentMap() switches to hidden map for players

Post by aliasmask »

Please don't make the condition to be isVisible. I see that more as a feature right now. I much rather have it be a protected function, so if ran from a lib token I could move a token to a map they wouldn't normally see. This is important since there is no macro way to turn map visibility on and off.

User avatar
aku
Dragon
Posts: 856
Joined: Wed Nov 15, 2006 9:03 am
Contact:

Re: setCurrentMap() switches to hidden map for players

Post by aku »

I'll look to see what it would take to add it to the protected functions then AM :) I aim to please, even if i dont know what the heck im firing :D

Edit: So I now have it is a trusted function, however, thats the ONLY way it's working ATM, which i dont think is WAI, because that changes the basically functionality of the macro, and is also counter to what can be done with a mouse.

More work ensues!

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: setCurrentMap() switches to hidden map for players

Post by Jagged »

I think it needs to be callable in any situation but it should only move to a hidden map if called as a trusted macro.

Which might be difficult to code ;)

User avatar
aku
Dragon
Posts: 856
Joined: Wed Nov 15, 2006 9:03 am
Contact:

Re: setCurrentMap() switches to hidden map for players

Post by aku »

Jagged wrote:I think it needs to be callable in any situation but it should only move to a hidden map if called as a trusted macro.

Which might be difficult to code ;)
Well, im hoping not too difficult, if i can take one thing offa Az's plate, im happy!

Anywheres, here's where I'm ad

Code: Select all

@Override
	public Object childEvaluate(Parser parser, String functionName, List<Object> parameters) throws ParserException {
		if (functionName.equals("getCurrentMapName")) {
			return MapTool.getFrame().getCurrentZoneRenderer().getZone().getName();
		} else if (functionName.equals("setCurrentMap")) {
			//Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
			if (!MapTool.getParser().isMacroTrusted()) {
				throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));
			}
			if (parameters.isEmpty())
				throw new ParserException(I18N.getText("macro.function.general.notEnoughParam", functionName, 1, parameters.size()));
			String mapName = parameters.get(0).toString();
			for (ZoneRenderer zr : MapTool.getFrame().getZoneRenderers()) {
				if (mapName.equals(zr.getZone().getName())) {
					MapTool.getFrame().setCurrentZoneRenderer(zr);
					return mapName;
				} // endif
			} // endfor
This works, with the obvious caveat that it needs to be a protected macro.

What i need to do, i think, is figure out where the map name is being passed from as an argument...

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: setCurrentMap() switches to hidden map for players

Post by jfrazierjr »

aku wrote:
Jagged wrote:I think it needs to be callable in any situation but it should only move to a hidden map if called as a trusted macro.

Which might be difficult to code ;)
Well, im hoping not too difficult, if i can take one thing offa Az's plate, im happy!

Anywheres, here's where I'm ad

Code: Select all

@Override
	public Object childEvaluate(Parser parser, String functionName, List<Object> parameters) throws ParserException {
		if (functionName.equals("getCurrentMapName")) {
			return MapTool.getFrame().getCurrentZoneRenderer().getZone().getName();
		} else if (functionName.equals("setCurrentMap")) {
			//Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
			if (!MapTool.getParser().isMacroTrusted()) {
				throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));
			}
			if (parameters.isEmpty())
				throw new ParserException(I18N.getText("macro.function.general.notEnoughParam", functionName, 1, parameters.size()));
			String mapName = parameters.get(0).toString();
			for (ZoneRenderer zr : MapTool.getFrame().getZoneRenderers()) {
				if (mapName.equals(zr.getZone().getName())) {
					MapTool.getFrame().setCurrentZoneRenderer(zr);
					return mapName;
				} // endif
			} // endfor
This works, with the obvious caveat that it needs to be a protected macro.

What i need to do, i think, is figure out where the map name is being passed from as an argument...

I am not seeing what I would expect, but from a brief look at the code it should be something as easy as:

check if there is a mapName passed
if NOT, throw exception
if so, get the zone AND zone renderer
check if the zone(or zonerenderer) is visible
if so, set that as the current zonerenderer
if NOT check if the macro is trusted
if so, set that as the current zonerenderer
if NOT, throw exception

so you need to move your "isMacroTrusted() check down into the for loop and that inner most if statement and also check for the isVisible to players also.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

Post Reply

Return to “Java Programming Info”