-
-
Save serverglitch/36d47ff41bcf8d6d45dc8c13a100c5ab to your computer and use it in GitHub Desktop.
Open Scenes Hack
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
// ares-webportal/app/controllers/scenes-open.js | |
import Controller from '@ember/controller'; | |
import { inject as service } from '@ember/service'; | |
import AuthenticatedController from 'ares-webportal/mixins/authenticated-controller'; | |
export default Controller.extend(AuthenticatedController, { | |
gameApi: service(), | |
gameSocket: service(), | |
flashMessages: service(), | |
newActivity: false, | |
onSceneActivity: function (type, msg, timestamp) { | |
let splitMsg = msg.split('|'); | |
let sceneId = splitMsg[0]; | |
let lastPosed = splitMsg[1]; | |
let model = this.get('model.active'); | |
model.forEach((s, i) => { | |
if (s.id === sceneId) { | |
this.set(`model.active.${i}.is_unread`, true); | |
this.set(`model.active.${i}.updated`, timestamp); | |
this.set(`model.active.${i}.last_posed`, lastPosed); | |
} | |
}); | |
}, | |
resetOnExit: function () { | |
this.set('newActivity', false); | |
}, | |
setupCallback: function () { | |
let self = this; | |
this.gameSocket.setupCallback( | |
'new_scene_activity', | |
function (type, msg, timestamp) { | |
self.onSceneActivity(type, msg, timestamp); | |
} | |
); | |
}, | |
actions: { | |
refresh() { | |
this.set('newActivity', false); | |
this.send('reloadModel'); | |
}, | |
joinScene(id) { | |
let api = this.gameApi; | |
api.requestOne('joinScene', { id: id }, null).then((response) => { | |
if (response.error) { | |
return; | |
} | |
this.flashMessages.success('You join the scene.'); | |
this.send('reloadModel'); | |
}); | |
}, | |
stopWatching(id) { | |
let api = this.gameApi; | |
api.requestOne('unwatchScene', { id: id }, null).then((response) => { | |
if (response.error) { | |
return; | |
} | |
this.flashMessages.success('You are no longer watching that scene.'); | |
this.send('reloadModel'); | |
}); | |
}, | |
watchScene(id) { | |
let api = this.gameApi; | |
api.requestOne('watchScene', { id: id }, null).then((response) => { | |
if (response.error) { | |
return; | |
} | |
this.flashMessages.success('You start watching that scene.'); | |
this.send('reloadModel'); | |
}); | |
}, | |
}, | |
}); |
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
# aresmush/plugins/scenes/web/open_scenes_handler.rb | |
module AresMUSH | |
module Scenes | |
class OpenScenesRequestHandler | |
def handle(request) | |
enactor = request.enactor | |
error = Website.check_login(request, true) | |
return error if error | |
open_scenes = Scene.all.select { |s| !s.completed && Scenes.can_read_scene?(enactor, s) } | |
.sort { |s1, s2| sort_scene(s1, s2, enactor) } | |
.map { |s| scene_data(s, enactor) } | |
if (enactor) | |
unshared = enactor.unshared_scenes.sort_by { |s| s.id.to_i }.reverse.map { |s| { | |
title: s.date_title, | |
people: s.participant_names.join(' '), | |
id: s.id }} | |
else | |
unshared = nil | |
end | |
{ | |
active: open_scenes, | |
unshared: unshared, | |
unshared_deletion_days: Global.read_config('scenes', 'unshared_scene_deletion_days') | |
} | |
end | |
def scene_data(s, enactor) | |
{ | |
id: s.id, | |
title: s.title, | |
summary: (can_read?(enactor, s) && !s.summary.blank?) ? Website.format_markdown_for_html(s.summary) : nil, | |
content_warning: s.content_warning, | |
limit: s.limit, | |
location: Scenes.can_read_scene?(enactor, s) ? s.location : t('scenes.private'), | |
icdate: s.icdate, | |
can_view: enactor && Scenes.can_read_scene?(enactor, s), | |
is_private: s.private_scene, | |
participants: Scenes.participants_and_room_chars(s) | |
.select { |p| !p.who_hidden } | |
.sort_by { |p| p.name } | |
.map { |p| { | |
name: p.name, | |
nick: p.nick, | |
id: p.id, | |
icon: Website.icon_for_char(p), | |
status: Website.activity_status(p), | |
online: Login.is_online?(p), | |
last_posed: s.last_posed == p }}, | |
scene_type: s.scene_type ? s.scene_type.titlecase : 'Unknown', | |
scene_pacing: s.scene_pacing, | |
likes: s.likes, | |
is_unread: can_read?(enactor, s) && enactor && s.participants.include?(enactor) && s.is_unread?(enactor), | |
updated: can_read?(enactor, s) ? OOCTime.local_long_timestr(enactor, s.last_activity) : nil, | |
watching: Scenes.is_watching?(s, enactor), | |
participating: Scenes.is_participant?(s, enactor), | |
last_posed: can_read?(enactor, s) && s.last_posed ? s.last_posed.name : nil, | |
last_pose_time_str: s.last_pose_time_str(enactor) | |
} | |
end | |
def can_read?(enactor, s) | |
Scenes.can_read_scene?(enactor, s) | |
end | |
def sort_scene(s1, s2, enactor) | |
if (Scenes.is_participant?(s2, enactor) && !Scenes.is_participant?(s1, enactor)) | |
return 1 | |
end | |
if (Scenes.is_participant?(s1, enactor) && !Scenes.is_participant?(s2, enactor)) | |
return -1 | |
end | |
if (!s1.private_scene && s2.private_scene) | |
return -1 | |
end | |
if (s1.private_scene && !s2.private_scene) | |
return 1 | |
end | |
if (s1.updated_at < s2.updated_at) | |
return 1 | |
end | |
if (s2.updated_at < s1.updated_at) | |
return -1 | |
end | |
return 0 | |
end | |
end | |
end | |
end |
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
// ares-webportal/app/routes/scenes-open.js | |
import Route from '@ember/routing/route'; | |
import { inject as service } from '@ember/service'; | |
import DefaultRoute from 'ares-webportal/mixins/default-route'; | |
import ReloadableRoute from 'ares-webportal/mixins/reloadable-route'; | |
import RouteResetOnExit from 'ares-webportal/mixins/route-reset-on-exit'; | |
export default Route.extend(DefaultRoute, ReloadableRoute, RouteResetOnExit, { | |
gameApi: service(), | |
gameSocket: service(), | |
activate: function () { | |
this.controllerFor('scenes-open').setupCallback(); | |
}, | |
deactivate: function () { | |
this.gameSocket.removeCallback('new_scene_activity'); | |
}, | |
model: function () { | |
let api = this.gameApi; | |
return api.requestOne('openScenes'); | |
}, | |
}); |
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
// ares-webportal/app/router.js | |
... | |
this.route('scenes-open'); | |
... |
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
# aresmush/plugins/scenes/scenes.rb | |
... | |
when "openScenes" | |
return OpenScenesRequestHandler | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment