[WIP] Replay Script

Discussion in 'Mod Discussions' started by trialq, May 6, 2014.

  1. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    The initial idea is to be able to add timed text to a replay, just like subtitles on a video. The vague title is because it could quite easily morph into a more complicated setup, like specifying that the camera should be in a certain place at a certain time so important events are not missed. Other additions are possible, with various levels of pipedream associated with them ;)

    If non-live casts ever take off (I assume they will in years to come, maybe not during the lifetime of this mod but meh), creating a script beforehand could allow you to avoid missing important events, add additional information you don't want to verbalise, or even allow you to do really polished camera work completely separately from the commentating (this would require some fancy camera functions, captain conundrum is working on some functions which are the sort of thing I'm talking about, here).

    I've done the groundwork, an initial version (with text only probably) may be around in about a week. I'm without a working pa for a little while, but may still release some dev versions throughout the week. These are very unlikely to work, but if someone wants to test them and send screenshots of the coherent debugger errors, that would help speed things along slightly. That's the best way to develop right? :p
  2. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    First untested release, v0.1-dev. Can someone test this and let me know what fails, it prints stuff to console. To test it, enable the mod and try loading this replay: http://www.pastats.com/replay/5253874604877805635

    • The mod will probably not load properly, check coherent debugger for errors
    • Capturing the lobbyid probably failed, it should be the same as the number in the above link
    • It will try to load json via ajax, this is the script. It will probably fail
    • The update function should be called every half second, determine what needs to be displayed, and update the display. The text it is trying to display will be shown in the console in case the ui does not work properly. It will probably fail
    • Even if the ui works, it will look crap because it has no styling
    • Text should be displayed at ~0, ~5 and ~120 seconds. It will probably fail
    • The text at time 0 should display until the text at time 5 takes over
    • The text at time 5 should display for ~10 seconds
    • The text at time 120 should display for ~3 seconds
    • If by magic all previous stuff has worked, try breaking the display of the text (like scrubbing back from 30 seconds to 8 seconds and seeing if the text is displayed when it should be, playing in reverse etc)

    Can you send a screenshot of the debugger console please, and a screenshot of text in the ui if it works.

    Attached Files:

    cptconundrum and Raevn like this.
  3. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    You forgot to mention it will probably fail.
    mishtakashi, cola_colin and Gorbles like this.
  4. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    LavaSnake likes this.
  5. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    The format of the script files has been made to accommodate different types of data point (other than just text), in a way that should be quickest to process. An example:
    Code:
    {
    "lobbyId":5253874604877805635,
    "author":"trialq",
    "text":[
    {"t":0,"v":"This should be displayed at time 0"},
    {"t":5,"v":"Displayed at 5 seconds, for longer than the text displayed at time 0, as it's longer"},
    {"t":30, "v":"30 seconds in. A web page should also be displayed"},
    {"t":120.23,"v":"2 minutes in"}
    ],
    "url":[
    {"t":30,"v":"http://pa-mods.com/replay.php?lobbyid=5253874604877805635"},
    {"t":60, "v":"http://duckduckgo.com"}
    ],
    "some_data_type":[
    {"t":10,"some_field":"field_value","some_other_field":"another value"}
    ]
    }
    • Every data point has a time value, and any number of fields. The data points are pre-sorted, so the arrays can be binary searched.
      At the minute the arrays are searched every time there is an update. This isn't a problem for small arrays, and I doubt it is for large arrays either. If it ever is a problem, implementing tracking recent time values to determine whether we're playing through or scrubbing can minimise searching.
    • Url support will be optional. If the user has the browser mod enabled they will work, but it isn't required to enable this mod
      This mods priority will have to be set such that the browser mod loads before it, so this mod can check for the existence of that one.
    • Camera tracking will be the next thing
    • At the minute the mod polls every half second with setInterval, to update everything
    • Adding new data types like camera tracking is as easy as adding an array format to the json spec, a function to handle the array format and do what it says, and updating the update function to call the function.

    If you notice anything you think should or could be done better, or an assumption I've made is wrong, let me know. How about what different types of data could be added? Currently there's text, url and camera planned, I haven't investigated whether pip is possible yet.

    Haven't thought too much about how users will create scripts, maybe a creator mode or separate creator mod. At first glance it needs to have something like:
    • Press a button when at a certain time to say 'I want to do something here'
    • Drop down to select the action
    • Do whatever is needed to capture the action (a text box for text or url, a button to capture the cameras position, etc)
    • All data points are presented in an ordered list, which the user can select and delete
    • A save mode, to a server or perhaps locally

    Which reminds me, saving locally should be implemented somehow, probably a copy-paste thing in the creator section. Is there a way to automate github submission? Don't know how comfortable I am with allowing arbitrary automatic data submission to my server, or how well it would take it anyway. If it's possible, github or something like that that could be community maintained would be a good choice.
  6. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    A new dev version is attached, v0.2-dev. Now with added audio support.
    • Text and url support should be working
    • Binary search instead of linear
    • Audio support is rudimentary
    • Url and audio events should not be triggered when going backwards, but currently will be triggered when skipping or playing forwards at weird speeds (will try and detect those cases too)
    • Nothing is done for audio besides triggering a play event when going forwards. If you pause the replay it will not pause any playing audio.To get rough sync between audio and replay allowing pause, split audio into chunks. This seems like reasonable behaviour (lots of audio files when used to annotate a replay, a single audio file when used to cast a replay), certainly the laziest way to do it
    • Audio is queued to load in the order specified in the script, aka the order it will be played. But it may just try to load everything at once
    • If the audio file fails to load, or hasn't loaded by the time we want it, it will just not play. The replay should continue regardless

    Audio is specified similar to the others described above, specifying the source url:
    Code:
     "audio":[
    {"t":40,"v":"http://www.opus-codec.org/examples/sweep.wav"},
    {"t":60,"v":"http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-64.opus"}
    ]
    If there's any mis-steps you think this mod is taking, let me know what they are and how you'd fix them. Anyone can test this by enabling the mod, and trying the following replay: http://www.pastats.com/chart?gameId=93208
    Notes for testing:
    • All testing bullet points for the previous version apply here
    • A 15 second wav file should start playing at time 40. This is to test the code
    • A 3+ minute opus file should start playing at time 60. This is to test format support

    I was thinking a good way to add support for multiple scripts per replay would be to look in multiple locations. Currently it looks in a single place:
    Code:
    http://pa-mods.com/replay.php?lobbyid=<lobbyid>
    • There could be an online list of public repositories
    • And a way for a user to add their own repository locally (url saved in local storage)
    • By default there could be a coui: repository, effectively giving players their own private repository to make replay scripts in
    • If someone wanted their server to offer multiple replay scripts, they would just use multiple repository locations, such as 'server.com/1/replay?lobby=<lobbyid>', 'server.com/2/replay?lobby=<lobbyid>', 'server.com/3/replay?lobby=<lobbyid>' etc

    This version will definitely work, there are no errors. It will do your taxes when you're not looking, and feed the dog.

    Attached Files:

    Fr33Lancer and LavaSnake like this.
  7. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Wow, this is really turning into an epic mod. Great work!
  8. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    I'm back with a copy of PA, and managed to unbreak the mod. It's still an early wip, so it's hardcoded to load the test script all the time. You could test it, but it doesn't do much more than the video shows yet (if you do try it, make sure you don't play any live games with the mod enabled, hardcoding broke the 'am i in a replay' logic).



    v0.3-dev has no new features, it just gets the existing ones working, poorly :p

    edit: Here's the script the video follows:
    Code:
    {
       "lobbyId":10099842292382001623,
       "author":"trialq",
       "text":[
         {"t":0,"v":"This should be displayed at time 0"},
         {"t":5,"v":"Displayed at 5 seconds"},
         {"t":10,"v":"10 seconds in. A web page is displayed if the inGameBrowser mod is enabled"},
         {"t":20.23,"v":"20 seconds in, a wav file is played"},
         {"t":35,"v":"35 seconds in, an ogg file is played"}
       ],
       "url":[
         {"t":10,"v":"http://pa-mods.com/replay.php?lobbyid=10099842292382001623"}
       ],
       "audio":[
         {"t":20,"v":"http://www.opus-codec.org/examples/sweep.wav"},
         {"t":35,"v":"http://upload.wikimedia.org/wikipedia/commons/b/bd/Rondo_Alla_Turka.ogg"}
       ]
    }
    

    Attached Files:

    emraldis likes this.

Share This Page