--------------------------------------------------------------------------
| 227 | |
| 228 | //-------------------------------------------------------------------------- |
| 229 | void ActionMap::dumpActionMap(const char* fileName, const bool append) const |
| 230 | { |
| 231 | if (fileName != NULL) { |
| 232 | // Dump the deletion, and creation script commands, followed by all the binds |
| 233 | // to a script. |
| 234 | |
| 235 | FileStream *iostrm; |
| 236 | if((iostrm = FileStream::createAndOpen( fileName, append ? Torque::FS::File::WriteAppend : Torque::FS::File::Write )) == NULL) |
| 237 | { |
| 238 | Con::errorf( "Unable to open file '%s' for writing.", fileName ); |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | char lineBuffer[1024]; |
| 243 | if ( append ) |
| 244 | iostrm->setPosition( iostrm->getStreamSize() ); |
| 245 | else |
| 246 | { |
| 247 | // IMPORTANT -- do NOT change the following line, it identifies the file as an input map file |
| 248 | dStrcpy( lineBuffer, "// Torque Input Map File\n", 1024 ); |
| 249 | iostrm->write( dStrlen( lineBuffer ), lineBuffer ); |
| 250 | } |
| 251 | |
| 252 | dSprintf(lineBuffer, 1024, "if (isObject(%s)) %s.delete();\n" |
| 253 | "new ActionMap(%s);\n", getName(), getName(), getName()); |
| 254 | iostrm->write(dStrlen(lineBuffer), lineBuffer); |
| 255 | |
| 256 | // Dump all the binds to the console... |
| 257 | for (S32 i = 0; i < mDeviceMaps.size(); i++) { |
| 258 | const DeviceMap* pDevMap = mDeviceMaps[i]; |
| 259 | |
| 260 | char devbuffer[32]; |
| 261 | getDeviceName(pDevMap->deviceType, pDevMap->deviceInst, devbuffer); |
| 262 | |
| 263 | for (S32 j = 0; j < pDevMap->nodeMap.size(); j++) { |
| 264 | const Node& rNode = pDevMap->nodeMap[j]; |
| 265 | |
| 266 | const char* pModifierString = getModifierString(rNode.modifiers); |
| 267 | |
| 268 | char objectbuffer[64]; |
| 269 | if (getKeyString(rNode.action, objectbuffer) == false) |
| 270 | continue; |
| 271 | |
| 272 | const char* command; |
| 273 | if (rNode.flags & Node::BindCmd) |
| 274 | command = "bindCmd"; |
| 275 | else if (rNode.flags & Node::Held) |
| 276 | command = "held"; |
| 277 | else |
| 278 | command = "bind"; |
| 279 | |
| 280 | dSprintf(lineBuffer, 1024, "%s.%s(%s, \"%s%s\"", |
| 281 | getName(), |
| 282 | command, |
| 283 | devbuffer, |
| 284 | pModifierString, objectbuffer); |
| 285 | |
| 286 | if (rNode.flags & (Node::HasScale|Node::HasDeadZone|Node::Ranged|Node::Inverted)) { |
no test coverage detected