Page 1 of 1

HTML interface module (need a /tg/ dev to look at this!)

Posted: Sun Nov 09, 2014 9:10 pm
by nullquery
Hi,

I've been working on a pluggable HTML interface module that's supposed to replace the computers and other browser windows in the game. It works pretty well, and I'd like to contribute my work to the /tg/station project.

So er... Would anybody know how to go about doing that? :D


The HTML interface module is documented and utilizes BYOND's JavaScript call functionality to update content without refreshing the entire window. This removes the annoying "flicker" that you often see and also reduces network traffic as you don't need to download new HTML files to clog up your cache with every time a value changes.

It's been tested on the Hypatia Station build of SS13 with the power monitoring computer and a deck of cards (item), and it works pretty well. It may take some time getting used to the approach I've used but I think it'll benefit everyone in the long run.

The HTML interface comes with a built-in copy of jQuery and Twitter Bootstrap to provide a simple way of dealing with widgets and enable developers to add their own flair to their interfaces. These resources are downloaded by the client only once upon login so there's no significant loss of speed in using them.

A small JavaScript file (1.19 KB non-compressed) provides a simple JavaScript API which is used to send content from BYOND (DM) code, which is also sent only once upon login.

It's possible to create custom layouts as well as using standard layouts. This is done by creating a subtype of the /datum/html_interface type. The playing cards use a subtype but only because they need to send resources to the client upon login (the card artwork).

Screenshots:
Image
The code for playing cards was changed to use the HTML interface module. The cards are downloaded from the web and may require attribution, but other than that I foresee no problems.
Note that clicking a card or action will only change the cards and action; the browser window does not refresh so there is no "flicker".

Image
The power monitoring computer. This uses the images from Bay's (?) NanoUI but none of the underlying code.

Personally I found the horde of JavaScript to look messy and unmanageable (no offense intended to whoever is responsible for it!) which is why I wrote this simplified version. Also I don't know if there are licensing issues x.x

Using BYOND 4.0's skins a new window is created with a browser window. The titlebar and (albeit ugly) "X" and "-" icons you see are actually buttons on the skin. You can drag the window around by clicking on the (custom!) titlebar and moving it around. It can be resized and minimized as normal (tested in Win8.1 with BYOND v506.1247).

tl;dr I hope to coordinate with someone to implement this into /tg/station so that it will eventually "trickle down" to other versions. Anyone care to help me out / explain?

What still needs to be done:
[*]A generic way of authenticating the user (i.e., by ID). By creating a generic way of authentication rather than doing it on a per-computer basis the code will become that much cleaner.
[*]Widespread implementation in other computers and deprecate/remove the old stuff (though I recommend starting small and slowly phasing out the old code)

For those interested, here's the public API:

Code: Select all

