901 lines
29 KiB
HTML
901 lines
29 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Cimdit Profile generator</title>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<style type="text/css">
|
|
textarea{width:100%}#string{height:5vh}.codeEditor,.lineCounter{font-family:courier new, courier, monospace;margin:0;padding:10px 0;height:75vh;border-radius:0;resize:none;line-height:1.2;outline:none;box-sizing:border-box}.codeEditor{padding-left:calc(3.5rem + 5px);width:100%;background-color:#272822;border-color:#272822;color:#ffffff}.lineCounter{display:flex;border-color:transparent;overflow-y:hidden;text-align:right;box-shadow:none;color:#707070;background-color:#d8d8d8;position:absolute;width:3.5rem;background-color:#3E3D32;border-color:#3E3D32;color:#928869}.lineCounter:focus-visible,.codeEditor:focus-visible{outline:none}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<form><div>
|
|
<textarea id="jsoncounter" class="lineCounter" wrap="off" readonly>1</textarea>
|
|
<textarea id="json" class="codeEditor" wrap="off">
|
|
[
|
|
{
|
|
"name": "Joystick",
|
|
"customimage": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007FFFFFFC000000000000000000000001FFFFFFFF800000000000000000000003FFFFFFFFC00000000000000000000007FFFFFFFFE0000000000000000000000FE0000007F0000000000000000000001F80000001F8000000000000000000001F1A000000F8000000000000000000003E1E00000E7C000000000000000000003E1E00001F7C000000000000000000003C5F80001F3C000000000000000000003CFFC0000E3C000000000000000000003CFFC000E03C000000000000000000003C7F0001E07C000000000000000000003E1E0000F07C000000000000000000003E1E1FF8E078000000000000000000001F143FFC00F8000000000000000000001F807FFE01F8000000000000000000000FD1FFFF87F00000000000000000000007FFF81FFFE00000000000000000000003FFF00FFFC00000000000000000000001FFE007FF8000000000000000000000007F8001FE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
"mappedbuttons": [
|
|
{
|
|
"source": 20,
|
|
"type": "JOYSTICK_BUTTON",
|
|
"target": 1
|
|
},
|
|
{
|
|
"source": 62,
|
|
"type": "SWITCH_PROFILE"
|
|
},
|
|
{
|
|
"source": 61,
|
|
"type": "MACRO_PRESS",
|
|
"macro": 0
|
|
},
|
|
{
|
|
"source": 60,
|
|
"type": "MACRO_PRESS",
|
|
"macro": 1
|
|
},
|
|
{
|
|
"source": 59,
|
|
"type": "MACRO_PRESS",
|
|
"macro": 2
|
|
},
|
|
{
|
|
"source": 59,
|
|
"type": "MACRO_RELEASE",
|
|
"macro": 3
|
|
},
|
|
{
|
|
"source": 58,
|
|
"type": "MACRO_PRESS",
|
|
"macro": 4
|
|
},
|
|
{
|
|
"source": 58,
|
|
"type": "MACRO_RELEASE",
|
|
"macro": 5
|
|
},
|
|
{
|
|
"source": 50,
|
|
"type": "KEYBOARD_BUTTON",
|
|
"target": "KEY_0"
|
|
}
|
|
],
|
|
"mappedaxis": [
|
|
{
|
|
"source": 0,
|
|
"type": "JOYSTICK_AXIS",
|
|
"axis": 1
|
|
},
|
|
{
|
|
"source": 1,
|
|
"type": "JOYSTICK_AXIS",
|
|
"axis": 2
|
|
},
|
|
{
|
|
"source": 2,
|
|
"type": "JOYSTICK_AXIS",
|
|
"axis": 3
|
|
},
|
|
{
|
|
"source": 3,
|
|
"type": "JOYSTICK_AXIS",
|
|
"axis": 4
|
|
}
|
|
],
|
|
"mappedrotary": [
|
|
{
|
|
"source": 0,
|
|
"type": "PREV_PROFILE"
|
|
},
|
|
{
|
|
"source": 1,
|
|
"type": "NEXT_PROFILE"
|
|
}
|
|
],
|
|
"macros": [
|
|
[
|
|
"MACRO_SPEED",
|
|
10,
|
|
"MACRO_TYPE",
|
|
"test"
|
|
],
|
|
[
|
|
"MACRO_SPEED",
|
|
10,
|
|
"MACRO_KEY_PRESS",
|
|
"KEY_LEFT_SHIFT",
|
|
"t",
|
|
"MACRO_KEY_RELEASE",
|
|
"t",
|
|
"KEY_LEFT_SHIFT",
|
|
"MACRO_TYPE",
|
|
"est"
|
|
],
|
|
[
|
|
"MACRO_SPEED",
|
|
10,
|
|
"MACRO_TYPE",
|
|
"te",
|
|
"MACRO_JOY_PRESS",
|
|
2,
|
|
"MACRO_DELAY",
|
|
2000,
|
|
"MACRO_JOY_RELEASE",
|
|
2,
|
|
"MACRO_TYPE",
|
|
"s"
|
|
],
|
|
[
|
|
"MACRO_TYPE",
|
|
"t"
|
|
],
|
|
[
|
|
"MACRO_MOUSE_PRESS",
|
|
2,
|
|
"MACRO_KEY_PRESS",
|
|
"KEY_LEFT_SHIFT",
|
|
"MACRO_MOUSE_REL_X_AXIS",
|
|
0,
|
|
5,
|
|
"MACRO_MOUSE_REL_Y_AXIS",
|
|
1,
|
|
5
|
|
],
|
|
[
|
|
"MACRO_MOUSE_REL_X_AXIS",
|
|
-1,
|
|
"MACRO_MOUSE_REL_Y_AXIS",
|
|
-1,
|
|
"MACRO_KEY_RELEASE",
|
|
"KEY_LEFT_SHIFT",
|
|
"MACRO_MOUSE_RELEASE",
|
|
2
|
|
]
|
|
]
|
|
},
|
|
{
|
|
"name": "Mouse",
|
|
"mappedbuttons": [
|
|
{
|
|
"source": 62,
|
|
"type": "SWITCH_PROFILE"
|
|
},
|
|
{
|
|
"source": 15,
|
|
"type": "MOUSE_REL_X_AXIS",
|
|
"value": 25
|
|
},
|
|
{
|
|
"source": 23,
|
|
"type": "MOUSE_REL_Y_AXIS",
|
|
"value": -25
|
|
}
|
|
],
|
|
"mappedaxis": [
|
|
{
|
|
"source": 0,
|
|
"type": "MOUSE_REL_X_AXIS",
|
|
"value": 50
|
|
},
|
|
{
|
|
"source": 1,
|
|
"type": "MOUSE_REL_Y_AXIS",
|
|
"value": 50
|
|
}
|
|
],
|
|
"mappedrotary": [
|
|
{
|
|
"source": 0,
|
|
"type": "PREV_PROFILE"
|
|
},
|
|
{
|
|
"source": 1,
|
|
"type": "NEXT_PROFILE"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
</textarea>
|
|
<p><button id="generatestring" class="button">Generate String</button></p>
|
|
<p id="error"></p>
|
|
<textarea id="string"></textarea>
|
|
<p><button id="generatejson" class="button">Generate Json</button></p>
|
|
</div></form>
|
|
<script type="text/javascript">
|
|
document.addEventListener("readystatechange", function (event) {
|
|
if (!window.pg) {
|
|
window.pg = new ProfileGenerator();
|
|
}
|
|
});
|
|
|
|
var ProfileGenerator = (function () {
|
|
function ProfileGenerator() {
|
|
var _this = this;
|
|
this.profileEnum = [
|
|
"MAPPING_NONE",
|
|
"JOYSTICK_BUTTON",
|
|
"JOYSTICK_AXIS",
|
|
"MOUSE_BUTTON",
|
|
"MOUSE_REL_X_AXIS",
|
|
"MOUSE_REL_Y_AXIS",
|
|
"MOUSE_REL_WHEEL",
|
|
"NEXT_PROFILE",
|
|
"PREV_PROFILE",
|
|
"SWITCH_PROFILE",
|
|
"MACRO_PRESS",
|
|
"MACRO_RELEASE",
|
|
"KEYBOARD_BUTTON",
|
|
];
|
|
this.macroEnum = [
|
|
"MACRO_NULL",
|
|
"MACRO_SPEED",
|
|
"MACRO_DELAY",
|
|
"MACRO_KEY_PRESS",
|
|
"MACRO_KEY_RELEASE",
|
|
"MACRO_JOY_PRESS",
|
|
"MACRO_JOY_RELEASE",
|
|
"MACRO_MOUSE_PRESS",
|
|
"MACRO_MOUSE_RELEASE",
|
|
"MACRO_MOUSE_WHEEL",
|
|
"MACRO_TYPE",
|
|
"MACRO_MOUSE_REL_X",
|
|
"MACRO_MOUSE_REL_Y",
|
|
"MACRO_MOUSE_REL_X_AXIS",
|
|
"MACRO_MOUSE_REL_Y_AXIS"
|
|
];
|
|
this.keyLookup = {
|
|
"KEY_RESERVED": 0,
|
|
"KEY_ERROR_ROLLOVER": 1,
|
|
"KEY_POST_FAIL": 2,
|
|
"KEY_ERROR_UNDEFINED": 3,
|
|
"KEY_A": 4,
|
|
"KEY_B": 5,
|
|
"KEY_C": 6,
|
|
"KEY_D": 7,
|
|
"KEY_E": 8,
|
|
"KEY_F": 9,
|
|
"KEY_G": 10,
|
|
"KEY_H": 11,
|
|
"KEY_I": 12,
|
|
"KEY_J": 13,
|
|
"KEY_K": 14,
|
|
"KEY_L": 15,
|
|
"KEY_M": 16,
|
|
"KEY_N": 17,
|
|
"KEY_O": 18,
|
|
"KEY_P": 19,
|
|
"KEY_Q": 20,
|
|
"KEY_R": 21,
|
|
"KEY_S": 22,
|
|
"KEY_T": 23,
|
|
"KEY_U": 24,
|
|
"KEY_V": 25,
|
|
"KEY_W": 26,
|
|
"KEY_X": 27,
|
|
"KEY_Y": 28,
|
|
"KEY_Z": 29,
|
|
"KEY_1": 30,
|
|
"KEY_2": 31,
|
|
"KEY_3": 32,
|
|
"KEY_4": 33,
|
|
"KEY_5": 34,
|
|
"KEY_6": 35,
|
|
"KEY_7": 36,
|
|
"KEY_8": 37,
|
|
"KEY_9": 38,
|
|
"KEY_0": 39,
|
|
"KEY_ENTER": 40,
|
|
"KEY_RETURN": 40,
|
|
"KEY_ESC": 41,
|
|
"KEY_BACKSPACE": 42,
|
|
"KEY_TAB": 43,
|
|
"KEY_SPACE": 44,
|
|
"KEY_MINUS": 45,
|
|
"KEY_EQUAL": 46,
|
|
"KEY_LEFT_BRACE": 47,
|
|
"KEY_RIGHT_BRACE": 48,
|
|
"KEY_BACKSLASH": 49,
|
|
"KEY_NON_US_NUM": 50,
|
|
"KEY_SEMICOLON": 51,
|
|
"KEY_QUOTE": 52,
|
|
"KEY_TILDE": 53,
|
|
"KEY_COMMA": 54,
|
|
"KEY_PERIOD": 55,
|
|
"KEY_SLASH": 56,
|
|
"KEY_CAPS_LOCK": 0x39,
|
|
"KEY_F1": 0x3A,
|
|
"KEY_F2": 0x3B,
|
|
"KEY_F3": 0x3C,
|
|
"KEY_F4": 0x3D,
|
|
"KEY_F5": 0x3E,
|
|
"KEY_F6": 0x3F,
|
|
"KEY_F7": 0x40,
|
|
"KEY_F8": 0x41,
|
|
"KEY_F9": 0x42,
|
|
"KEY_F10": 0x43,
|
|
"KEY_F11": 0x44,
|
|
"KEY_F12": 0x45,
|
|
"KEY_PRINT": 0x46,
|
|
"KEY_PRINTSCREEN": 0x46,
|
|
"KEY_SCROLL_LOCK": 0x47,
|
|
"KEY_PAUSE": 0x48,
|
|
"KEY_INSERT": 0x49,
|
|
"KEY_HOME": 0x4A,
|
|
"KEY_PAGE_UP": 0x4B,
|
|
"KEY_DELETE": 0x4C,
|
|
"KEY_END": 0x4D,
|
|
"KEY_PAGE_DOWN": 0x4E,
|
|
"KEY_RIGHT_ARROW": 0x4F,
|
|
"KEY_LEFT_ARROW": 0x50,
|
|
"KEY_DOWN_ARROW": 0x51,
|
|
"KEY_UP_ARROW": 0x52,
|
|
"KEY_RIGHT": 0x4F,
|
|
"KEY_LEFT": 0x50,
|
|
"KEY_DOWN": 0x51,
|
|
"KEY_UP": 0x52,
|
|
"KEY_NUM_LOCK": 0x53,
|
|
"KEYPAD_DIVIDE": 0x54,
|
|
"KEYPAD_MULTIPLY": 0x55,
|
|
"KEYPAD_SUBTRACT": 0x56,
|
|
"KEYPAD_ADD": 0x57,
|
|
"KEYPAD_ENTER": 0x58,
|
|
"KEYPAD_1": 0x59,
|
|
"KEYPAD_2": 0x5A,
|
|
"KEYPAD_3": 0x5B,
|
|
"KEYPAD_4": 0x5C,
|
|
"KEYPAD_5": 0x5D,
|
|
"KEYPAD_6": 0x5E,
|
|
"KEYPAD_7": 0x5F,
|
|
"KEYPAD_8": 0x60,
|
|
"KEYPAD_9": 0x61,
|
|
"KEYPAD_0": 0x62,
|
|
"KEYPAD_DOT": 0x63,
|
|
"KEY_NON_US": 0x64,
|
|
"KEY_APPLICATION": 0x65,
|
|
"KEY_MENU": 0x65,
|
|
"KEY_POWER": 0x66,
|
|
"KEY_PAD_EQUALS": 0x67,
|
|
"KEY_F13": 0x68,
|
|
"KEY_F14": 0x69,
|
|
"KEY_F15": 0x6A,
|
|
"KEY_F16": 0x6B,
|
|
"KEY_F17": 0x6C,
|
|
"KEY_F18": 0x6D,
|
|
"KEY_F19": 0x6E,
|
|
"KEY_F20": 0x6F,
|
|
"KEY_F21": 0x70,
|
|
"KEY_F22": 0x71,
|
|
"KEY_F23": 0x72,
|
|
"KEY_F24": 0x73,
|
|
"KEY_EXECUTE": 0x74,
|
|
"KEY_HELP": 0x75,
|
|
"KEY_MENU2": 0x76,
|
|
"KEY_SELECT": 0x77,
|
|
"KEY_STOP": 0x78,
|
|
"KEY_AGAIN": 0x79,
|
|
"KEY_UNDO": 0x7A,
|
|
"KEY_CUT": 0x7B,
|
|
"KEY_COPY": 0x7C,
|
|
"KEY_PASTE": 0x7D,
|
|
"KEY_FIND": 0x7E,
|
|
"KEY_MUTE": 0x7F,
|
|
"KEY_VOLUME_MUTE": 0x7F,
|
|
"KEY_VOLUME_UP": 0x80,
|
|
"KEY_VOLUME_DOWN": 0x81,
|
|
"KEY_LOCKING_CAPS_LOCK": 0x82,
|
|
"KEY_LOCKING_NUM_LOCK": 0x83,
|
|
"KEY_LOCKING_SCROLL_LOCK": 0x84,
|
|
"KEYPAD_COMMA": 0x85,
|
|
"KEYPAD_EQUAL_SIGN": 0x86,
|
|
"KEY_INTERNATIONAL1": 0x87,
|
|
"KEY_INTERNATIONAL2": 0x88,
|
|
"KEY_INTERNATIONAL3": 0x89,
|
|
"KEY_INTERNATIONAL4": 0x8A,
|
|
"KEY_INTERNATIONAL5": 0x8B,
|
|
"KEY_INTERNATIONAL6": 0x8C,
|
|
"KEY_INTERNATIONAL7": 0x8D,
|
|
"KEY_INTERNATIONAL8": 0x8E,
|
|
"KEY_INTERNATIONAL9": 0x8F,
|
|
"KEY_LANG1": 0x90,
|
|
"KEY_LANG2": 0x91,
|
|
"KEY_LANG3": 0x92,
|
|
"KEY_LANG4": 0x93,
|
|
"KEY_LANG5": 0x94,
|
|
"KEY_LANG6": 0x95,
|
|
"KEY_LANG7": 0x96,
|
|
"KEY_LANG8": 0x97,
|
|
"KEY_LANG9": 0x98,
|
|
"KEY_ALTERNATE_ERASE": 0x99,
|
|
"KEY_SYSREQ_ATTENTION": 0x9A,
|
|
"KEY_CANCEL": 0x9B,
|
|
"KEY_CLEAR": 0x9C,
|
|
"KEY_PRIOR": 0x9D,
|
|
"KEY_RETURN2": 0x9E,
|
|
"KEY_SEPARATOR": 0x9F,
|
|
"KEY_OUT": 0xA0,
|
|
"KEY_OPER": 0xA1,
|
|
"KEY_CLEAR_AGAIN": 0xA2,
|
|
"KEY_CRSEL_PROPS": 0xA3,
|
|
"KEY_EXSEL": 0xA4,
|
|
"KEY_PAD_00": 0xB0,
|
|
"KEY_PAD_000": 0xB1,
|
|
"KEY_THOUSANDS_SEPARATOR": 0xB2,
|
|
"KEY_DECIMAL_SEPARATOR": 0xB3,
|
|
"KEY_CURRENCY_UNIT": 0xB4,
|
|
"KEY_CURRENCY_SUB_UNIT": 0xB5,
|
|
"KEYPAD_LEFT_BRACE": 0xB6,
|
|
"KEYPAD_RIGHT_BRACE": 0xB7,
|
|
"KEYPAD_LEFT_CURLY_BRACE": 0xB8,
|
|
"KEYPAD_RIGHT_CURLY_BRACE": 0xB9,
|
|
"KEYPAD_TAB": 0xBA,
|
|
"KEYPAD_BACKSPACE": 0xBB,
|
|
"KEYPAD_A": 0xBC,
|
|
"KEYPAD_B": 0xBD,
|
|
"KEYPAD_C": 0xBE,
|
|
"KEYPAD_D": 0xBF,
|
|
"KEYPAD_E": 0xC0,
|
|
"KEYPAD_F": 0xC1,
|
|
"KEYPAD_XOR": 0xC2,
|
|
"KEYPAD_CARET": 0xC3,
|
|
"KEYPAD_PERCENT": 0xC4,
|
|
"KEYPAD_LESS_THAN": 0xC5,
|
|
"KEYPAD_GREATER_THAN": 0xC6,
|
|
"KEYPAD_AMPERSAND": 0xC7,
|
|
"KEYPAD_DOUBLEAMPERSAND": 0xC8,
|
|
"KEYPAD_PIPE": 0xC9,
|
|
"KEYPAD_DOUBLEPIPE": 0xCA,
|
|
"KEYPAD_COLON": 0xCB,
|
|
"KEYPAD_POUND_SIGN": 0xCC,
|
|
"KEYPAD_SPACE": 0xCD,
|
|
"KEYPAD_AT_SIGN": 0xCE,
|
|
"KEYPAD_EXCLAMATION_POINT": 0xCF,
|
|
"KEYPAD_MEMORY_STORE": 0xD0,
|
|
"KEYPAD_MEMORY_RECALL": 0xD1,
|
|
"KEYPAD_MEMORY_CLEAR": 0xD2,
|
|
"KEYPAD_MEMORY_ADD": 0xD3,
|
|
"KEYPAD_MEMORY_SUBTRACT": 0xD4,
|
|
"KEYPAD_MEMORY_MULTIPLY": 0xD5,
|
|
"KEYPAD_MEMORY_DIVIDE": 0xD6,
|
|
"KEYPAD_PLUS_MINUS": 0xD7,
|
|
"KEYPAD_CLEAR": 0xD8,
|
|
"KEYPAD_CLEAR_ENTRY": 0xD9,
|
|
"KEYPAD_BINARY": 0xDA,
|
|
"KEYPAD_OCTAL": 0xDB,
|
|
"KEYPAD_DECIMAL": 0xDC,
|
|
"KEYPAD_HEXADECIMAL": 0xDD,
|
|
"KEY_LEFT_CTRL": 0xE0,
|
|
"KEY_LEFT_SHIFT": 0xE1,
|
|
"KEY_LEFT_ALT": 0xE2,
|
|
"KEY_LEFT_GUI": 0xE3,
|
|
"KEY_LEFT_WINDOWS": 0xE3,
|
|
"KEY_RIGHT_CTRL": 0xE4,
|
|
"KEY_RIGHT_SHIFT": 0xE5,
|
|
"KEY_RIGHT_ALT": 0xE6,
|
|
"KEY_RIGHT_GUI": 0xE7,
|
|
"KEY_RIGHT_WINDOWS": 0xE7,
|
|
};
|
|
this.json = document.getElementById("json");
|
|
this.jsonCounter = document.getElementById("jsoncounter");
|
|
this.profile = document.getElementById("string");
|
|
this.generatejson = document.getElementById("generatejson");
|
|
this.generatestring = document.getElementById("generatestring");
|
|
this.error = document.getElementById("error");
|
|
this.generatestring.addEventListener("click", this.createProfile.bind(this));
|
|
this.generatejson.addEventListener("click", this.createJson.bind(this));
|
|
this.lineCountCache = 0;
|
|
this.json.addEventListener('scroll', function () {
|
|
_this.jsonCounter.scrollTop = _this.json.scrollTop;
|
|
_this.jsonCounter.scrollLeft = _this.json.scrollLeft;
|
|
});
|
|
this.json.addEventListener('input', function () {
|
|
_this.line_counter();
|
|
});
|
|
this.line_counter();
|
|
}
|
|
ProfileGenerator.prototype.createProfile = function (event) {
|
|
event.preventDefault();
|
|
var input = this.json.value;
|
|
var json = {};
|
|
try {
|
|
json = JSON.parse(input);
|
|
}
|
|
catch (e) {
|
|
this.error.innerHTML = e.message;
|
|
return false;
|
|
}
|
|
var profiles = [];
|
|
var lengths = [];
|
|
var profileCount = 0;
|
|
for (var pNum in json) {
|
|
var p = this.parseProfile(json[pNum]);
|
|
profiles.push(p[1]);
|
|
lengths.push(p[0]);
|
|
++profileCount;
|
|
}
|
|
profiles.unshift(this.hexString(profileCount));
|
|
var length = 3;
|
|
for (var i = 0; i < lengths.length; ++i) {
|
|
length += lengths[i];
|
|
}
|
|
profiles.unshift(this.hexString(length >> 8) + this.hexString(length & 255));
|
|
this.profile.value = "cimdit:F" + profiles.join("");
|
|
return false;
|
|
};
|
|
ProfileGenerator.prototype.hexString = function (input) {
|
|
if (input < 0) {
|
|
input += 256;
|
|
}
|
|
var hex = input.toString(16);
|
|
if (hex.length < 2) {
|
|
hex = "0" + hex;
|
|
}
|
|
return hex;
|
|
};
|
|
ProfileGenerator.prototype.parseProfile = function (json) {
|
|
var out = "";
|
|
var length = 2;
|
|
var tmp = json["name"];
|
|
for (var pos in tmp) {
|
|
out += this.hexString(tmp.charCodeAt(pos));
|
|
}
|
|
out += "00";
|
|
length += out.length / 2;
|
|
if (json["customimage"]) {
|
|
out += "01";
|
|
out += json["customimage"];
|
|
length += 513;
|
|
}
|
|
else {
|
|
out += "00";
|
|
++length;
|
|
}
|
|
if (json["mappedbuttons"] instanceof Array) {
|
|
var buttons = this.map(json["mappedbuttons"]);
|
|
out += this.hexString(buttons.count);
|
|
out += buttons.string;
|
|
length += buttons.bytes + 1;
|
|
}
|
|
else {
|
|
out += "00";
|
|
++length;
|
|
}
|
|
if (json["mappedaxis"] instanceof Array) {
|
|
var axis = this.map(json["mappedaxis"]);
|
|
out += this.hexString(axis.count);
|
|
out += axis.string;
|
|
length += axis.bytes + 1;
|
|
}
|
|
else {
|
|
out += "00";
|
|
++length;
|
|
}
|
|
if (json["mappedrotary"] instanceof Array) {
|
|
var rotary = this.map(json["mappedrotary"]);
|
|
out += this.hexString(rotary.count);
|
|
out += rotary.string;
|
|
length += rotary.bytes + 1;
|
|
}
|
|
else {
|
|
out += "00";
|
|
++length;
|
|
}
|
|
if (json["macros"] instanceof Array) {
|
|
var macro = this.createMacroString(json["macros"]);
|
|
out += this.hexString(macro.count);
|
|
out += macro.string;
|
|
length += macro.bytes + 1;
|
|
}
|
|
else {
|
|
out += "00";
|
|
++length;
|
|
}
|
|
out = this.hexString(length >> 8) + this.hexString(length & 255) + out;
|
|
return [length, out];
|
|
};
|
|
ProfileGenerator.prototype.map = function (entities) {
|
|
var out = "";
|
|
var bytes = 0;
|
|
var count = 0;
|
|
for (var i = 0; i < entities.length; ++i) {
|
|
var entity = entities[i];
|
|
try {
|
|
var tmp = this.hexString(entity.source);
|
|
tmp += this.hexString(this.profileEnum.indexOf(entity.type));
|
|
if (entity.target !== undefined) {
|
|
if (typeof (entity.target) === "number") {
|
|
tmp += this.hexString(entity.target);
|
|
}
|
|
else {
|
|
tmp += this.hexString(this.keyLookup[entity.target]);
|
|
}
|
|
}
|
|
else if (entity.axis !== undefined) {
|
|
tmp += this.hexString(entity.axis);
|
|
}
|
|
else if (entity.value !== undefined) {
|
|
tmp += this.hexString(entity.value);
|
|
}
|
|
else if (entity.macro !== undefined) {
|
|
tmp += this.hexString(entity.macro);
|
|
}
|
|
else {
|
|
tmp += "00";
|
|
}
|
|
out += tmp;
|
|
bytes += 3;
|
|
++count;
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
}
|
|
}
|
|
return { bytes: bytes, count: count, string: out };
|
|
};
|
|
ProfileGenerator.prototype.createMacroString = function (macros) {
|
|
var bytes = 0;
|
|
var out = "";
|
|
for (var i = 0; i < macros.length; ++i) {
|
|
var macro = macros[i];
|
|
var append = false;
|
|
for (var j = 0; j < macro.length; ++j) {
|
|
var token = macro[j];
|
|
if (token === "MACRO_SPEED" || token === "MACRO_MOUSE_WHEEL" || token.toString().match(/^MACRO_(JOY|MOUSE)_(PRESS|RELEASE)$/)) {
|
|
if (append) {
|
|
append = false;
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
out += this.hexString(this.macroEnum.indexOf(token)) + this.hexString(macro[++j]);
|
|
bytes += 2;
|
|
}
|
|
else if (token === "MACRO_DELAY") {
|
|
if (append) {
|
|
append = false;
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
var value = macro[++j];
|
|
out += this.hexString(this.macroEnum.indexOf(token)) + this.hexString((value >> 8)) + this.hexString(value & 255);
|
|
bytes += 3;
|
|
}
|
|
else if (token.toString().match(/^MACRO_KEY_(PRESS|RELEASE)$/) || token === "MACRO_TYPE") {
|
|
if (append) {
|
|
append = false;
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
out += this.hexString(this.macroEnum.indexOf(token));
|
|
append = true;
|
|
++bytes;
|
|
}
|
|
else if (token === "MACRO_MOUSE_REL_X" || token === "MACRO_MOUSE_REL_Y") {
|
|
if (append) {
|
|
append = false;
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
out += this.hexString(this.macroEnum.indexOf(token)) + this.hexString(macro[++j]);
|
|
bytes += 2;
|
|
}
|
|
else if (token === "MACRO_MOUSE_REL_X_AXIS" || token === "MACRO_MOUSE_REL_Y_AXIS") {
|
|
if (append) {
|
|
append = false;
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
if (macro[j + 1] == -1) {
|
|
out += this.hexString(this.macroEnum.indexOf(token)) + this.hexString(macro[++j]);
|
|
bytes += 2;
|
|
}
|
|
else {
|
|
out += this.hexString(this.macroEnum.indexOf(token)) + this.hexString(macro[++j]) + this.hexString(macro[++j]);
|
|
bytes += 3;
|
|
}
|
|
}
|
|
else {
|
|
if (typeof (token) === "number") {
|
|
out += this.hexString(token);
|
|
++bytes;
|
|
}
|
|
else {
|
|
if (token.startsWith("KEY_")) {
|
|
out += this.hexString(this.keyLookup[token]);
|
|
++bytes;
|
|
}
|
|
else {
|
|
for (var k = 0; k < token.length; ++k) {
|
|
out += this.hexString(this.keyLookup["KEY_" + token[k].toUpperCase()]);
|
|
++bytes;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (append) {
|
|
append = false;
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
out += "00";
|
|
++bytes;
|
|
}
|
|
return { bytes: bytes, count: macros.length, string: out };
|
|
};
|
|
ProfileGenerator.prototype.fromHexS = function (input) {
|
|
var ret = parseInt(input, 16);
|
|
if (ret > 127)
|
|
ret -= 256;
|
|
return ret;
|
|
};
|
|
ProfileGenerator.prototype.fromHexU = function (input) {
|
|
return parseInt(input, 16);
|
|
};
|
|
ProfileGenerator.prototype.createJson = function (event) {
|
|
event.preventDefault();
|
|
var string = this.profile.value;
|
|
string = string.replace("cimdit:F", "");
|
|
var tokens = string.match(/.{1,2}/g);
|
|
tokens.shift();
|
|
tokens.shift();
|
|
var json;
|
|
json = [];
|
|
var numProfile = this.fromHexU(tokens.shift());
|
|
for (var i = 0; i < numProfile; ++i) {
|
|
json.push(this.createProfileFromTokens(tokens));
|
|
}
|
|
this.json.value = JSON.stringify(json, null, " ");
|
|
return false;
|
|
};
|
|
ProfileGenerator.prototype.createProfileFromTokens = function (tokens) {
|
|
tokens.shift();
|
|
tokens.shift();
|
|
var name = "";
|
|
var char;
|
|
do {
|
|
char = this.fromHexU(tokens.shift());
|
|
if (char)
|
|
name += String.fromCharCode(char);
|
|
} while (char !== 0 && tokens.length > 0);
|
|
var ret = { name: name };
|
|
var customImage = tokens.shift();
|
|
if (customImage != "00") {
|
|
var cu = "";
|
|
for (var i = 0; i < 512; ++i) {
|
|
cu += tokens.shift();
|
|
}
|
|
ret.customimage = cu;
|
|
}
|
|
var mappedButtons = [];
|
|
var numButtons = this.fromHexU(tokens.shift());
|
|
for (var i = 0; i < numButtons; ++i) {
|
|
mappedButtons.push(this.createEntityFromTokens(tokens));
|
|
}
|
|
ret.mappedbuttons = mappedButtons;
|
|
var mappedAxis = [];
|
|
var numAxis = this.fromHexU(tokens.shift());
|
|
for (var i = 0; i < numAxis; ++i) {
|
|
mappedAxis.push(this.createEntityFromTokens(tokens));
|
|
}
|
|
ret.mappedaxis = mappedAxis;
|
|
var mappedRotary = [];
|
|
var numRotary = this.fromHexU(tokens.shift());
|
|
for (var i = 0; i < numRotary; ++i) {
|
|
mappedRotary.push(this.createEntityFromTokens(tokens));
|
|
}
|
|
ret.mappedrotary = mappedRotary;
|
|
var macros = [];
|
|
var numMacro = this.fromHexU(tokens.shift());
|
|
for (var i = 0; i < numMacro; ++i) {
|
|
macros.push(this.createMacrosFromTokens(tokens));
|
|
}
|
|
ret.macros = macros;
|
|
return ret;
|
|
};
|
|
ProfileGenerator.prototype.createEntityFromTokens = function (tokens) {
|
|
var entity = { source: this.fromHexU(tokens.shift()), type: this.profileEnum[this.fromHexU(tokens.shift())] };
|
|
if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') {
|
|
entity.target = this.fromHexU(tokens.shift());
|
|
}
|
|
else if (entity.type === 'KEYBOARD_BUTTON') {
|
|
entity.target = this.getKey(this.fromHexU(tokens.shift()));
|
|
}
|
|
else if (entity.type === 'JOYSTICK_AXIS') {
|
|
entity.axis = this.fromHexU(tokens.shift());
|
|
}
|
|
else if (entity.type === 'MOUSE_REL_X_AXIS' || entity.type === 'MOUSE_REL_Y_AXIS' || entity.type === 'MOUSE_REL_WHEEL') {
|
|
entity.value = this.fromHexS(tokens.shift());
|
|
}
|
|
else if (entity.type === 'MACRO_PRESS' || entity.type === 'MACRO_RELEASE') {
|
|
entity.macro = this.fromHexU(tokens.shift());
|
|
}
|
|
else {
|
|
tokens.shift();
|
|
}
|
|
return entity;
|
|
};
|
|
ProfileGenerator.prototype.getKey = function (input) {
|
|
var _this = this;
|
|
return Object.keys(this.keyLookup).find(function (k) { return _this.keyLookup[k] === input; });
|
|
};
|
|
ProfileGenerator.prototype.createMacrosFromTokens = function (tokens) {
|
|
var macro = [];
|
|
do {
|
|
var token = this.macroEnum[this.fromHexU(tokens.shift())];
|
|
if (token !== "MACRO_NULL") {
|
|
macro.push(token);
|
|
}
|
|
switch (token) {
|
|
case "MACRO_NULL":
|
|
break;
|
|
case "MACRO_SPEED":
|
|
case "MACRO_JOY_PRESS":
|
|
case "MACRO_JOY_RELEASE":
|
|
case "MACRO_MOUSE_PRESS":
|
|
case "MACRO_MOUSE_RELEASE":
|
|
case "MACRO_MOUSE_WHEEL":
|
|
macro.push(this.fromHexU(tokens.shift()));
|
|
break;
|
|
case "MACRO_DELAY":
|
|
macro.push((this.fromHexU(tokens.shift()) << 8) + this.fromHexU(tokens.shift()));
|
|
break;
|
|
case "MACRO_KEY_PRESS":
|
|
case "MACRO_KEY_RELEASE":
|
|
case "MACRO_TYPE":
|
|
var next;
|
|
var tmp = "";
|
|
do {
|
|
next = this.fromHexU(tokens.shift());
|
|
if (next != 0) {
|
|
var k = this.getKey(next);
|
|
if (k.match(/^KEY_\S$/)) {
|
|
tmp += k[4].toLowerCase();
|
|
}
|
|
else {
|
|
if (tmp !== "")
|
|
macro.push(tmp);
|
|
tmp = "";
|
|
macro.push(k);
|
|
}
|
|
}
|
|
} while (next != 0);
|
|
if (tmp !== "") {
|
|
macro.push(tmp);
|
|
}
|
|
break;
|
|
case "MACRO_MOUSE_REL_X":
|
|
case "MACRO_MOUSE_REL_Y":
|
|
var next = this.fromHexS(tokens.shift());
|
|
macro.push(next);
|
|
break;
|
|
case "MACRO_MOUSE_REL_X_AXIS":
|
|
case "MACRO_MOUSE_REL_Y_AXIS":
|
|
var next = this.fromHexS(tokens.shift());
|
|
macro.push(next);
|
|
if (next != -1) {
|
|
macro.push(this.fromHexS(tokens.shift()));
|
|
}
|
|
break;
|
|
}
|
|
} while (token !== "MACRO_NULL" && tokens.length > 0);
|
|
return macro;
|
|
};
|
|
ProfileGenerator.prototype.line_counter = function () {
|
|
var lineCount = this.json.value.split('\n').length;
|
|
var outarr = new Array();
|
|
if (this.lineCountCache != lineCount) {
|
|
for (var x = 0; x < lineCount; x++) {
|
|
outarr[x] = (x + 1);
|
|
}
|
|
this.jsonCounter.value = outarr.join('\n');
|
|
}
|
|
this.lineCountCache = lineCount;
|
|
};
|
|
return ProfileGenerator;
|
|
})();
|
|
|
|
|
|
</script>
|
|
</body>
|
|
</html> |