<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Luxi Sans'; font-size:11pt; font-weight:400; font-style:normal;">Hi Bert,<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Thanks for your detail comments. I will probably try to get the "patched" version working this weekend so that I can get quickly to the part of coding the Datastore interactions. I have been stalling on this too long (mostly time reasons I cannot get anything done except weekends), so I want to get to the Datastore part first as a step 1 experiment. <br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>But I completely agree it is best to replace SugarLauncher with a more generic one asy ou suggested, which I'd make to be step 2. <br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Let me see how far I get this weekend on step 1. I have a feeling I will ask for help along the way :)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Thanks and later, Milan<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>On June 1, 2009, Bert Freudenberg wrote:<br>
> On 31.05.2009, at 23:23, Milan Zimmermann wrote:<br>
> > Hi Bert,<br>
> ><br>
> > After 3 weekend delay I got back today to FreeCell. I re-read the<br>
> > email thread and put together high level steps of how FreeCell's<br>
> > statistics state could be managed. I hope the steps are<br>
> > uderstandable, and realize architecturally it is not very nice, but<br>
> > a step..<br>
> ><br>
> > Below, I am listing base code (additions and patches) that would<br>
> > plugin FreeCell into the workflow so that everything is in place<br>
> > where it's statistics state could be managed, serialized and stored<br>
> > in Datastore. Could you comment if the following would work as a<br>
> > first step to play with the Datastore stuff in FreeCell - Thanks.<br>
> > There are some questions at the end, and I appreciate any<br>
> > suggestions and alternatives :)<br>
> ><br>
> ><br>
> > 1) Patch SugarLauncher>>#startUp to call<br>
> > self class allInstances do: [:ea| ea shutdown]. "is this neded?"<br>
><br>
> It's a safety net, not strictly needed.<br>
><br>
> > parameters at 'ACTIVITY_ID' ifPresent: [:activityId|<br>
> > objectId := "todo get objectId".<br>
> > "Make FreeCell and recover statistics from journal"<br>
> > FreeCell class startUpInSugarForActivity: activityId object: objectId.<br>
> > World windowEventHandler: self.<br>
> > ].<br>
> ><br>
> > (A note: I realize you suggested to use FREECELL_ACTIVITY_ID and<br>
> > FREECELL_OBJECT_ID instead of ACTIVITY_ID and OBJECT_ID and then we<br>
> > would not have to patch SugarLauncher>>#startup, but it seems we<br>
> > probably need to patch some other SugarLauncher methods such as<br>
> > invite anyway, so I thought this could be ok)<br>
><br>
> No, in that case SugarLauncher would not be used at all, that was what<br>
> I was proposing. Better implement the whole caboodle on your own so<br>
> you know what's happening. Less magic ;) OTOH SugarLauncher is hard-<br>
> wired in some places, like in the SugarNavBar, so some refactoring may<br>
> be needed anyway.<br>
><br>
> A potential problem is that the FreeCell code gets loaded via<br>
> ProjectLauncher so it depends on ProjectLauncher being started first<br>
> before SugarLauncher:<br>
><br>
>         AutoStart installedLaunchers<br>
><br>
> > 2) Add method FreeCell class>>#startUpInSugarForActivity: activityId<br>
> > object: objectId<br>
> ><br>
> > which would perform the steps currently performed in the FreeCell.st<br>
> > doits:<br>
> ><br>
> > Project current flapsSurpressed: true.<br>
> > World color: Color black.<br>
> > FreeCell<br>
> > instance<br>
> > (recoverStatisticsOnSugarStartUpForActivity: activityId object:<br>
> > objectId)<br>
> > openInWorld.<br>
> > (... center and zoom to screen extent)<br>
><br>
> Yes, though objectId may not be present (if this was run the first<br>
> time).<br>
><br>
> > 3) Add method FreeCell class>>#instance<br>
> > FreeCellSingleton := FreeCell new. "just a class var"<br>
> > ^ FreeCellSingleton.<br>
> ><br>
> > 4) Add method FreeCell>>#recoverStatisticsOnSugarStartUpForActivity:<br>
> > activityId object: objectId<br>
> > this method is eventually called from patched<br>
> > SugarLauncher>>#startUp, and it would do:<br>
> > - use activityId and objectId to read Datastore, and obtain value<br>
> > for key=serialized_statistics<br>
><br>
> You only need the object id to read from datastore.<br>
><br>
> > - obtain sessionWins, sessionLosses, totalWins ... etc from<br>
> > serialized_statistics_value<br>
> > - set the deserialized values on the FreeCellStatistics members.<br>
> > (This will need a simple setter of the statistics values)<br>
> ><br>
> > 5) Patch SugarLauncher>>#shutDown as follows:<br>
> > activityId := parameters at: ACTIVITY_ID.<br>
> > objectId := parameters at: OBJECT_ID.<br>
> > freeCell := FreeCell instance.<br>
> > freeCell #shutDownInSugarAsActivity: activityId object: objectId.<br>
> ><br>
> ><br>
> > 6) Add method FreeCell>>#shutDownInSugarAsActivity: activityId<br>
> > object: objectId<br>
> > which would :<br>
> > - serialize sessionWins, sessionLosses, totalWins ... etc to<br>
> > serialized_statistics_value<br>
> > - put on Datastore, for activityId and objectId, an entry with<br>
> > key=serialized_statistics, value=serialized_statistics_value<br>
> ><br>
> > 7) Add method FreeCell>>#quit which would do:<br>
> > Sugarlauncher current quit<br>
> ><br>
> ><br>
> > 8) Patch SugarLauncher>>#quit to call<br>
> > self leaveSharedActivity. "is this needed?"<br>
> > Smalltalk quitPrimitive. "i hope this calls shutDown?"<br>
><br>
> No, this quits immediately ...<br>
><br>
> > FreeCell class startUpInSugar.<br>
><br>
> ... meaning you need to do the FreeCell shutdown before quitting.<br>
><br>
> > 9) Export the changes to FreeCell.st. so it will contain roughtly:<br>
> > - patches for:<br>
> > - SugarLauncher>>#startUp<br>
> > - SugarLauncher>>#shutDown<br>
> > - SugarLauncher>>#quit<br>
> > - FreeCell>>#quit<br>
> ><br>
> > I did not run any of this .. this is my next step, but I wanted to<br>
> > run it by you for obvious problems, so:<br>
> ><br>
> > Questions, comments and doubts:<br>
> > =============================<br>
> ><br>
> > - Would this work in principal? I am especially not sure around<br>
> > handling the shutDown on quit.<br>
><br>
> In principle it should work, yes.<br>
><br>
> > - Are there better more elegant/reusable ways if someone else wants<br>
> > to do something similar to other Etoys activity (ZIP, Speach etc etc)?<br>
><br>
> Well, replacing SugarLauncher with a more generic one would be good.<br>
> At least the Etoys-specific parts should be factored out. But then<br>
> again getting it to work first is not the worst idea.<br>
><br>
> > - In step 6, what would be the mime type for the new datastore<br>
> > record, so it is associated with Etoys? There are Mime types listed<br>
> > in /usr/share/sugar/data/mime.defaults but it does not list Etoys...<br>
><br>
> It should not be associated with Etoys but with FreeCell. You could<br>
> make up any mimetype. It does not have to be listed in the mime<br>
> database, unless you intend to transfer these files outside of Sugar.<br>
> If you want that you need to make up an extension and add a mime rule,<br>
> see mimetypes.xml in<br>
><br>
> http://wiki.laptop.org/go/Activity_bundles<br>
><br>
> > - I need to check when etoys start SugarLauncher>>#startUp is<br>
> > performed when I click on a Journal FreeCell item, as startUp<br>
> > contains the FreeCell creation and initialization mechanism<br>
><br>
> SugarLauncher is registered with AutoStart.<br>
><br>
> > - I cannot figure out which class puts the ACTIVITY_ID to<br>
> > AbstractLauncher>>member parameters, but that is not needed for the<br>
> > stuff above.<br>
><br>
> AbstractLauncher>>parameters does lazy initialization. But before<br>
> that, AutoStart>>startUp: actually sets the parameters. In either<br>
> case, #extractParameters is what gets arguments from the command line<br>
> (as passed in the activity script).<br>
><br>
> - Bert -<br>
><br>
><br>
> _______________________________________________<br>
> Etoys mailing list<br>
> Etoys@lists.laptop.org<br>
> http://lists.laptop.org/listinfo/etoys<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p></body></html>