Author Topic: Might And Fealty - Greasemonkey Script  (Read 1132 times)

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Might And Fealty - Greasemonkey Script
« on: January 31, 2017, 02:34:30 PM »
Might And Fealty - Streamlining the interface with Greasemonkey

Hey people, I've made something that I think would be very useful to y'all. Basically it's a Javascript plug-in that adds some functionality to the soldier selection screen. It simplifies troop selection to the degree I think everyone should be using it, and it could in fact later be integrated into the core game itself.

Greasemonkey / Tampermonkey

Before installing these types of extensions, you need to have installed GreaseMonkey (FireFox) or TamperMonkey (Chrome) in your browser.

https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
http://www.greasespot.net/

https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
http://tampermonkey.net/

Installation

Once you have a working 'Monkey installation, You browse to this link to install it:
http://retrogressiongames.com/scripts/mightandfealty.user.js

Instructions (Updated 12th March 2017)

What this script does is install an extra toolbar below the menu bar while on a soldier selection screen. There are two sections, the selection box (left) and the orders box (right).

In the selection box you can select an "action", and number of "filters". When you click "Appl,y" then the chosen action will be applied to all troops which match the filter.

- Actions include select/deselect (toggles the tick boxes), as well as all the regular options that can be applied to troops.

- "up to" X = how many troops to select. Default is 90 at a time, so that it avoids the "PHP bug" for going 100+

- "From" <group> - you can restrict the filter to apply only to letter-groups. Default is "any", and "none" is for troops with no group.

- at least/less than "X" XP = XP-based filter. Default is "at least 0 XP"

- hunger: can by "---" (matches anything), not hungry, hungry, starving or "any hunger" (matches hungry or starving). Default is "---"

- weapon/armor/equipment - self explanatory. Default is "any X" for each

- "Apply" button: sets the chosen task on the soldiers defined in the filter

~~~

"Issue Orders" button. This sends the batch of orders to the server (finalize your orders this way).

The easy way to use this is to pick an action from the drop-down menu, click Apply then click go. You can batch simple orders for 90 troops at once this way.

===

Changes

v0.2b
- better styling for panel which matches the game
- fixed a bug that occured with the new group system when you had freshly assigned troops
- default choice is "mobilize" when viewing settlement troops

v0.2a
- added the group selection feature
- merged action choice into the selection box
« Last Edit: March 12, 2017, 10:31:08 AM by Cipheron »

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Might And Fealty - Greasemonkey Script
« Reply #1 on: January 31, 2017, 05:31:57 PM »
Does not appear to function at all on chrome. Tampermonkey says that it's loaded it, but nothing appears on the pages.

In firefox it's limited only to users that use english, that's what the /en/ is in the URL. My Javascript and regex are totally nonexistent, but if you change...

// @include     *http://mightandfealty.com/en/*

to

// @include     *http://mightandfealty.com/*

and change...

if(window.location.href.match(/http:\/\/mightandfealty.com\/en\/(settlement\/[0-9][0-9]*|character)\/soldiers/) !== null)

to

if(window.location.href.match(/http:\/\/mightandfealty.com\/[a-z]\/(settlement\/[0-9][0-9]*|character)\/soldiers/) !== null)

it should work for any language.

Again though, my JavaScript is nonexistent and my regex is just a touch above nonexistent.

That said, I'm going to toy with getting this to work on my dev machine, as part of M&F itself.

Could you expand this to include groups?
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #2 on: January 31, 2017, 11:13:18 PM »
Yup, I figure the language thing, but it's the small things like that that need to be patched up so everyone can used it.

BTW should be [a-z][a-z] assuming all language codes are 2-char. [a-z] only matches a single char.

As a quick guide:

[a-z] = match one
[a-z]* = match any amount (but includes none)
[a-z][a-z] = match two
[a-z][a-z]* = match one or more

Group select already exists in the regular interface, but the idea is to later replicate the existing controls inside the panel, so that'll be part of it.
« Last Edit: January 31, 2017, 11:16:43 PM by Cipheron »

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Might And Fealty - Greasemonkey Script
« Reply #3 on: January 31, 2017, 11:30:15 PM »
When I've a moment I was going to see if this could replace the existing selection interface.

