The Sandbox Option

Discussion in 'Mod Discussions' started by wondible, April 15, 2015.

  1. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    On further thought change control and vision are tricky because the game uses them for regular single-player control, with the expectation that the server will stop any funny business. So if they get hooked, it's going to have to calculate the allowed values and check against that.

    Meanwhile: live game model.gameOptions is a non-observable which gets wholesale replaced when new options come in. So in order for a mod to discover the sandbox state, it either has to poll or hook the server_state message. I'm going to see if there is another observable value which gets set at the same time as the game options.
  2. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    Current patch for sandbox unit toolbox and company:

    Code:
    (function() {
      if (!model['serverSandboxState']) {
        model.serverSandboxState = ko.observable(false)
        model.serverSandboxState.subscribe(model.cheatAllowCreateUnit)
        model.serverSandboxState.subscribe(model.cheatAllowChangeVision)
        model.serverSandboxState.subscribe(model.cheatAllowChangeControl)
    
        var live_game_server_state = handlers.server_state
        handlers.server_state = function(msg) {
          live_game_server_state.apply(this, arguments)
    
          if (msg.data && msg.data.client && msg.data.client.game_options) {
            model.serverSandboxState(!!msg.data.client.game_options.sandbox)
          }
        }
      }
    })()
    
  3. crizmess

    crizmess Well-Known Member

    Messages:
    434
    Likes Received:
    317
    Just because I saw this here.
    I've been out of the loop on javascript for a few years now. Is it now common to omit the semicolon in javascript? I know that the specification doesn't require that semicolon, there is the automatic semicolon insertion (§7.4, §7.9.1) but I always perceived this mechanism as a source of more confusion, than to be helpful.
    Last edited: April 16, 2015
  4. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,084
    It's still a point of debate and one of the linters defaults to enforcing it. I've decided I prefer fewer characters. The only issue I've run into is mysterious errors because the next line starts with a parenthesized expression that gets parsed as an unwanted function call.

Share This Page