/*
Author: NullQuery
Created on: 2014-09-24

	** CAUTION - A WORD OF WARNING **

If there is no getter or setter available and you aren't extending my code with a sub-type, DO NOT ACCESS VARIABLES DIRECTLY!

Add a getter/setter instead, even if it does nothing but return or set the variable. Thank you for your patience with me. -NQ

	** Public API **

	var/datum/html_interface/hi = new/datum/html_interface(ref, title, width = 700, height = 480, head = "")

Creates a new HTML interface object with [ref] as the object and [title] as the initial title of the page. [width] and [height] is the initial width and height
of the window. The text in [head] is added just before the end </head> tag.

	hi.setTitle(title)

Changes the title of the page.

	hi.getTitle()

Returns the current title of the page.

	hi.updateLayout(layout)

Updates the overall layout of the page (the HTML code between the body tags).

This should be used sparingly.

	hi.updateContent(id, content, ignore_cache = FALSE)

Updates a portion of the page, i.e., the DOM element with the appropriate ID. The contents of the element are replaced with the provided HTML.

The content is cached on the server-side to minimize network traffic when the client "should have" the same HTML. The client may not have
the same HTML if scripts cause the content to change. In this case set the ignore_cache parameter.

	hi.executeJavaScript(jscript, client = null)

Executes Javascript on the browser.

The client is optional and may be a /mob, /client or /html_interface_client object. If not specified the code is executed on all clients.

	hi.show(client)

Shows the HTML interface to the provided client. This will create a window, apply the current layout and contents. It will then wait for events.

	hi.hide(client)

Hides the HTML interface from the provided client. This will close the browser window.

	hi.isUsed()

Returns TRUE if the interface is being used (has an active client) or FALSE if not.

	** Additional notes **

When working with byond:// links make sure to reference the HTML interface object and NOT the original object. Topic() will still be called on
your object, but it will pass through the HTML interface first allowing interception at a higher level.


	** Sample code **

mob/var/datum/html_interface/hi

mob/verb/test()
	if (!hi) hi = new/datum/html_interface(src, "[src.key]")

	hi.updateLayout("<div id=\"content\"></div>")
	hi.updateContent("content", "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque porttitor, leo nec facilisis aliquam, elit ligula iaculis sapien, non vulputate neque metus id quam. Cras mauris nisl, pharetra malesuada massa nec, volutpat feugiat metus. Duis sed condimentum purus. In ex leo, laoreet ac rhoncus quis, volutpat ac risus. Ut et tempus magna. Vestibulum in nisl vitae metus commodo tempus et dapibus urna. Integer nec vestibulum lacus. Donec quis metus non lacus bibendum lacinia. Aenean tincidunt libero vestibulum metus blandit pharetra. Nunc quis magna volutpat, bibendum nulla in, sagittis risus. Sed id velit sodales, bibendum purus accumsan, eleifend purus.</p><p>Suspendisse potenti. Proin lorem orci, euismod at elit in, molestie dapibus leo. Nulla lacinia vel urna nec vulputate. Praesent non enim metus. Quisque non pharetra justo. Integer efficitur massa orci, vitae placerat libero eleifend sit amet. Fusce in placerat quam. Praesent quis lectus turpis. Aenean mattis lacus sed laoreet sagittis. Aliquam efficitur nisl at tellus ultrices auctor. Quisque hendrerit, mi quis suscipit interdum, justo magna gravida libero, et venenatis sapien ante quis odio.</p><p>Etiam ullamcorper condimentum lacus, eu laoreet ipsum gravida et. Fusce odio libero, iaculis euismod finibus sit amet, condimentum ac ante. Etiam pretium lorem mauris, sit amet varius tortor efficitur eget. Pellentesque at lacinia lectus. Integer tristique nibh hendrerit purus placerat dapibus. Cras elementum est elementum, bibendum orci nec, consequat elit. Fusce porttitor neque quis libero placerat, vel varius arcu aliquet. Aenean vitae rhoncus nunc, non tempus magna. Aliquam lacinia sit amet dolor id maximus. Curabitur eget eleifend nisl. Mauris interdum nibh feugiat lectus lacinia fringilla. Aliquam nec magna vel leo ultricies dignissim. Duis eu luctus odio, finibus dictum nulla.</p>Mauris fringilla a lorem vel euismod. Sed auctor eget lorem sed lacinia. Maecenas vel posuere sapien. In lobortis odio non tincidunt ultricies. Sed consequat molestie orci et pharetra. Suspendisse potenti. Vestibulum vitae ornare risus, nec semper arcu. Duis et interdum lacus.</p><p>Etiam urna nulla, pulvinar at est auctor, varius feugiat orci. Vestibulum efficitur maximus imperdiet. Donec vehicula, leo sit amet condimentum pulvinar, urna felis aliquet velit, bibendum placerat dui libero sed tortor. Vivamus ac diam commodo nisi facilisis lacinia. Aenean a rhoncus risus, venenatis efficitur arcu. Curabitur tincidunt nulla eget augue malesuada imperdiet. Quisque ligula purus, dictum a imperdiet eget, eleifend eu leo. Phasellus massa ipsum, molestie nec pellentesque eu, scelerisque et mi. Vivamus at libero varius, lacinia magna non, imperdiet tortor. Donec scelerisque ipsum sollicitudin justo ornare accumsan. In velit orci, lobortis eget maximus et, scelerisque ut nulla. Cras sit amet finibus sapien. Aenean metus lorem, gravida a rutrum quis, varius eu arcu. Integer ac hendrerit purus. Aliquam cursus ultricies tortor. Fusce scelerisque, arcu id pellentesque accumsan, nulla turpis tempus lectus, tincidunt blandit mi nisi non metus.</p>")

	hi.show(src)

*/

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sun Nov 09, 2014 10:06 pm
by Gun Hog
Please say you are going to develop this for TG and convert our interfaces to it!

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sun Nov 09, 2014 10:11 pm
by nullquery
Gun Hog wrote:Please say you are going to develop this for TG and convert our interfaces to it!
That is my intention, if I'm allowed to do so...

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sun Nov 09, 2014 10:24 pm
by Remie Richards
nullquery wrote:
Gun Hog wrote:Please say you are going to develop this for TG and convert our interfaces to it!
That is my intention, if I'm allowed to do so...
Allowed to do so? Open source contribution is a beautiful thing.
Just note were in a feature freeze until december 4th, until this time no "features" will be added, only fixes.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sun Nov 09, 2014 10:34 pm
by Wild Bill
Image
Excellent work. A big step up from Nano.
Is the code up somewhere (github repo)?
Spoiler:
btw /vg/ isn't in a feature freeze ;)

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 1:30 am
by Nienhaus
So would it be possible coding pool tables using this, because that's a nice fancy looking cards.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 5:01 am
by paprika
Wild Bill wrote:
Spoiler:
btw /vg/ isn't in a feature freeze ;)
Back to your cave.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 6:27 am
by nullquery
Wild Bill wrote:Is the code up somewhere (github repo)?
Code is currently in the Hypatia Station Github repository. See https://github.com/HypatiaStation/HypatiaStation for the full repository, or https://github.com/HypatiaStation/Hypat ... _interface for the module specifically.