But yes, as far as I'm aware, they're all 2 digit. Least the ones in use are.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #4 on: February 01, 2017, 02:08:41 AM »
Ok I fixed the Chrome thing, turns out there was one extra line needed in the metadata so that Chrome knows when to load the script. Also it should work for any language code now even if they go > 2 characters in the future.

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #5 on: February 04, 2017, 10:31:24 AM »
Fixed another issue where if you had troops that were partway assigned to you the script would stop working. I'm more busy at the moment with work/school-related things but I'll look at getting some additional fixes going soon.

BTW Andrew when is that big server move scheduled for?

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Might And Fealty - Greasemonkey Script
« Reply #6 on: February 04, 2017, 11:06:33 AM »
I've got the new server to actually run and serve the game's code. Now I'm just working out the kinks in it handling the database. You can see said server running a test site at http://maf.tests.lemuriacommunity.org/ -- I offer no guarantee this site will be up or operational whenever someone looks at it. Right now it serves a blank page anywhere it tries to access a database.

If it follows the same issues as my local machine once I get it to accept importing the game's database it'll have issues with some battles and the lendan tower system, and after that's fixed it SHOULD run fairly well. That's when I'll want people to come in and try things out for a bit.

To answer though, after I make sure it all works right. I don't want to move everything just to have to handle ninety new problems. I'm not going to bring it up to Tom again until then.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #7 on: February 05, 2017, 04:34:45 PM »
Ok, more improvements. I got most of the functionality from below the soldier's list working in the top bar now. So you can do most basic actions now without ever scrolling down. Only caveats:

- Groups aren't fully integrated yet, but will be soon. They'll probably stay as an alternative to using selections however.

- You still have to scroll down below the list for selecting "assign" and "retrain" choices, etc, because these get added as code automatically, so I'd need to do something tricky to integrate that with the top-bar system.

- I haven't tested anything with dead guys or resupplying, so these are still handled by scrolling down.

One other thing I did actually improve from how the game works before is that when you set a soldier to "no action" it resets them to "unchanged" so excludes them from the form when it gets submitted. That means that if you set an action on 100 guys, then turn the action off, the form won't bug out when you submit it. This only works if you use my top-bar buttons however.

The holy grail here, of course, is to write code to submit the form in chunks, such that it never hits the php bug limit. That's getting closer now.

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Might And Fealty - Greasemonkey Script
« Reply #8 on: February 07, 2017, 10:16:59 AM »
Assign and retrain are handled by the code here: https://github.com/tvogt/mightandfealty/blob/4e4beb59a21b8cbec057974c9b69915607df68a7/src/BM2/SiteBundle/Resources/views/element/soldierslist.html.twig#L233

In fact, that entire page handles the soldier list for both characters and settlements, to include the buttons for it if I'm not mistaken.

I've an instance of M&F on my local machine where I can push file updates directly in order to see if they work as intended, if you want to try out alterations.

Or, if you've a Debian or Ubuntu machine at home, and are interested in continuing to help, I could help you setup a dev site of your own.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Demivar

  • Full Member
  • ***
  • Posts: 128
  • Karma: +1/-0
  • Purveyor of cunning plans.
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #9 on: March 04, 2017, 07:46:02 PM »
Even in it's basic form, after a few weeks this has helped us to bring back a couple of players and keep a few more interested.


With it, in quiet times people are still happy to log in to do the milk round of their settlements, able to transfer troops freely and know that when they're needed, mobilising doesn't require them to click hundreds of tiny boxes. Particularly useful with the 200 input limit, meaning that the old trick with mobilising the entire garrison, sorting them by equipment and finding good sized chunks doesn't work.


So yeah, nice work. Small convenience features are really helpful.
« Last Edit: March 04, 2017, 11:18:28 PM by Demivar »
22:34 - Roran Hawkins: Radovid's like you
22:34 - Roran Hawkins: but then insane
22:34 - Roran Hawkins: Dijkstra is like you

jameslg

  • Jr. Member
  • **
  • Posts: 16
  • Karma: +1/-1
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #10 on: March 06, 2017, 09:03:20 AM »
my chrome browser having difficulty installing this, how does this work?


Might And Fealty - Streamlining the interface with Greasemonkey

