lemo's Forum Posts

  • Thanks for the reply Ashley

    Can you guys explain what you mean by a "true" binary image (or a fake one)?

    With the method above in the end we seem to get a proper binary PNG file, and very different from it's base64 string counterpart

    Also, either using {'encoding': 'base64'} or atob() and {'encoding': 'binary'} seems to produce the same result

    Can you see the capx below, and explain how the resulting PNG isn't a true binary one?

    NWimagefile.capx

    Otherwise yeah I suppose it would be more efficient to remove the "base64" middle man from the CanvasSnapshot method (or extract base64 plugin),

    and somehow access the binary image data from a layer or a sprite for the user with say Sprite.imageData, and be able to save it directly ^^

    PS: MadSpy I posted a couple of links on page1 with (apparently?) buffer examples

  • I see, sounds pretty good then

    Either way Ashley there's still time to consider such a MINOR change for a very HANDY feature in the official plugin.

    I mean, proper games do have a hotkey to save their captures as images in a Screenshots folder... and the file I/O actions are a major reason for people to use nwjs

    PS: In my case of sprite extract and image library, being able to save/load PNGs on disk (currently with the execJS action) instead of TXT images boosted my loading times from 7sec to now just 3sec

  • Okay sounds alright

    Btw in case of a separate action from the other Write File, maybe no need to have the utf8/base64, and just keep base64 for this one

    Probably best to have a png/jpg dropdown in that case actually

    How would you plan to implement an extra action to the official plugin like in your pic though, keeping this post in mind?

  • Yeah I guessed it would from the pics, I was just nitpicking about the naming of "Write Canvas Screenshot" instead of something more general

  • MadSpy Yes, that's pretty much it, or rather for the name just "Write Image" or "write File +"

    So people could save other things rather than only CanvasSnapshot

    In my case, like I mentioned above I save a bunch of Sprites though the base64 extract plugin

    "var fs = require('fs');fs['writeFileSync']('" & replace(replace(AppPath & "Img\" & replace(Box.Title,":", "~") & " (" & Box.Year & ").png","\","\\"),"'","\'") & "','" & Box.ExtractImage.currentImage & "'.split(',')[1], {'encoding': 'base64'});"[/code:sawspujv]
    
    But yeah my execJS looks like above, would be much cleaner with a proper C2 action... does it mean you are making the plugin?
    If you are, it would be great to have the synchronous/asynchronous dropdown as well :]
  • MadSpy Thanks that also works, and even better than my version as I don't have to call the nw.js plugin and keep a modified version of it with "binary" encoding mode :]

    It's pretty much like in the first link I posted on this thread, but I had no idea you could use nw.js functions in execjs too so, it's good to know

    Looks like the "base64" encoding choice does the conversion directly, also saving a step which is nice (so let's says Encoding dropdown: Utf-8 | Base64 | BInary for my suggestion above!)

    Although this is good for temporary work around, I rather not have a capx that looks like a full JS script, and hopefully we can have more "C2-friendly" options in the actual NWJS plugin

  • HURRAY

    NW.JS Write File > Browser.ExecJS("atob("""&tokenat(Sprite.ExtractImage.currentImage,1,",")&""")")

    This finally works, and saves a PNG file representation of the Sprite in the specified folder automatically

    I mentioned ExecJs + atob() a few posts above, and couldn't get the quotes right, then I dug out this post

    The link to the video tutorial that James linked is gone, I found it again

    Subscribe to Construct videos now

    thanks to the title

    For general screenshots on disk: Browser.ExecJS("atob(""" & tokenat(CanvasSnapshot, 1, ",") & """)")

    Now this method doesn't work (anymore?), and produces the same corrupted image I had in other tests

    I also had to edit the original NW.JS plugin, and exchange the Write File encoding from "utf8" to "binary"

    This now works, and here's the change below, with a UI mockup to hopefully have it for the official plugin

    Runtime.js

    	Acts.prototype.WriteFile = function (path_, contents_)
    	{
    		if (!isNWjs)
    			return;
    		
    		try {
    			fs["writeFileSync"](path_, contents_, {"encoding": "binary"});
    		}
    		catch (e)
    		{}
    	};[/code:1y0o2ik8]
    
    Suggestion
    [img="http://i.imgur.com/LiJ3EH3.png"]
    
    Also while I'm at it I added another suggested option to choose between Synchronous/Asynchronous
    Like rexrainbow [url=https://www.scirra.com/forum/request-nw-js-write-image-file_p1029199?#p1029199]mentioned[/url], it would be worth having to maybe improve performance in some cases
    Anyway, I think it's important to have a way to save live screenshots or batch of image on desktop apps
    
    @Ashley can you have a look at this suggestion for the nwjs plugin?
  • I dunno, that's sounds like a lot more complicated approach to me than storing each image directly

    Even if there's a lib, someone would still need to make a plugin to use it

    And I doubt adding an extra step for unzipping will help my loading times

  • newt

    The library is different for each user and each image has to be fetched one by one through an API

    (it's a movie app with film posters from IMDb)

  • Now, I'm trying to modify Pode original plugin to extract the sprite directly as a "blob" instead of a base64 string

    Luckily the HTMLCanvasElement.toBlob() is supported form Chrome 50+, which just made it into nw.js 14.0 ten days ago!

    Would that work to write that image "blob" with nw.js "write file" as a PNG on disk?

    But yeah I have no idea about javascript or how to write a plugin, so the modified plugin below doesn't work

    How do I return the "blob" out of that child function back into the "ret"?

    	// the example expression
    	exps.currentImage = function (ret)	// 'ret' must always be the first parameter - always return the expression's result through it!
    	{
    		this.canvasSprite.width = this.inst.cur_animation.frames[this.inst.cur_frame].texture_img.width;
    		this.canvasSprite.height = this.inst.cur_animation.frames[this.inst.cur_frame].texture_img.height;
    		this.ctxSprite.drawImage(this.inst.cur_animation.frames[this.inst.cur_frame].texture_img, 0, 0);
    		this.canvasSprite.toBlob(function(blob) {
    			ret.set_string(blob);
    		});
    	};[/code:2f17co95]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I found this nice plugin to decode base64 inside C2

    Combined with the other extract sprite to base 64 would that work?

    How about an ExecJS with atob()

    I seem to get some kind of "binary" data written, but it says the image is corrupted when I try to open it

    Can someone have a look at the NWautosave.capx, where I'm trying all that? with no success whatsoever

  • rexrainbow

    Well that sucks, yeah the player api docs don't seem to have that indeed

    Hey check out this other video, just playing around with the focus, before the video event load

    (same behavior when a video is playing anyway)

    -Click outside the player two separate times to loose focus

    -Subsequent clicks have no effects

    -Then a double-click OUTSIDE the player brings back focus to it

    Definitely something strange going on here o_O

    https://drive.google.com/file/d/0B6wXdu ... JwQ0E/view

  • rexrainbow

    Doh I'm starting to wonder if the quality of my written english is really that bad... let me try to explain again

    I am not trying to avoid the Youtube UI, on the contrary I do want it to show up on hover, so I'll really keep those to "Yes"

    Now, even when it's all setup as "Yes", the Youtube UI fails to show up on hover, after the "focus" is lost

    See the link below, I just made a video to show that more clearly

    https://drive.google.com/file/d/0B6wXdu ... VwNDg/view

    00:00 - 00:05: As you can see the player reacts on hover as the icon turns red

    00:12 - 00:22: The Youtube UI shows up fine after clicking PLAY, and when hovering the mouse

    I can scroll through the timeline thumbnail and change the volume on the go

    00:33 - 00:43: Focus is lost after another click and I can't see any controls while hovering

    I have to click the player, which pauses the video, then only I can control it

    00:43 - 00:59: The UI now shows up normally on hover

    And once again, in the case of my app, there's a few click before reaching the Play button,

    so the "focus" is already lost for the first play, making the control/pause situation a bit clumsy

  • Hey rexrainbow, thx for update, I know the video starts just fine, it's not my issue

    It's really about the "focus on hover" behavior, so that when you hover the video, the controls from the player show up

    Try to hover after pressing PLAY once, and try to hover again after pressing PLAY again

    And to see the youtube UI again, change the volume, or see the timeline thumbnails, you have to click (and pause!) the player

    I thought in the meantime it would be good to have no autoplay in my case, so the user grab the focus before without pausing it in middle

    Although another problem maybe with the bug fix? I was expecting to see the video thumbnail and a play arrow button

    But if I set a "load video" with "autoplay no", it indeed doesn't play yet, but shows the "loading dots" instead of a nice video thumbnail?

    The "autoplay no" does show a nice thumbnail though if you launch it with the VideoID already in the object properties

  • Thanks rexrainbow, hmm still no luck for me though

    Hey I did some tests with all the elements in my projects, and I finally found a way to replicate in a simple capx

    It just happens with the TOUCH, after I click another element... TWICE?

    Same exchanging with a MOUSE click anyway, but I don't really why it doesn't loose focus at first o_O

    Here is a capx: YouFocus.capx

    Don't ever click the youtube object but just hover it

    If you press PLAY once you can still have focus and have the controls reappear on hover

    Press PLAY again and focus is lost for good

    (In my app I don't even get focus the first time)

    Btw I'm also highlighting a bug in this capx, the autoplay is "no" on both the object and the "load" action, and yet plays