The module is designed to be plug and play. So if you copy the contents of "code/modules/html_interface" into another codebase and tick/enable the .dm files it should compile without a problem.

You'll need to add a few procs to function as "hooks" though so that the interface will know when a client may be active. The code for this is over here: https://github.com/HypatiaStation/Hypat ... chinery.dm

The first hook is used to determine if a client is allowed to receive updates. The second hook is used to unset the machine variable if the player closes the window.

This is the code for playing cards: https://github.com/HypatiaStation/Hypat ... s/cards.dm

Playing cards are interactive, whereas the power monitor is not. All Topic calls are routed through the interface to prevent inactive clients from using them, to ensure security and provide a 'global' override.

The "hiIsValidClient" hook is slightly different in that case because it needs to check if the item in the player's inventory. I'm not entirely familiar with the changes to the SS13 codebase so I'm not sure if there's a simple proc to do it, but from what I've seen so far this does not seem to be the case.

What I'd like to accomplish is to introduce various pluggable modules and use those to clean up the code. I'd like to work on creating a clean codebase so that new developers won't have to reinvent the wheel or get confused. I'm considering to fork from /tg/station and implement these changes myself, pulling these changes back into /tg/ using (large) pull requests. But "as new features aren't permitted until the 4th of December" I fear that any changes I make now may not end up in /tg/ making future attempts to pull it in more difficult (due to changes in the /tg/ codebase).

Ideally I'd like to roll out the module itself immediately, regularly providing updates to it, and pushing the code related to the actual implementation of the module at a later date when new features are allowed. Once thoroughly tested the implementation of the module can then be offered to /tg/ as a pull request. In the meantime people can experiment with it / use it for new computers.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 6:29 am
by nullquery
I think it makes sense for me to host my own server so that I can implement and roll out these features and they can be tested, but I don't think I'd be able to attract many players without help from others. I could try to join an existing server, but I don't think anyone wants a rogue developer.

If there's anyone who has any ideas about or would be interested in working with me on creating/hosting a branch that'd be great since I'd be able to push a lot more content out that way. Right now I feel constrained because I can't make large changes (can't test them properly in a live environment) and even the small changes need to go through pull requests for me at the moment. Note that I already own a dedicated server, so from a technical standpoint I'm already able to host a server/website/forum/anything. But I'm not sure how to attract players and create a community (I'm more technically oriented than people oriented, if you know what I mean).

EDIT: Due to the excitement that's been shown in this thread I've also taken the liberty to create my own Github repository. I named it "Void Station" as the primary purpose of the fork is to send bad code "into the void" and to create a clean codebase. I'll submit the code for the module to it but other than that I'm not going to work on it unless I have a good feeling about the outcome of creating and maintaining my own fork/server. In other words it would depend on who may be willing to help me with the logistics and day-to-day operations.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 8:33 am
by adrix89
For testers drop by #coderbus and #tgstation13 from IRC to get some volunteers.
Someone might be active and drop by.
You can ping me when I am on and I might drop by.

We used to have a development server that run different branches but it didn't exactly have a population.
You can try to speak with the site admin and advertise it on the front page.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 4:38 pm
by Miauw
We have a CanUseTopic() proc to see if a client is allowed to do things (alternatively, ..() in Topic should usually return 1 if usr is not allowed). To see if an item is in a player's inventory, you could just do if(item.loc == user.loc)

As adrix said, feel free to come to #coderbus to discuss this.
And removing bad code is already basically tg's main focus. We rewrote say(), somebody is working on powernets, Aran rewrote atmos and is rewriting pipeatmos, etc.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 6:34 pm
by Remie Richards
Miauw wrote:do if(item.loc == user.loc)
you mean if(item.loc == user), right :P

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 6:45 pm
by Miauw
Remie Richards wrote:
Miauw wrote:do if(item.loc == user.loc)
you mean if(item.loc == user), right :P
you mean if(item.loc == user || item.Adjacent(user)), right :P

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 7:11 pm
by Remie Richards
Miauw wrote:
Remie Richards wrote:
Miauw wrote:do if(item.loc == user.loc)
you mean if(item.loc == user), right :P
you mean if(item.loc == user || item.Adjacent(user)), right :P
if it's adjacent to user it can't possibly be in their inventory! (unless Adjacent() contains some pretty dark magic) Hehe.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 8:35 pm
by oranges
Just to clarify this is a replacement for nano ui correct?

