-
-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve LOL activity to play against another user using presence #252
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a55edc6
added button
Kuthar8055 510ba0b
Update activity.css
Kuthar8055 dba7348
Update activity.js
Kuthar8055 ed4b1dd
Update activity.js
Kuthar8055 b25db6f
Update activity.js
Kuthar8055 746b882
Update activity.js
Kuthar8055 7f87cd9
Update activity.js
Kuthar8055 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,121 @@ | ||
|
||
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 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.LOL', function(groupId) { | ||
console.log("Activity shared"); | ||
}); | ||
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 = "<h1>"+webL10n.get("Played", {name:currentenv.user.name})+"</h1>"; | ||
|
||
if (presence) { | ||
presence.sendMessage(presence.getSharedInfo().id, { | ||
user: presence.getUserInfo(), | ||
content: currentenv.user.colorvalue | ||
}); | ||
} | ||
}); | ||
|
||
env.getEnvironment(function(err, environment) { | ||
currentenv = environment; | ||
|
||
// Set current language to Sugarizer | ||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't work. Something is missing here. |
||
|
||
// Load from datatore | ||
if (!environment.objectId) { | ||
... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't work. Something is missing here. |
||
} | ||
|
||
// 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 = "<h1>"+webL10n.get("Played", {name:msg.user.name})+"</h1>"; | ||
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; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function don't exist.