Play Now Login Create Account
illyriad
  New Posts New Posts RSS Feed - Anyone have UIv2 experience yet?
  FAQ FAQ  Forum Search   Register Register  Login Login

Topic ClosedAnyone have UIv2 experience yet?

 Post Reply Post Reply
Author
photojoe View Drop Down
New Poster
New Poster


Joined: 21 Jan 2011
Status: Offline
Points: 17
Direct Link To This Post Topic: Anyone have UIv2 experience yet?
    Posted: 02 May 2011 at 19:29
Hello. I'm looking to make a tool to help our alliance share data. Screen caps and pasting to an alliance wiki sucks!

I'd like to automate the process but as UIv2 appears to be almost pure javascript I'm unable to scrape the incoming HTML for the data we want.

So, what I'm looking for, is advice from those who have, or are, developing tools for UIv2.

Thanks in advance!
Back to Top
HonoredMule View Drop Down
Postmaster General
Postmaster General
Avatar

Joined: 05 Mar 2010
Location: Canada
Status: Offline
Points: 1650
Direct Link To This Post Posted: 02 May 2011 at 20:03
If you're looking to use a client-side script to gather data and reformat as bbcode or wiki text, etc., take a look at http://api.jquery.com/ajaxComplete/. What you'll need to do is implement a universal "incoming data" handler to identify and optionally parse/present/share whatever has been dynamically fetched by the stock UI.  I think you'll need to attach the handler to document.body, but don't recall.  I haven't gone beyond a barebones proof-of-concept yet myself, since for HarmlessButler 2.0 I'm currently far more concerned with the extra UI templating, town/player/alliance data lookup and caching, and various other subsystems.  Info scraping is a way off for me yet.
Back to Top
photojoe View Drop Down
New Poster
New Poster


Joined: 21 Jan 2011
Status: Offline
Points: 17
Direct Link To This Post Posted: 02 May 2011 at 20:23
Out of curiosity: If you aren't pulling data down from the game what are you using as a data set to test your code against? Or is it that you aren't even to the point where you're testing anything yet?
Back to Top
HonoredMule View Drop Down
Postmaster General
Postmaster General
Avatar

Joined: 05 Mar 2010
Location: Canada
Status: Offline
Points: 1650
Direct Link To This Post Posted: 02 May 2011 at 20:57
It's the latter, but much of the data I need to populate my UI extensions doesn't need scraped from dynamic content.  For example, player id, time offset, and building information on the current city are all available as raw javascript--relevant variables for generating navigational links are PlayerId, CurrentTown (id), buildings (complex array), and OffsetTime (in milliseconds).  And the player name and town list (with ids, names and coordinates) are available in the base html--logout link and town select dropdown.  (The QA tester in me wonders how/whether that updates when a settler lands or town is captured and the page not fully reloaded).

If you're familiar with the original HarmlessButler, you may have noticed both addition of new UI elements (sidebar, nav menus) and also alteration of the existing ones (bigger links in context menus, new tooltip system, etc.)  Much of what I have to do doesn't really require reading any original information at all, but simply adding more (such as more html content and css rules that impact both the new and the old).

On the other hand, I want players to be able to read email without constantly switching between email and list, and launch troops/diplos without switching between map and launch pages.  For these, I intend to duplicate the map/email list contents wholesale in the form of a side panel showing "whatever map view/email listing you visited last" complete with the associated context menus etc.  And of course plenty of other examples abound.  There's hardly anything that can be fetched and isn't useful for enhancing something else, and I'm all about showing aggregate/overview information, as well as highly contextualized content.  (Example: looking at info telling of a scout returning to town x: send resources to x from here; or bring resources here from x; or view that scout's report; or send troops from here to where that scout went; or show the player list and summarize city count and total population for the alliance whose player's town occupied the spot that diplo scouted; etc...)
Back to Top
HonoredMule View Drop Down
Postmaster General
Postmaster General
Avatar

Joined: 05 Mar 2010
Location: Canada
Status: Offline
Points: 1650
Direct Link To This Post Posted: 06 May 2011 at 04:06
This may be more elaborate than you need, but here's the solution I've produced.  It allows you to have multiple handlers "subscribe" to various data sources by matching include and exclude strings or regular expressions in the request url.  (for example, subscribe function "readerFunc" to chat data by saying:

Gateway.subscribe("mychatreader", readerFunc, "/Chat/Update");

readerFunc then gets called with (event object, request object, settings object) and you can use request.responseHTML, request.responseXML, request.responseJSON, or request.responseText as you please.  This is particularly convenient for me, because I have some handlers that need to be called for just about anything, and others that need to register for a number of inputs, etc.  The various subscribers will be fed in the order you registered them.  They also get called after the ajax call's own personal success handler, which means whatever you want to parse from html content will already be injected into the page.  In many cases, it will be easier to use jQuery selectors, dom traversal, and other traditional means than trying to parse raw text.  It's unfortunate (for us at least) that the UI seems to mostly use HTML snippets, which aren't very malleable or efficient to manipulate.

Subscribe accepts either null, single values, or arrays of values for "includePaths" and "excludePaths," which both work as filters.  A subscriber always gets called unless one or more include paths exist but none match, or an exclude path exists and is matched.  Browsers other than Firefox may need a different method of accessing jQuery and the error console than using "unsafeWindow"...I haven't gotten into cross-browser compatibility much yet.  It appears that choosing between unsafeWindow and window will satisfy most browsers, but preliminary research indicates Chrome 4 might be troublesome.


The code:
var $ = unsafeWindow.$;

var Gateway = new function() {
    var subscribers = {};
   
    var pubObj = {};
   
    function dispatch(evt, request, settings) {
        var key, i, client, rPath = settings.context.url;
        for(key in subscribers) {
            try {
                client = subscribers[key];
                if(client.include.length && !multiMatch(rPath, client.include))
                    continue;
                if(multiMatch(rPath, client.exclude))
                    continue;
                client.func(evt, request, settings);
            } catch(e) {
                unsafeWindow.consle.log(e);
            }
        }
    }
   
    function multiMatch(str, regArr) {
        for(var i in regArr)
            if(str.match(regArr))
                return true;
        return false;
    }
   
    // subscribe to incoming data, optionally filtering by regex matches on the request url (can use plain string matches as well)
    pubObj.subscribe = function(id, parserFunc, includePaths, excludePaths) {
        if(!includePaths)
            includePaths = [];
        if(typeof includePaths === "string" || includePaths instanceof RegExp)
            includePaths = [includePaths];
       
        if(!excludePaths)
            excludePaths = [];
        if(typeof excludePaths === "string" || excludePaths instanceof RegExp)
            excludePaths = [excludePaths];
       
        subscribers[id] = {"func":parserFunc, "include":includePaths, "exclude":excludePaths};
    }
    pubObj.unsubscribe = function(id) {
        delete subscribers[id];
    }
   
    $("body").ajaxSuccess(dispatch);
    return pubObj;
}();




Edited by HonoredMule - 06 May 2011 at 07:58
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.03
Copyright ©2001-2019 Web Wiz Ltd.