Hey people, I've made something that I think would be very useful to y'all. Basically it's a Javascript plug-in that adds some functionality to the soldier selection screen. It simplifies troop selection to the degree I think everyone should be using it, and it could in fact later be integrated into the core game itself.

Installation

Requires Greasemonkey (firefox) or Tampermonkey (chrome) to execute. You click this link to install it:
http://retrogressiongames.com/scripts/mightandfealty.user.js

Instructions

Basically, what this does (or should do, please give feedback) is give you an extra toolbar below the menu bar while on a soldier selection screen. What this bar does is specify a selection criteria, and it has multiple parts:

- up to X = how many troops to select. Default is 90 at a time, so that it avoids the "PHP bug" for going 100+

- select/deselect = you can make it tick OR untick the specified troops. Default is select.

- at least/less than "X" XP = basically an XP-based filter. Default is "at least 0 XP"

- hunger: can by "---" (matches anything), not hungry, hungry, starving or "any hunger" (matches hungry or starving). Default is "---"

- weapon/armor/equipment - self explanatory. Default is "any X" for each

"GO" button. This button sets/unsets the tick marks for the selected choices

Basically, the most basic way to use this is to just click "GO". This will tick the first 90 troops. You can then use the normal interface to mobilize, assign, set as militia for the whole 90. This option alone means moving large stacks of men around is dozens of times faster than normal.

Please try this out, especially on Chrome, I need the feedback.

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #11 on: March 06, 2017, 11:52:05 AM »
Do you have TamperMonkey extension? You need that for these sorts of scripts to work.

BTW, I've been pretty busy with other stuff but now I have a little time to see about adding an improvement or two.

EDIT: Added a few small improvements:

- Can now choose group as a filter option, it only lists actually existing groups
- Retrain and Assign dialogues now appear at the top of the soldiers list
- Retrain and Assign dialogues are properly triggered by the new interface

EDIT2: Next group of changes to be implemented. The goal is to reduce the number of different buttons that exist, as well as reducing mouse clicks needed:

- Reduce clicks, by adding new options to the select/deselect box
  - "Invert" as another option, get rid of global invert button
  - "clear all" as another option
  - able to directly select options such as mobilize/assign/etc from there
  - get rid of select -> apply altogether, you're always choosing options
« Last Edit: March 07, 2017, 06:18:39 AM by Cipheron »

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #12 on: March 12, 2017, 10:32:33 AM »
Some bug fixes and visual improvements in the script. There were problems with the new group code when you had newly partway-assigned troops, I had to make an allowance for that.

Cipheron

  • Full Member
  • ***
  • Posts: 170
  • Karma: +7/-4
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #13 on: March 21, 2017, 05:58:00 PM »
bump, a major improvement in the script. I managed to get a pure HTML/CSS/JavaScript multi-select drop-down box working tonight. So with that, I've set things up so that you can now select multiple types of things and the script will match them.

e.g. you can now match spears OR axes, cloth OR leather, and any subset of equipment with a single command, as well as saying e.g. mobilize multiple groups if you use the groups system. It works similar to before, except the first option in the dropdown menu is a toggle button (it alternates between all things selected, and just the most likely one, e.g. you can toggle all weapons or just spears). To select multiple things, open the drop-down menu then hold ctrl or command while clicking. Clicking without ctrl/command clear the choices.

EDIT: And as is the way of such things, adding in this more detailed check exposed a minor bug, troops with damaged gear weren't getting recognized properly. When there was the old way of detecting "any gear" then this wasn'ta problem, but now the script checks their broken gear against the list and it doesn't match. I had to rewrite how it was detecting the gear to take into account that the HTML for damaged gear is different (since it's not wrapped in the hyperlink to the definition of the gear).

There are also a few minor bug fixes, and added a Bury Dead button at the top that only buries up to max 90 dead at a time to avoid the dreaded php_vars bug. I had to wait until I had been in a battle and had dead people to be able to get this working.
« Last Edit: March 21, 2017, 07:04:05 PM by Cipheron »

Dorian

  • Full Member
  • ***
  • Posts: 219
  • Karma: +26/-11
  • Playing since 2015.
    • View Profile
Re: Might And Fealty - Greasemonkey Script
« Reply #14 on: March 21, 2017, 09:58:32 PM »
This is such a nice feature that makes one of the most annoying game mechanics of the game work like a charm. Well done and keep up the great work!