From a55edc6302ac7f0af5c1df40df7fe058ec65a8bc Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sat, 24 Nov 2018 22:28:29 +0530 Subject: [PATCH 1/7] added button --- activities/LastOneLoses.activity/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activities/LastOneLoses.activity/index.html b/activities/LastOneLoses.activity/index.html index 8133e7a7b..408ed3e20 100644 --- a/activities/LastOneLoses.activity/index.html +++ b/activities/LastOneLoses.activity/index.html @@ -32,7 +32,7 @@ - + From 510ba0b725938551e24ed6cf9fe8cd9876906929 Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sat, 24 Nov 2018 22:31:26 +0530 Subject: [PATCH 2/7] Update activity.css --- .../LastOneLoses.activity/css/activity.css | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/activities/LastOneLoses.activity/css/activity.css b/activities/LastOneLoses.activity/css/activity.css index 055505b80..a6129f878 100644 --- a/activities/LastOneLoses.activity/css/activity.css +++ b/activities/LastOneLoses.activity/css/activity.css @@ -25,6 +25,40 @@ background-image: url(../icons/switch-player.svg); } +#main-toolbar #network-button { + background-image: url(../lib/sugar-web/graphics/icons/actions/zoom-home.svg); +} + +#private-button { + background-image: url(../lib/sugar-web/graphics/icons/actions/zoom-home.svg); + width: 47px; + height: 47px; + margin: 4px 2px; + color: white; + color: transparent; + background-color: transparent; + background-position: center; + background-repeat: no-repeat; + background-size: contain; + border: 0; + border-radius: 5.5px; +} + +#shared-button { + background-image: url(../lib/sugar-web/graphics/icons/actions/zoom-neighborhood.svg); + width: 47px; + height: 47px; + margin: 4px 2px; + color: white; + color: transparent; + background-color: transparent; + background-position: center; + background-repeat: no-repeat; + background-size: contain; + border: 0; + border-radius: 5.5px; +} + @media screen and (max-width: 620px) { .toolbar { padding-left: 10px; From dba73483ae5b76446b226c18c058e36901f36f49 Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sat, 24 Nov 2018 22:42:36 +0530 Subject: [PATCH 3/7] Update activity.js --- activities/LastOneLoses.activity/js/activity.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/activities/LastOneLoses.activity/js/activity.js b/activities/LastOneLoses.activity/js/activity.js index f44601ea4..1a940b1d2 100644 --- a/activities/LastOneLoses.activity/js/activity.js +++ b/activities/LastOneLoses.activity/js/activity.js @@ -1,4 +1,7 @@ +define(["sugar-web/activity/activity", "sugar-web/env", "sugar-web/graphics/icon", "webL10n","sugar-web/graphics/presencepalette"], function (activity, env, icon, webL10n, presencepalette) { + // Link presence palette + var palette = new presencepalette.PresencePalette(document.getElementById("network-button"), undefined); define(["sugar-web/activity/activity", "sugar-web/graphics/radiobuttonsgroup"], function (activity, radioButtonsGroup) { var app; From ed4b1ddf44ec226080c508d8f893ae797cb671fc Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sun, 25 Nov 2018 10:15:27 +0530 Subject: [PATCH 4/7] Update activity.js --- activities/LastOneLoses.activity/js/activity.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/activities/LastOneLoses.activity/js/activity.js b/activities/LastOneLoses.activity/js/activity.js index 1a940b1d2..cbdeb623f 100644 --- a/activities/LastOneLoses.activity/js/activity.js +++ b/activities/LastOneLoses.activity/js/activity.js @@ -1,7 +1,22 @@ define(["sugar-web/activity/activity", "sugar-web/env", "sugar-web/graphics/icon", "webL10n","sugar-web/graphics/presencepalette"], function (activity, env, icon, webL10n, presencepalette) { // Link presence palette - var palette = new presencepalette.PresencePalette(document.getElementById("network-button"), undefined); + var presence = null; + var palette = new presencepalette.PresencePalette(document.getElementById("network-button"), undefined); + palette.addEventListener('shared', function() { + palette.popDown(); + console.log("Want to share"); + presence = activity.getPresenceObject(function(error, network) { + if (error) { + console.log("Sharing error"); + return; + } + network.createSharedActivity('org.sugarlabs.Pawn', function(groupId) { + console.log("Activity shared"); + }); + network.onDataReceived(onNetworkDataReceived); + }); + }); define(["sugar-web/activity/activity", "sugar-web/graphics/radiobuttonsgroup"], function (activity, radioButtonsGroup) { var app; From b25db6fb5bd81c5cbcf96576b1480453c5157b30 Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sun, 25 Nov 2018 10:19:31 +0530 Subject: [PATCH 5/7] Update activity.js --- activities/LastOneLoses.activity/js/activity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activities/LastOneLoses.activity/js/activity.js b/activities/LastOneLoses.activity/js/activity.js index cbdeb623f..0b9e5fed6 100644 --- a/activities/LastOneLoses.activity/js/activity.js +++ b/activities/LastOneLoses.activity/js/activity.js @@ -11,7 +11,7 @@ define(["sugar-web/activity/activity", "sugar-web/env", "sugar-web/graphics/icon console.log("Sharing error"); return; } - network.createSharedActivity('org.sugarlabs.Pawn', function(groupId) { + network.createSharedActivity('org.sugarlabs.LOL', function(groupId) { console.log("Activity shared"); }); network.onDataReceived(onNetworkDataReceived); From 746b88237cd9deb4354645dce924f16bb1eaaf03 Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sun, 25 Nov 2018 10:27:23 +0530 Subject: [PATCH 6/7] Update activity.js --- activities/LastOneLoses.activity/js/activity.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/activities/LastOneLoses.activity/js/activity.js b/activities/LastOneLoses.activity/js/activity.js index 0b9e5fed6..b16f23c48 100644 --- a/activities/LastOneLoses.activity/js/activity.js +++ b/activities/LastOneLoses.activity/js/activity.js @@ -17,6 +17,23 @@ define(["sugar-web/activity/activity", "sugar-web/env", "sugar-web/graphics/icon network.onDataReceived(onNetworkDataReceived); }); }); + + // Handle click on add + document.getElementById("add-button").addEventListener('click', function (event) { + + LOL.push(currentenv.user.colorvalue); + drawLOL(); + + document.getElementById("user").innerHTML = "

