PBeM-Spiele
Aktuelle Zeit: 24.11.2020 23:43

Alle Zeiten sind UTC + 1 Stunde




Ein neues Thema erstellen Auf das Thema antworten  [ 33 Beiträge ]  Gehe zu Seite Vorherige  1, 2, 3  Nächste
Autor Nachricht
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 21.10.2020 13:48 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
That seems about right. getBuildingType.getMaintenance((EresseaConstants.I_USILVER).getAmount is a little more concise.
I tried this, but received EresseaConstants class or variable doesn't exist.

Yeeeeessssss! This seems like it will work very well for what I am trying to do.

Can you explain the benefits of the interface?
Code:
interface Interpreter {
   public void accept(String[] parameters);
}
class TestInterpreter implements Interpreter {
  public void accept(String[] parameters) {
     helper.addOrder(unit, "TestInt - " + parameters[0] + " - " + parameters[1]);
  }
}
This produces the same result
Code:
class TestInterpreter {
  public void accept(String[] parameters) {
     helper.addOrder(unit, "TestInt - " + parameters[0] + " - " + parameters[1]);
  }
}
This should work well. I might have stumbled onto this if I would have thought about using a HashMap before, which I should have :?

Now I am going to dive into lambda a little bit :D


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 21.10.2020 17:05 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
You must import magellan.library.gamebinding.EresseaConstants, of course.

The benefit of the Interface is precisely that you can put it into a map and work with different commands. If you don't know what "programming to an interface" means, you should probably look into that before caring about lambda expressions. You can live without them, in fact, Java has lived without them for literally decades.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 21.10.2020 17:35 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
You must import magellan.library.gamebinding.EresseaConstants, of course.
:oops: but it says getAmount() is invalid after importing Constants. It will return silver without getAmount(), but doesn't work with getAmount().

Zitat:
If you don't know what "programming to an interface" means, you should probably look into that before caring about lambda expressions.
I do not :oops: so I will shift gears into "programming to an interface" :thumbup:
I really appreciate you taking the time to provide me with all this information. I learn a lot faster with this kind of help compared to reading tons of forum posts :prost:


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 22.10.2020 00:22 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
You're most welcome. It's fun an nice to see that somebody is using this. And maybe some day you could become a Magellan developer yourself, so this also a bit selfish. By the way if you want to hang out at the Eressea Discord server, you could connect to some other Magellan users. Invitation link is on the Wiki page.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 23.10.2020 04:05 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
By the way if you want to hang out at the Eressea Discord server, you could connect to some other Magellan users.
Sounds like a good idea!

I think I have everything running pretty good now. I have something I am missing as its running through my code 2x that I have to find when I get more time. I had this happen before and forget how I fixed it :oops: Ugh! I had a second fake faction that I was testing the code on and it was calling the same command as the report faction since I never deleted the code in its unit.

2 new questions:

1. Is there a way to quickly get the previous turns default order? I was having trouble finding the ROUTE command until I realized I was putting it in the wrong place :oops: and got it working. I would still be curious if there was a built in way of getting the default order.

2. Can I directly call second() from inside first() without creating a new instance of Initialization? FOUND THE ANSWER: You cannot return from a void! Changed to public int[] after some googling :D

Look at that, I was kind of able to figure out the answers to my own questions for the most part :D other than if there is an easier way to get default order.
Code:
Map DICTfunctions = new HashMap();
DICTfunctions.put("initialization", new initialization());

interface Interpreter {
   public void first();
   // XXXXXXXXX public void second(Region region);
   public void run(Unit unit, List args);
}

public class initialization implements Interpreter {
   public void first() {
      // Do stuff here
      // XXXXXXXXX int[] VARdata = DICTfunctions.get("initialization").second(region); // unsure of this
      int[] VARdata = second(region);
      // Do more stuff here
   }
   // XXXXXXXXX public void second(Region region) {
   public int[] second(Region region) {
      int[] VARdata = new int[6];
      // add data to VARdata
      return VARdata;
   }
}


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 26.10.2020 00:04 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
Cool. I'm wondering if I misled you with the Interpreter interface. It might be thinking too complicated, depending on what you're doing in the rest of your code. Who is calling your first()? Does it make sense to add it to the Interpreter interface?

There is no way to get the default orders back. The orders are loaded from the report and if you change them, they're changed. There is also no easy way to access any of the previous turn's info if that's what you mean. Short of loading a different report from a file, which you could do, in theory.

_________________
--> Drachensgrab-Regeln

Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 26.10.2020 04:01 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
Who is calling your first()?
I just have any (1) unit that runs the entire script. This unit gets a message "; Runs Extended Commands Script" every turn so I don't forget which one it is :lol: There won't be any other units with individual commands. This may not be what was intended with Extended Commands, but when I am gathering information for each region I also loop through each units orders with getCompleteOrders(). I have commands similar to Template/Vorlage that are then read and stored in a List until I am ready to run all orders. While looping through the orders I grab anything with // and put them back in the units new orders so they are always there. I just prefer to be able to see the commands of every unit right in the orders instead of another window and this allows me to choose the order in which they are executed. I am also able to grab the default LONG order and store it in a Map should I need to grab it later which I only currently do for the ROUTE command during this loop.

I can run any teach commands first as the students don't have any code to say they are students. The students have any desired order they want. However, if any of the students listed in the teachers commands can be taught they will learn the appropriate skill and are then added to a Map that gets checked before any long order is performed to prevent them from performing another long order. Every potential student gets a "; message" each turn if they are listed in a teachers code whether they can be taught that turn or not so it is known they are being looked at for potential training. Then after that I run all the orders in the List that were gathered in the unit command loop. After that I do some overweight and long order double checks and then export data to an xml file for easier viewing.

I use the xml file in excel to make further plans for each region. If I can learn enough java I may try to make an addon to eliminate the need for excel :shock: but I am probably a long way from that :D

Zitat:
Does it make sense to add it to the Interpreter interface?
I have added multiple things to the Interpreter interface and have them working good (at least to the best of my knowledge). I still have a ton to learn on this subject as I haven't read a ton on the "Programming to an Interface", but I have done a fair amount of reading on it :D since you mentioned it to me.

Zitat:
There is no way to get the default orders back.
As mentioned above, I accomplish this when looping through the unit orders before they are removed. I do the same thing to determine any help silver sent/received, previous turn earnings/costs, etc... looping though unit/faction messages.

Since I only have one unit running the script, is it possible to skip/break cycling the rest of the individual units? Or, is it possible to skip running all individual units and just run the main library?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 26.10.2020 14:42 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
This is similar to what I am doing.

You can run an individual unit's script either with the Execute button in the editor or by right clicking it in the overview tree and selecting ExtCmds->run script (or something).

_________________
--> Drachensgrab-Regeln

Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 26.10.2020 23:49 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Solthar hat geschrieben:
This is similar to what I am doing.

You can run an individual unit's script either with the Execute button in the editor or by right clicking it in the overview tree and selecting ExtCmds->run script (or something).
I have had a lot of :oops: moments LoL! I have seen that Execute button in the Extended Commands window since I started this project.

Will this work without using a unit to call the first() method? I tried a couple things and it doesn't appear to as it looks like it tries to run through all units if you execute from the library.
I got it to work without needing to put any commands on a unit! Much easier this way.

I can't seem to get MovementEvaluator to work. I keep getting errors with anything I try.
Code:
import magellan.library.gamebinding.MovementEvaluator;

addMessage(unit, "" + MovementEvaluator.getWeight(unit));
addMessage(unit, "" + MovementEvaluator.getPayloadOnFoot(unit));
addMessage(unit, "" + MovementEvaluator.getPayloadOnHorse(unit));
Token Parsing Error: Lexical error at line 1445, column 130. Encountered: "\u200b" (8203), after : ""

Code:
import magellan.library.gamebinding.MovementEvaluator;

int lbs1 = MovementEvaluator.getPayloadOnFoot(unit);
int lbs2 = MovementEvaluator.getPayloadOnHorse(unit);
Typed variable declaration : Cannot reach instance method: getPayloadOnHorse( magellan.library.Unit ) from static context: magellan.library.gamebinding.MovementEvaluator : at Line: 1446


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 28.10.2020 02:24 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
The payload methods are not static methods, meaning you need an instance, not just the class to call them. A way of doing this is world.getRules().getGameSpecificStuff().getMovementEvaluator().getPayloadOnFoot(unit).

The \u200b error is weird (google it). Looks like you somehow got a weird character into your code.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 28.10.2020 04:25 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Easy fix:
Code:
MovementEvaluator MoveEval = world.getRules().getGameSpecificStuff().getMovementEvaluator();
Zitat:
The \u200b error is weird (google it). Looks like you somehow got a weird character into your code.
I had this happen before and when I paste my code into a different editor I can see a unknow character. Deleted it and it works now. I think this happens when I copy and paste code for some reason.

Now lets have some fun :lol: (This could get messy so feel free to say NO as I am sure it will lead me to a ton more questions!)

1. How do I go about creating another window? I am assuming I am now talking about creating a plugin. I want to be able to undock it just like the others. I am thinking of trying to eliminate the need for exporting data to excel and just doing it in another Magellan window.

2. Is it possible to be able to have a button in my new window that will Execute the Extended Commands Library when clicked?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 28.10.2020 11:28 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
Well ... you can do it, but I would not recommend it for what you intend to do. You would probably want to extend JDialog and setup your UI within. But that's not what ExtCmds was intended to do. I think you really would want to create an actual plugin. Get Eclipse, get the magellan sources and the plugins, and develop an actual plugin. It's not that much more complicated and you can profit from all the benefits of an IDE. It's a bit of a learning curve, but much more fun.

Executing your scripts from within a script ... I will not say it is impossible, but I wouldn't recommend it.

_________________
--> Drachensgrab-Regeln

Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 28.10.2020 17:30 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
I think you really would want to create an actual plugin
That is what I was guessing, hopefully I won't scare you away with a ton more questions!
Zitat:
Get Eclipse, get the magellan sources and the plugins
Done! I am assuming I just wanted the Eclipse IDE for Java Developers version.
Zitat:
It's a bit of a learning curve, but much more fun.
You say that now :lol: Remember, I have no REAL experience doing any kind of coding, especially Java! I just play with code till I can make some sense of it as I enjoy learning it. I am sure my code is extremely "dirty"!

Do you have any recommendations for the best information to learn how to use eclipse? I have never created projects before. Always just wrote scripts like I have done for Extended Commands to grab and/or manipulate data. I added Magellan2 and plugins to a project (found the PluginTemplate).

Zitat:
Executing your scripts from within a script ... I will not say it is impossible, but I wouldn't recommend it.
Just in case I explained that wrong...my script for Extended Commands would still be in the Library. Basically, I just want a button in my plugin that would tell Extended Commands to Execute the Library. If its still not recommended I will skip that idea.

I was just playing around and even if I try to compile the plugin sources that are already done I get an error:
1495: error: method loadElements in class RegionShapeCellRenderer.GeomRendererAdapter.ModePanel cannot be applied to given types

It throws this error on any plugin source code I try to compile...any of the standard plugins!

Until I figure that error out I am able to put a plugin directly in Magellan and compile to play with it.

UPDATE 10-30-2020 I still get the error when trying to compile, but I have been putting the plugin directly in Magellan and playing around. I have actually made some real progress in the JPanel design. Learned a lot on that and got a rough start to what I want to do.

How do listeners work? Basically I currently have a JComboBox that is populated with all the regions in the report. What I would like to figure out is how to make the combobox update to the current region anytime a region on the map or the overview is clicked. Then I want the data in the plugin window to update its data to match the newly clicked region by seeing the combobox change. I am thinking it will automatically change all the data if I set everything according to the Region in the combobox since I have it stored as a Region type.

Also, it would be nice if I could make it go the other way as well. When a region is chosen in the combobox, the active region in Magellan would update to match the combobox.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 31.10.2020 10:11 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 378
Wohnort: Karlsruhe
There are good tutorials that explain the basics of Eclipse. As for Magellan-specific tips, it has been a while since I have gone through the basics. I'm not sure what the problem with the plugins is. I think the best way is to import not the magellan2-extensions-plugins project, but every plugin as its own java project. For example MemoryWatchPlugin or YourPlugin. Then you have to tell the plugin project where to find the Magellan sources, by going to the project properties -> Java Build Path -> Projects and adding the Magellan2 project there. When I have time, I will try to go through the process myself and describe it in more detail. For now, you should be fine with the plugin in the Magellan project itself.

As a note: I strongly recommend to use git to manage and archive your own progress while developing. Maybe more on that later.

For adding a listener you have to implement the magellan.client.event.SelectionListener interface, then add you listener by calling client.getDispatcher().addSelectionListener(myListener). See the ExtendedCommandsPlugin for an example, or any class that implements SelectionListener*. You have to implement the selectionChanged method and have it update your combobox if a region is selected. There are different types of SelectionEvents (unit selections, single and multiple region selections ...) and you don't want to react to them all.

For the opposite way, you probably already have added an ActionListener to your combobox? If not, read any java tutorial on combobox or Actionlisteners. Then all you need to do in your actionPerformed method is to call dispatcher.fire(SelectionEvent.create(this, region)). dispatcher is again the EventDispatcher (client.getDispatcher()). See the FindDialog, ArmyStatsDialog or possibly the BookmarkManager classes for examples.



* by selecting SelectionListener, for example in the editor and calling the Type Hierarchy by pressing F4 you can see all the classes that implement SelectionListener.

_________________
--> Drachensgrab-Regeln

Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 01.11.2020 18:33 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
I think the best way is to import not the magellan2-extensions-plugins project, but every plugin as its own java project. For example MemoryWatchPlugin or YourPlugin. Then you have to tell the plugin project where to find the Magellan sources, by going to the project properties -> Java Build Path -> Projects and adding the Magellan2 project there. When I have time, I will try to go through the process myself and describe it in more detail. For now, you should be fine with the plugin in the Magellan project itself.
I had tried both ways. First tried the whole addon package and then each addon individually. I receive the following error:

[javac] eclipseWorspace\Magellan Source Code\magellan2\src-client\magellan\client\swing\map\RegionShapeCellRenderer.java:1495: error: method loadElements in class RegionShapeCellRenderer.GeomRendererAdapter.ModePanel cannot be applied to given types;
[javac] loadElements(politicsMode ? factionColors : regionColors);
[javac] ^
[javac] required: Map<T,Color>
[javac] found: politicsMo[...]olors
[javac] reason: inference variable T has incompatible equality constraints StringID,String
[javac] where T is a type-variable:
[javac] T extends Object declared in method <T>loadElements(Map<T,Color>)
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error

It appears the Build Path is setup correctly from what I can tell. I am running the "build.installer.xml" in eclipse for each individual plugin.
Zitat:
As a note: I strongly recommend to use git to manage and archive your own progress while developing. Maybe more on that later.
I used git a little before, but need to better familiarize myself with it when I have time.
Zitat:
For adding a listener you have to implement the magellan.client.event.SelectionListener interface
I started with using the teacher plugin as my template. I have been adding and deleting code to better understand. I have successfully created my GUI (JPanel) with some information on it to test. I somehow figured out how to send my JComboBox (Region) to the client fairly quickly to my surprise. It took me much, much longer to send the client Active Region to my JComboBox. I actually spent way too much time to get the "client" info. I think I pretty much found it by mistake! :lol: Once I discovered that Magellan plugins calls init() which allows me to get the client I made progress. The teacher plugin base I am using didn't send client to the GUI so I was able to change that and then finally was able to send the active region to my JComboBox :D I tried going off the getSelectionType() without success as it was always returning 0. I am not sure if this is the best way, but I ended up using the following code:
Code:
public void selectionChanged(SelectionEvent se) {
    Region region = (Region) rBox.getSelectedItem();
    if (!data.getActiveRegion().equals(region)) {
      region = data.getActiveRegion();
      rBox.setSelectedItem(region);
      setActiveRegion(region);
    }
  }
Zitat:
* by selecting SelectionListener, for example in the editor and calling the Type Hierarchy by pressing F4 you can see all the classes that implement SelectionListener.
This was VERY VERY helpful :D You have no idea how much easier this whole project has been with your guidance. It is making this process VERY enjoyable! :prost: My profession is in Sales and Management and I just play with coding when I have time as I really enjoy it. I don't know any languages really. Just pieces and parts of languages from wanting to do a certain project (mostly to do with games :lol:) I understand a descent amount on Java coding now as I never tried Java until this project, but proper layout(still want to do 1 long script instead of multiple classes, methods, etc.) I still have a long way to go.

I will do some more playing around, but I am actually very optimistic I will be able to get this to work. I may even dive into the UnitOrders side of it later to auto update on the fly :shock:


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 33 Beiträge ]  Gehe zu Seite Vorherige  1, 2, 3  Nächste

Alle Zeiten sind UTC + 1 Stunde


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 15 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
Webhosting by sunrise design ohg