Does it handle things like distance and visiblity as well as nanoui used too?

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 8:50 pm
by Miauw
Remie Richards wrote:
Miauw wrote:
Remie Richards wrote:
Miauw wrote:do if(item.loc == user.loc)
you mean if(item.loc == user), right :P
you mean if(item.loc == user || item.Adjacent(user)), right :P
if it's adjacent to user it can't possibly be in their inventory! (unless Adjacent() contains some pretty dark magic) Hehe.
Hence the ||.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 10, 2014 9:09 pm
by nullquery
oranges wrote:Just to clarify this is a replacement for nano ui correct?

Does it handle things like distance and visiblity as well as nanoui used too?
It uses hooks so you can specify what constitutes an active client. This can be based on distance, whether the device is powered, if the sun is facing northwest... you name it.

The green/red eye from NanoUI is copied and shows if the window is active. This only works with Nanotrasen-themed windows.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Wed Nov 12, 2014 7:36 am
by oranges
Sweet, I'll just hop onto this hypetrain here now.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Thu Nov 20, 2014 10:32 am
by ErikHanson
holy shit

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Thu Nov 20, 2014 11:44 am
by Razharas
Looks nice but i hope it will not follow nano ui fate

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Thu Nov 20, 2014 12:53 pm
by Gun Hog
Razharas wrote:Looks nice but i hope it will not follow nano ui fate
This. Please try to stay with us and continue development for /tg/! The last developer fled to Bay, leaving us with a beautiful, but outdated UI. NanoUI has been greatly expanded on Bay, giving them nice features such as a crew monitor that plots crew members onto a mini-map of the station. There are plenty of opportunities for this seemingly superior UI to improve our usability!

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sat Nov 22, 2014 11:59 am
by nullquery
Gun Hog wrote:
Razharas wrote:Looks nice but i hope it will not follow nano ui fate
This. Please try to stay with us and continue development for /tg/!
Well, I'd like to apologize in advance then, because I'm currently working on a platform with wb, a /vg/station developer. We're hoping to produce a stable codebase that will not only be useful to build a new SS13 off of but to allow other projects using the same core components as well. (The core is licensed under MIT license, so developers only using the core would not be subject to the same licensing standards as SS13.)

Current progress on the project is that a few basics have been implemented: movement is done using pixel-based movement, the HTML interface system is plugged in (I've done such a good job at designing it to be modular that it fit snugly into this new project :D), and the last thing I did was implement the HUD from SS13. This week I've been occupied with a personal project but I hope to get back to the project.

I've (perhaps foolishly) registered a domain name for the group and I hope we'll be able to attract more developers to our project (if anyone is interested feel free to send me a PM!). Promises I make are an optimized codebase and a source-code that compiles fast rather than the 30 seconds - 1 minute compile time SS13 takes. Link to Github.
Gun Hog wrote:The last developer fled to Bay, leaving us with a beautiful, but outdated UI. NanoUI has been greatly expanded on Bay, giving them nice features such as a crew monitor that plots crew members onto a mini-map of the station. There are plenty of opportunities for this seemingly superior UI to improve our usability!
My intention for the code I write is to ensure that other people can use it very easily, and to provide a clear and properly documented public API for other developers to work with. You shouldn't need to understand exactly how the HTML interface module works, you'd just need to know how to use it. And I've provided examples for that (power monitor computer and playing cards).

It's still missing a generic way of authenticating players by their ID cards or PIN numbers. This needs to be a generic implementation and not decided per computer as it is now, because it will make things messier in the codebase and won't be a consistent interface for players.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sat Nov 22, 2014 12:00 pm
by Ricotez
I tried to understand NanoUI a few times but I just couldn't figure the syntax out. You'll have that problem much less with HTML and JS.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Sat Nov 22, 2014 2:49 pm
by Remie Richards
nullquery wrote: Well, I'd like to apologize in advance then, because I'm currently working on a platform with wb, a /vg/station developer. We're hoping to produce a stable codebase
Don't apologise for helping wb with Core/SS99, it's got a lot of potential and will end up being a really nice Byond library.

Re: HTML interface module (need a /tg/ dev to look at this!)

Posted: Mon Nov 24, 2014 9:20 pm
by oranges
NanoUI is html and js though? It's just using a template library

>Core99

More like DeadProject99