"+webL10n.get("Played", {name:currentenv.user.name})+"

"; + + if (presence) { + presence.sendMessage(presence.getSharedInfo().id, { + user: presence.getUserInfo(), + content: currentenv.user.colorvalue + }); + } + }); + define(["sugar-web/activity/activity", "sugar-web/graphics/radiobuttonsgroup"], function (activity, radioButtonsGroup) { var app; From 7f87cd916fa79d058095daa1cd391d421a21f6ea Mon Sep 17 00:00:00 2001 From: Mayank Kuthar <43777451+Kuthar8055@users.noreply.github.com> Date: Sun, 25 Nov 2018 10:58:58 +0530 Subject: [PATCH 7/7] Update activity.js --- .../LastOneLoses.activity/js/activity.js | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/activities/LastOneLoses.activity/js/activity.js b/activities/LastOneLoses.activity/js/activity.js index b16f23c48..30f92ab5c 100644 --- a/activities/LastOneLoses.activity/js/activity.js +++ b/activities/LastOneLoses.activity/js/activity.js @@ -34,6 +34,88 @@ define(["sugar-web/activity/activity", "sugar-web/env", "sugar-web/graphics/icon } }); + env.getEnvironment(function(err, environment) { + currentenv = environment; + + // Set current language to Sugarizer + ... + + // Load from datatore + if (!environment.objectId) { + ... + } + + // Shared instances + if (environment.sharedId) { + console.log("Shared instance"); + presence = activity.getPresenceObject(function(error, network) { + network.onDataReceived(onNetworkDataReceived); + }); + } + }); + + var onNetworkDataReceived = function(msg) { + if (presence.getUserInfo().networkId === msg.user.networkId) { + return; + } + switch (msg.content.action) { + case 'init': + LOL = msg.content.data; + drawLOL(); + break; + case 'update': + LOL.push(msg.content.data); + drawLOL(); + document.getElementById("user").innerHTML = "

"+webL10n.get("Played", {name:msg.user.name})+"

"; + break; + } + }; + + network.onSharedActivityUserChanged(onNetworkUserChanged); + + var onNetworkUserChanged = function(msg) { + console.log("User "+msg.user.name+" "+(msg.move == 1 ? "join": "leave")); + }; + + presence.sendMessage(presence.getSharedInfo().id, { + user: presence.getUserInfo(), + content: { + action: 'update', + data: currentenv.user.colorvalue + } + }); + + var onNetworkUserChanged = function(msg) { + if (isHost) { + presence.sendMessage(presence.getSharedInfo().id, { + user: presence.getUserInfo(), + content: { + action: 'init', + data: LOL + } + }); + } + console.log("User "+msg.user.name+" "+(msg.move == 1 ? "join": "leave")); + }; + + var isHost = false; + palette.addEventListener('shared', function() { + palette.popDown(); + console.log("Want to share"); + presence = activity.getPresenceObject(function(error, network) { + if (error) { + console.log("Sharing error"); + return; + } + network.createSharedActivity('org.sugarlabs.LOL', function(groupId) { + console.log("Activity shared"); + isHost = true; + }); + network.onDataReceived(onNetworkDataReceived); + network.onSharedActivityUserChanged(onNetworkUserChanged); + }); + }); + define(["sugar-web/activity/activity", "sugar-web/graphics/radiobuttonsgroup"], function (activity, radioButtonsGroup) { var app;