if ($i == count($buttons) - 1) {
        echo "      }\n\n";
    } else {
        echo "      },\n\n";
    }
}
// end foreach buttons...
// Close the switches
echo "    },\n\n\n";
// #############################################
// #############################################
// DEFAULT STATES
echo "    \"fields\":\n";
echo "    {\n";
// Get the switches for this button
$switches = getSwitches($dbMapID, 0);
// Initialize a counter since we have to differentiate
// commas in certain lines
$i = 0;
// Step through the button switches
foreach ($switches as $CellID => $DefaultState) {
    // Get the position
    $posXY = getCellXY($CellID, true);
    if ($i == count($switches) - 1) {
        echo "      \"" . $posXY['x'] . "," . $posXY['y'] . "\": { \"defaultState\": \"{$DefaultState}\" }\n";
    } else {
        echo "      \"" . $posXY['x'] . "," . $posXY['y'] . "\": { \"defaultState\": \"{$DefaultState}\" },\n";
    }
    // Increment the counter
    $i++;
}
Esempio n. 2
0
<?php

define('SWITCH_CACHE', __DIR__ . '/switches.json');
require './orvfms/orvfms.php';
$cmd = $argv[1];
function getSwitches($refresh = false)
{
    if ($refresh || !file_exists(SWITCH_CACHE)) {
        $switches = initS20Data();
        file_put_contents(SWITCH_CACHE, json_encode($switches));
    } else {
        $switches = json_decode(file_get_contents(SWITCH_CACHE), $assoc = true);
    }
    return $switches;
}
switch ($cmd) {
    case 'list':
        echo json_encode(getSwitches());
        break;
    case 'on':
        $switchId = $argv[2];
        $switches = getSwitches();
        actionAndCheck($switchId, 1, $switches);
        break;
    case 'off':
        $switchId = $argv[2];
        $switches = getSwitches();
        actionAndCheck($switchId, 0, $switches);
        break;
}
Esempio n. 3
0
 $switches = getSwitches($dbMapID, $ButtonID, 'grate');
 // Initialize an identifier to control commas
 $j = 0;
 foreach ($switches as $CellID => $defaultState) {
     // If this is the first element, do not inject a comma
     // otherwise we will
     if ($j == 0) {
         $switchString .= "{$CellID}";
     } else {
         $switchString .= ",{$CellID}";
     }
     // Increment the comma controller
     $j++;
 }
 // Get the bombs and step through them for this button
 $bombs = getSwitches($dbMapID, $ButtonID, 'bomb');
 // Initialize an identifier to control commas
 $j = 0;
 foreach ($bombs as $CellID => $defaultState) {
     // If this is the first element, do not inject a comma
     // otherwise we will
     if ($j == 0) {
         $bombString .= "{$CellID}";
     } else {
         $bombString .= ",{$CellID}";
     }
     // Increment the comma controller
     $j++;
 }
 // Close out this button's object lsting
 $switchString .= "]";