Reformat _server & delete map

This commit is contained in:
oc 2018-04-18 00:28:53 +08:00
parent bff5298c7a
commit 81df4a9b19
24 changed files with 26199 additions and 5902 deletions

View File

@ -13,6 +13,7 @@
.CodeMirror-lines { .CodeMirror-lines {
padding: 4px 0; /* Vertical padding around content */ padding: 4px 0; /* Vertical padding around content */
} }
.CodeMirror pre { .CodeMirror pre {
padding: 0 4px; /* Horizontal padding of content */ padding: 0 4px; /* Horizontal padding of content */
} }
@ -28,7 +29,10 @@
background-color: #f7f7f7; background-color: #f7f7f7;
white-space: nowrap; white-space: nowrap;
} }
.CodeMirror-linenumbers {}
.CodeMirror-linenumbers {
}
.CodeMirror-linenumber { .CodeMirror-linenumber {
padding: 0 3px 0 5px; padding: 0 3px 0 5px;
min-width: 20px; min-width: 20px;
@ -37,8 +41,13 @@
white-space: nowrap; white-space: nowrap;
} }
.CodeMirror-guttermarker { color: black; } .CodeMirror-guttermarker {
.CodeMirror-guttermarker-subtle { color: #999; } color: black;
}
.CodeMirror-guttermarker-subtle {
color: #999;
}
/* CURSOR */ /* CURSOR */
@ -47,24 +56,29 @@
border-right: none; border-right: none;
width: 0; width: 0;
} }
/* Shown when moving in bi-directional text */ /* Shown when moving in bi-directional text */
.CodeMirror div.CodeMirror-secondarycursor { .CodeMirror div.CodeMirror-secondarycursor {
border-left: 1px solid silver; border-left: 1px solid silver;
} }
.cm-fat-cursor .CodeMirror-cursor { .cm-fat-cursor .CodeMirror-cursor {
width: auto; width: auto;
border: 0 !important; border: 0 !important;
background: #7e7; background: #7e7;
} }
.cm-fat-cursor div.CodeMirror-cursors { .cm-fat-cursor div.CodeMirror-cursors {
z-index: 1; z-index: 1;
} }
.cm-fat-cursor-mark { .cm-fat-cursor-mark {
background-color: rgba(20, 255, 20, 0.5); background-color: rgba(20, 255, 20, 0.5);
-webkit-animation: blink 1.06s steps(1) infinite; -webkit-animation: blink 1.06s steps(1) infinite;
-moz-animation: blink 1.06s steps(1) infinite; -moz-animation: blink 1.06s steps(1) infinite;
animation: blink 1.06s steps(1) infinite; animation: blink 1.06s steps(1) infinite;
} }
.cm-animate-fat-cursor { .cm-animate-fat-cursor {
width: auto; width: auto;
border: 0; border: 0;
@ -73,82 +87,199 @@
animation: blink 1.06s steps(1) infinite; animation: blink 1.06s steps(1) infinite;
background-color: #7e7; background-color: #7e7;
} }
@-moz-keyframes blink { @-moz-keyframes blink {
0% {} 0% {
50% { background-color: transparent; } }
100% {} 50% {
background-color: transparent;
}
100% {
}
} }
@-webkit-keyframes blink { @-webkit-keyframes blink {
0% {} 0% {
50% { background-color: transparent; } }
100% {} 50% {
background-color: transparent;
}
100% {
}
} }
@keyframes blink { @keyframes blink {
0% {} 0% {
50% { background-color: transparent; } }
100% {} 50% {
background-color: transparent;
}
100% {
}
} }
/* Can style cursor different in overwrite (non-insert) mode */ /* Can style cursor different in overwrite (non-insert) mode */
.CodeMirror-overwrite .CodeMirror-cursor {} .CodeMirror-overwrite .CodeMirror-cursor {
}
.cm-tab { display: inline-block; text-decoration: inherit; } .cm-tab {
display: inline-block;
text-decoration: inherit;
}
.CodeMirror-rulers { .CodeMirror-rulers {
position: absolute; position: absolute;
left: 0; right: 0; top: -50px; bottom: -20px; left: 0;
right: 0;
top: -50px;
bottom: -20px;
overflow: hidden; overflow: hidden;
} }
.CodeMirror-ruler { .CodeMirror-ruler {
border-left: 1px solid #ccc; border-left: 1px solid #ccc;
top: 0; bottom: 0; top: 0;
bottom: 0;
position: absolute; position: absolute;
} }
/* DEFAULT THEME */ /* DEFAULT THEME */
.cm-s-default .cm-header {color: blue;} .cm-s-default .cm-header {
.cm-s-default .cm-quote {color: #090;} color: blue;
.cm-negative {color: #d44;} }
.cm-positive {color: #292;}
.cm-header, .cm-strong {font-weight: bold;} .cm-s-default .cm-quote {
.cm-em {font-style: italic;} color: #090;
.cm-link {text-decoration: underline;} }
.cm-strikethrough {text-decoration: line-through;}
.cm-negative {
color: #d44;
}
.cm-positive {
color: #292;
}
.cm-header, .cm-strong {
font-weight: bold;
}
.cm-em {
font-style: italic;
}
.cm-link {
text-decoration: underline;
}
.cm-strikethrough {
text-decoration: line-through;
}
.cm-s-default .cm-keyword {
color: #708;
}
.cm-s-default .cm-atom {
color: #219;
}
.cm-s-default .cm-number {
color: #164;
}
.cm-s-default .cm-def {
color: #00f;
}
.cm-s-default .cm-keyword {color: #708;}
.cm-s-default .cm-atom {color: #219;}
.cm-s-default .cm-number {color: #164;}
.cm-s-default .cm-def {color: #00f;}
.cm-s-default .cm-variable, .cm-s-default .cm-variable,
.cm-s-default .cm-punctuation, .cm-s-default .cm-punctuation,
.cm-s-default .cm-property, .cm-s-default .cm-property,
.cm-s-default .cm-operator {} .cm-s-default .cm-operator {
.cm-s-default .cm-variable-2 {color: #05a;} }
.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
.cm-s-default .cm-comment {color: #a50;}
.cm-s-default .cm-string {color: #a11;}
.cm-s-default .cm-string-2 {color: #f50;}
.cm-s-default .cm-meta {color: #555;}
.cm-s-default .cm-qualifier {color: #555;}
.cm-s-default .cm-builtin {color: #30a;}
.cm-s-default .cm-bracket {color: #997;}
.cm-s-default .cm-tag {color: #170;}
.cm-s-default .cm-attribute {color: #00c;}
.cm-s-default .cm-hr {color: #999;}
.cm-s-default .cm-link {color: #00c;}
.cm-s-default .cm-error {color: #f00;} .cm-s-default .cm-variable-2 {
.cm-invalidchar {color: #f00;} color: #05a;
}
.CodeMirror-composing { border-bottom: 2px solid; } .cm-s-default .cm-variable-3, .cm-s-default .cm-type {
color: #085;
}
.cm-s-default .cm-comment {
color: #a50;
}
.cm-s-default .cm-string {
color: #a11;
}
.cm-s-default .cm-string-2 {
color: #f50;
}
.cm-s-default .cm-meta {
color: #555;
}
.cm-s-default .cm-qualifier {
color: #555;
}
.cm-s-default .cm-builtin {
color: #30a;
}
.cm-s-default .cm-bracket {
color: #997;
}
.cm-s-default .cm-tag {
color: #170;
}
.cm-s-default .cm-attribute {
color: #00c;
}
.cm-s-default .cm-hr {
color: #999;
}
.cm-s-default .cm-link {
color: #00c;
}
.cm-s-default .cm-error {
color: #f00;
}
.cm-invalidchar {
color: #f00;
}
.CodeMirror-composing {
border-bottom: 2px solid;
}
/* Default styles for common addons */ /* Default styles for common addons */
div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;} div.CodeMirror span.CodeMirror-matchingbracket {
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;} color: #0b0;
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } }
.CodeMirror-activeline-background {background: #e8f2ff;}
div.CodeMirror span.CodeMirror-nonmatchingbracket {
color: #a22;
}
.CodeMirror-matchingtag {
background: rgba(255, 150, 0, .3);
}
.CodeMirror-activeline-background {
background: #e8f2ff;
}
/* STOP */ /* STOP */
@ -165,12 +296,14 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
overflow: scroll !important; /* Things will break if this is overridden */ overflow: scroll !important; /* Things will break if this is overridden */
/* 30px is the magic margin used to hide the element's real scrollbars */ /* 30px is the magic margin used to hide the element's real scrollbars */
/* See overflow: hidden in .CodeMirror */ /* See overflow: hidden in .CodeMirror */
margin-bottom: -30px; margin-right: -30px; margin-bottom: -30px;
margin-right: -30px;
padding-bottom: 30px; padding-bottom: 30px;
height: 100%; height: 100%;
outline: none; /* Prevent dragging from highlighting the element */ outline: none; /* Prevent dragging from highlighting the element */
position: relative; position: relative;
} }
.CodeMirror-sizer { .CodeMirror-sizer {
position: relative; position: relative;
border-right: 30px solid transparent; border-right: 30px solid transparent;
@ -184,28 +317,39 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
z-index: 6; z-index: 6;
display: none; display: none;
} }
.CodeMirror-vscrollbar { .CodeMirror-vscrollbar {
right: 0; top: 0; right: 0;
top: 0;
overflow-x: hidden; overflow-x: hidden;
overflow-y: scroll; overflow-y: scroll;
} }
.CodeMirror-hscrollbar { .CodeMirror-hscrollbar {
bottom: 0; left: 0; bottom: 0;
left: 0;
overflow-y: hidden; overflow-y: hidden;
overflow-x: scroll; overflow-x: scroll;
} }
.CodeMirror-scrollbar-filler { .CodeMirror-scrollbar-filler {
right: 0; bottom: 0; right: 0;
bottom: 0;
} }
.CodeMirror-gutter-filler { .CodeMirror-gutter-filler {
left: 0; bottom: 0; left: 0;
bottom: 0;
} }
.CodeMirror-gutters { .CodeMirror-gutters {
position: absolute; left: 0; top: 0; position: absolute;
left: 0;
top: 0;
min-height: 100%; min-height: 100%;
z-index: 3; z-index: 3;
} }
.CodeMirror-gutter { .CodeMirror-gutter {
white-space: normal; white-space: normal;
height: 100%; height: 100%;
@ -213,32 +357,45 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
vertical-align: top; vertical-align: top;
margin-bottom: -30px; margin-bottom: -30px;
} }
.CodeMirror-gutter-wrapper { .CodeMirror-gutter-wrapper {
position: absolute; position: absolute;
z-index: 4; z-index: 4;
background: none !important; background: none !important;
border: none !important; border: none !important;
} }
.CodeMirror-gutter-background { .CodeMirror-gutter-background {
position: absolute; position: absolute;
top: 0; bottom: 0; top: 0;
bottom: 0;
z-index: 4; z-index: 4;
} }
.CodeMirror-gutter-elt { .CodeMirror-gutter-elt {
position: absolute; position: absolute;
cursor: default; cursor: default;
z-index: 4; z-index: 4;
} }
.CodeMirror-gutter-wrapper ::selection { background-color: transparent }
.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent } .CodeMirror-gutter-wrapper ::selection {
background-color: transparent
}
.CodeMirror-gutter-wrapper ::-moz-selection {
background-color: transparent
}
.CodeMirror-lines { .CodeMirror-lines {
cursor: text; cursor: text;
min-height: 1px; /* prevents collapsing before first draw */ min-height: 1px; /* prevents collapsing before first draw */
} }
.CodeMirror pre { .CodeMirror pre {
/* Reset some styles that the rest of the page might have set */ /* Reset some styles that the rest of the page might have set */
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; -moz-border-radius: 0;
-webkit-border-radius: 0;
border-radius: 0;
border-width: 0; border-width: 0;
background: transparent; background: transparent;
font-family: inherit; font-family: inherit;
@ -255,6 +412,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
-webkit-font-variant-ligatures: contextual; -webkit-font-variant-ligatures: contextual;
font-variant-ligatures: contextual; font-variant-ligatures: contextual;
} }
.CodeMirror-wrap pre { .CodeMirror-wrap pre {
word-wrap: break-word; word-wrap: break-word;
white-space: pre-wrap; white-space: pre-wrap;
@ -263,7 +421,10 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
.CodeMirror-linebackground { .CodeMirror-linebackground {
position: absolute; position: absolute;
left: 0; right: 0; top: 0; bottom: 0; left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 0; z-index: 0;
} }
@ -273,9 +434,12 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
padding: 0.1px; /* Force widget margins to stay inside of the container */ padding: 0.1px; /* Force widget margins to stay inside of the container */
} }
.CodeMirror-widget {} .CodeMirror-widget {
}
.CodeMirror-rtl pre { direction: rtl; } .CodeMirror-rtl pre {
direction: rtl;
}
.CodeMirror-code { .CodeMirror-code {
outline: none; outline: none;
@ -303,13 +467,17 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
position: absolute; position: absolute;
pointer-events: none; pointer-events: none;
} }
.CodeMirror-measure pre { position: static; }
.CodeMirror-measure pre {
position: static;
}
div.CodeMirror-cursors { div.CodeMirror-cursors {
visibility: hidden; visibility: hidden;
position: relative; position: relative;
z-index: 3; z-index: 3;
} }
div.CodeMirror-dragcursors { div.CodeMirror-dragcursors {
visibility: visible; visibility: visible;
} }
@ -318,11 +486,25 @@ div.CodeMirror-dragcursors {
visibility: visible; visibility: visible;
} }
.CodeMirror-selected { background: #d9d9d9; } .CodeMirror-selected {
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } background: #d9d9d9;
.CodeMirror-crosshair { cursor: crosshair; } }
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; } .CodeMirror-focused .CodeMirror-selected {
background: #d7d4f0;
}
.CodeMirror-crosshair {
cursor: crosshair;
}
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection {
background: #d7d4f0;
}
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection {
background: #d7d4f0;
}
.cm-searching { .cm-searching {
background-color: #ffa; background-color: #ffa;
@ -330,7 +512,9 @@ div.CodeMirror-dragcursors {
} }
/* Used to force a border model for a node */ /* Used to force a border model for a node */
.cm-force-border { padding-right: .1px; } .cm-force-border {
padding-right: .1px;
}
@media print { @media print {
/* Hide the cursor when printing */ /* Hide the cursor when printing */
@ -340,7 +524,11 @@ div.CodeMirror-dragcursors {
} }
/* See issue #2901 */ /* See issue #2901 */
.cm-tab-wrap-hack:after { content: ''; } .cm-tab-wrap-hack:after {
content: '';
}
/* Help users use markselection to safely style text background */ /* Help users use markselection to safely style text background */
span.CodeMirror-selectedtext { background: none; } span.CodeMirror-selectedtext {
background: none;
}

View File

@ -1,14 +1,14 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) { (function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function (CodeMirror) {
var Pos = CodeMirror.Pos; var Pos = CodeMirror.Pos;
function forEach(arr, f) { function forEach(arr, f) {
@ -36,8 +36,10 @@
// If it's not a 'word-style' token, ignore the token. // If it's not a 'word-style' token, ignore the token.
if (!/^[\w$_]*$/.test(token.string)) { if (!/^[\w$_]*$/.test(token.string)) {
token = {start: cur.ch, end: cur.ch, string: "", state: token.state, token = {
type: token.string == "." ? "property" : null}; start: cur.ch, end: cur.ch, string: "", state: token.state,
type: token.string == "." ? "property" : null
};
} else if (token.end > cur.ch) { } else if (token.end > cur.ch) {
token.end = cur.ch; token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start); token.string = token.string.slice(0, cur.ch - token.start);
@ -52,14 +54,18 @@
if (!context) var context = []; if (!context) var context = [];
context.push(tprop); context.push(tprop);
} }
return {list: getCompletions(token, context, keywords, options), return {
list: getCompletions(token, context, keywords, options),
from: Pos(cur.line, token.start), from: Pos(cur.line, token.start),
to: Pos(cur.line, token.end)}; to: Pos(cur.line, token.end)
};
} }
function javascriptHint(editor, options) { function javascriptHint(editor, options) {
return scriptHint(editor, javascriptKeywords, return scriptHint(editor, javascriptKeywords,
function (e, cur) {return e.getTokenAt(cur);}, function (e, cur) {
return e.getTokenAt(cur);
},
options); options);
}; };
CodeMirror.registerHelper("hint", "javascript", javascriptHint); CodeMirror.registerHelper("hint", "javascript", javascriptHint);
@ -85,6 +91,7 @@
function coffeescriptHint(editor, options) { function coffeescriptHint(editor, options) {
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options); return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
} }
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint); CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " + var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
@ -108,10 +115,12 @@
function getCompletions(token, context, keywords, options) { function getCompletions(token, context, keywords, options) {
var found = [], start = token.string, global = options && options.globalScope || window; var found = [], start = token.string, global = options && options.globalScope || window;
function maybeAdd(str) { function maybeAdd(str) {
if (str==null || str==undefined) return; if (str == null || str == undefined) return;
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str); if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
} }
function gatherCompletions(obj) { function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd); if (typeof obj == "string") forEach(stringProps, maybeAdd);
else if (obj instanceof Array) forEach(arrayProps, maybeAdd); else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
@ -153,4 +162,4 @@
} }
return found; return found;
} }
}); });

View File

@ -1,15 +1,16 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) { (function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function (CodeMirror) {
"use strict"; "use strict";
// declare global: JSHINT // declare global: JSHINT
function validator(text, options) { function validator(text, options) {
@ -30,7 +31,7 @@
CodeMirror.registerHelper("lint", "javascript", validator); CodeMirror.registerHelper("lint", "javascript", validator);
function parseErrors(errors, output) { function parseErrors(errors, output) {
for ( var i = 0; i < errors.length; i++) { for (var i = 0; i < errors.length; i++) {
var error = errors[i]; var error = errors[i];
if (error) { if (error) {
if (error.line <= 0) { if (error.line <= 0) {
@ -60,4 +61,4 @@
} }
} }
} }
}); });

View File

@ -1,9 +1,9 @@
/* The lint marker gutter */ /* The lint marker gutter */
.CodeMirror-lint-markers { .CodeMirror-lint-markers {
width: 16px; width: 16px;
} }
.CodeMirror-lint-tooltip { .CodeMirror-lint-tooltip {
background-color: #ffd; background-color: #ffd;
border: 1px solid black; border: 1px solid black;
border-radius: 4px 4px 4px 4px; border-radius: 4px 4px 4px 4px;
@ -23,24 +23,22 @@
-webkit-transition: opacity .4s; -webkit-transition: opacity .4s;
-o-transition: opacity .4s; -o-transition: opacity .4s;
-ms-transition: opacity .4s; -ms-transition: opacity .4s;
} }
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning { .CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
background-position: left bottom; background-position: left bottom;
background-repeat: repeat-x; background-repeat: repeat-x;
} }
.CodeMirror-lint-mark-error { .CodeMirror-lint-mark-error {
background-image: background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==");
url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==") }
;
}
.CodeMirror-lint-mark-warning { .CodeMirror-lint-mark-warning {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII="); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
} }
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning { .CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
background-position: center center; background-position: center center;
background-repeat: no-repeat; background-repeat: no-repeat;
cursor: pointer; cursor: pointer;
@ -49,25 +47,26 @@
width: 16px; width: 16px;
vertical-align: middle; vertical-align: middle;
position: relative; position: relative;
} }
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning { .CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
padding-left: 18px; padding-left: 18px;
background-position: top left; background-position: top left;
background-repeat: no-repeat; background-repeat: no-repeat;
} }
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error { .CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII="); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
} }
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning { .CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII="); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
} }
.CodeMirror-lint-marker-multiple { .CodeMirror-lint-marker-multiple {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC"); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: right bottom; background-position: right bottom;
width: 100%; height: 100%; width: 100%;
} height: 100%;
}

View File

@ -1,14 +1,14 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) { (function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function (CodeMirror) {
"use strict"; "use strict";
var GUTTER_ID = "CodeMirror-lint-markers"; var GUTTER_ID = "CodeMirror-lint-markers";
@ -23,32 +23,45 @@
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px"; tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
tt.style.left = (e.clientX + 5) + "px"; tt.style.left = (e.clientX + 5) + "px";
} }
CodeMirror.on(document, "mousemove", position); CodeMirror.on(document, "mousemove", position);
position(e); position(e);
if (tt.style.opacity != null) tt.style.opacity = 1; if (tt.style.opacity != null) tt.style.opacity = 1;
return tt; return tt;
} }
function rm(elt) { function rm(elt) {
if (elt.parentNode) elt.parentNode.removeChild(elt); if (elt.parentNode) elt.parentNode.removeChild(elt);
} }
function hideTooltip(tt) { function hideTooltip(tt) {
if (!tt.parentNode) return; if (!tt.parentNode) return;
if (tt.style.opacity == null) rm(tt); if (tt.style.opacity == null) rm(tt);
tt.style.opacity = 0; tt.style.opacity = 0;
setTimeout(function() { rm(tt); }, 600); setTimeout(function () {
rm(tt);
}, 600);
} }
function showTooltipFor(e, content, node) { function showTooltipFor(e, content, node) {
var tooltip = showTooltip(e, content); var tooltip = showTooltip(e, content);
function hide() { function hide() {
CodeMirror.off(node, "mouseout", hide); CodeMirror.off(node, "mouseout", hide);
if (tooltip) { hideTooltip(tooltip); tooltip = null; } if (tooltip) {
hideTooltip(tooltip);
tooltip = null;
} }
var poll = setInterval(function() { }
if (tooltip) for (var n = node;; n = n.parentNode) {
var poll = setInterval(function () {
if (tooltip) for (var n = node; ; n = n.parentNode) {
if (n && n.nodeType == 11) n = n.host; if (n && n.nodeType == 11) n = n.host;
if (n == document.body) return; if (n == document.body) return;
if (!n) { hide(); break; } if (!n) {
hide();
break;
}
} }
if (!tooltip) return clearInterval(poll); if (!tooltip) return clearInterval(poll);
}, 400); }, 400);
@ -60,7 +73,9 @@
this.options = options; this.options = options;
this.timeout = null; this.timeout = null;
this.hasGutter = hasGutter; this.hasGutter = hasGutter;
this.onMouseOver = function(e) { onMouseOver(cm, e); }; this.onMouseOver = function (e) {
onMouseOver(cm, e);
};
this.waitingFor = 0 this.waitingFor = 0
} }
@ -86,7 +101,7 @@
inner.className = "CodeMirror-lint-marker-multiple"; inner.className = "CodeMirror-lint-marker-multiple";
} }
if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) { if (tooltips != false) CodeMirror.on(inner, "mouseover", function (e) {
showTooltipFor(e, labels, inner); showTooltipFor(e, labels, inner);
}); });
@ -123,16 +138,20 @@
function lintAsync(cm, getAnnotations, passOptions) { function lintAsync(cm, getAnnotations, passOptions) {
var state = cm.state.lint var state = cm.state.lint
var id = ++state.waitingFor var id = ++state.waitingFor
function abort() { function abort() {
id = -1 id = -1
cm.off("change", abort) cm.off("change", abort)
} }
cm.on("change", abort) cm.on("change", abort)
getAnnotations(cm.getValue(), function(annotations, arg2) { getAnnotations(cm.getValue(), function (annotations, arg2) {
cm.off("change", abort) cm.off("change", abort)
if (state.waitingFor != id) return if (state.waitingFor != id) return
if (arg2 && annotations instanceof CodeMirror) annotations = arg2 if (arg2 && annotations instanceof CodeMirror) annotations = arg2
cm.operation(function() {updateLinting(cm, annotations)}) cm.operation(function () {
updateLinting(cm, annotations)
})
}, passOptions, cm); }, passOptions, cm);
} }
@ -150,10 +169,14 @@
} else { } else {
var annotations = getAnnotations(cm.getValue(), passOptions, cm); var annotations = getAnnotations(cm.getValue(), passOptions, cm);
if (!annotations) return; if (!annotations) return;
if (annotations.then) annotations.then(function(issues) { if (annotations.then) annotations.then(function (issues) {
cm.operation(function() {updateLinting(cm, issues)}) cm.operation(function () {
updateLinting(cm, issues)
})
}); });
else cm.operation(function() {updateLinting(cm, annotations)}) else cm.operation(function () {
updateLinting(cm, annotations)
})
} }
} }
@ -196,7 +219,9 @@
var state = cm.state.lint; var state = cm.state.lint;
if (!state) return; if (!state) return;
clearTimeout(state.timeout); clearTimeout(state.timeout);
state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500); state.timeout = setTimeout(function () {
startLinting(cm);
}, state.options.delay || 500);
} }
function popupTooltips(annotations, e) { function popupTooltips(annotations, e) {
@ -223,7 +248,7 @@
if (annotations.length) popupTooltips(annotations, e); if (annotations.length) popupTooltips(annotations, e);
} }
CodeMirror.defineOption("lint", false, function(cm, val, old) { CodeMirror.defineOption("lint", false, function (cm, val, old) {
if (old && old != CodeMirror.Init) { if (old && old != CodeMirror.Init) {
clearMarks(cm); clearMarks(cm);
if (cm.state.lint.options.lintOnChange !== false) if (cm.state.lint.options.lintOnChange !== false)
@ -246,7 +271,7 @@
} }
}); });
CodeMirror.defineExtension("performLint", function() { CodeMirror.defineExtension("performLint", function () {
if (this.state.lint) startLinting(this); if (this.state.lint) startLinting(this);
}); });
}); });

View File

@ -7,9 +7,9 @@
margin: 0; margin: 0;
padding: 2px; padding: 2px;
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); -webkit-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); -moz-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2); box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
border-radius: 3px; border-radius: 3px;
border: 1px solid silver; border: 1px solid silver;
@ -19,18 +19,18 @@
max-height: 20em; max-height: 20em;
overflow-y: auto; overflow-y: auto;
} }
.CodeMirror-hint { .CodeMirror-hint {
margin: 0; margin: 0;
padding: 0 4px; padding: 0 4px;
border-radius: 2px; border-radius: 2px;
white-space: pre; white-space: pre;
color: black; color: black;
cursor: pointer; cursor: pointer;
} }
li.CodeMirror-hint-active { li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
} }

View File

@ -1,14 +1,14 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) { (function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function (CodeMirror) {
"use strict"; "use strict";
var HINT_ELEMENT_CLASS = "CodeMirror-hint"; var HINT_ELEMENT_CLASS = "CodeMirror-hint";
@ -16,7 +16,7 @@
// This is the old interface, kept around for now to stay // This is the old interface, kept around for now to stay
// backwards-compatible. // backwards-compatible.
CodeMirror.showHint = function(cm, getHints, options) { CodeMirror.showHint = function (cm, getHints, options) {
if (!getHints) return cm.showHint(options); if (!getHints) return cm.showHint(options);
if (options && options.async) getHints.async = true; if (options && options.async) getHints.async = true;
var newOpts = {hint: getHints}; var newOpts = {hint: getHints};
@ -24,7 +24,7 @@
return cm.showHint(newOpts); return cm.showHint(newOpts);
}; };
CodeMirror.defineExtension("showHint", function(options) { CodeMirror.defineExtension("showHint", function (options) {
options = parseOptions(this, this.getCursor("start"), options); options = parseOptions(this, this.getCursor("start"), options);
var selections = this.listSelections() var selections = this.listSelections()
if (selections.length > 1) return; if (selections.length > 1) return;
@ -56,16 +56,18 @@
this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length; this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
var self = this; var self = this;
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); }); cm.on("cursorActivity", this.activityFunc = function () {
self.cursorActivity();
});
} }
var requestAnimationFrame = window.requestAnimationFrame || function(fn) { var requestAnimationFrame = window.requestAnimationFrame || function (fn) {
return setTimeout(fn, 1000/60); return setTimeout(fn, 1000 / 60);
}; };
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout; var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
Completion.prototype = { Completion.prototype = {
close: function() { close: function () {
if (!this.active()) return; if (!this.active()) return;
this.cm.state.completionActive = null; this.cm.state.completionActive = null;
this.tick = null; this.tick = null;
@ -76,11 +78,11 @@
CodeMirror.signal(this.cm, "endCompletion", this.cm); CodeMirror.signal(this.cm, "endCompletion", this.cm);
}, },
active: function() { active: function () {
return this.cm.state.completionActive == this; return this.cm.state.completionActive == this;
}, },
pick: function(data, i) { pick: function (data, i) {
var completion = data.list[i]; var completion = data.list[i];
if (completion.hint) completion.hint(this.cm, data, completion); if (completion.hint) completion.hint(this.cm, data, completion);
else this.cm.replaceRange(getText(completion), completion.from || data.from, else this.cm.replaceRange(getText(completion), completion.from || data.from,
@ -89,7 +91,7 @@
this.close(); this.close();
}, },
cursorActivity: function() { cursorActivity: function () {
if (this.debounce) { if (this.debounce) {
cancelAnimationFrame(this.debounce); cancelAnimationFrame(this.debounce);
this.debounce = 0; this.debounce = 0;
@ -102,20 +104,22 @@
this.close(); this.close();
} else { } else {
var self = this; var self = this;
this.debounce = requestAnimationFrame(function() {self.update();}); this.debounce = requestAnimationFrame(function () {
self.update();
});
if (this.widget) this.widget.disable(); if (this.widget) this.widget.disable();
} }
}, },
update: function(first) { update: function (first) {
if (this.tick == null) return if (this.tick == null) return
var self = this, myTick = ++this.tick var self = this, myTick = ++this.tick
fetchHints(this.options.hint, this.cm, this.options, function(data) { fetchHints(this.options.hint, this.cm, this.options, function (data) {
if (self.tick == myTick) self.finishUpdate(data, first) if (self.tick == myTick) self.finishUpdate(data, first)
}) })
}, },
finishUpdate: function(data, first) { finishUpdate: function (data, first) {
if (this.data) CodeMirror.signal(this.data, "update"); if (this.data) CodeMirror.signal(this.data, "update");
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle); var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
@ -153,22 +157,37 @@
function buildKeyMap(completion, handle) { function buildKeyMap(completion, handle) {
var baseMap = { var baseMap = {
Up: function() {handle.moveFocus(-1);}, Up: function () {
Down: function() {handle.moveFocus(1);}, handle.moveFocus(-1);
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);}, },
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);}, Down: function () {
Home: function() {handle.setFocus(0);}, handle.moveFocus(1);
End: function() {handle.setFocus(handle.length - 1);}, },
PageUp: function () {
handle.moveFocus(-handle.menuSize() + 1, true);
},
PageDown: function () {
handle.moveFocus(handle.menuSize() - 1, true);
},
Home: function () {
handle.setFocus(0);
},
End: function () {
handle.setFocus(handle.length - 1);
},
Enter: handle.pick, Enter: handle.pick,
Tab: handle.pick, Tab: handle.pick,
Esc: handle.close Esc: handle.close
}; };
var custom = completion.options.customKeys; var custom = completion.options.customKeys;
var ourMap = custom ? {} : baseMap; var ourMap = custom ? {} : baseMap;
function addBinding(key, val) { function addBinding(key, val) {
var bound; var bound;
if (typeof val != "string") if (typeof val != "string")
bound = function(cm) { return val(cm, handle); }; bound = function (cm) {
return val(cm, handle);
};
// This mechanism is deprecated // This mechanism is deprecated
else if (baseMap.hasOwnProperty(val)) else if (baseMap.hasOwnProperty(val))
bound = baseMap[val]; bound = baseMap[val];
@ -176,6 +195,7 @@
bound = val; bound = val;
ourMap[key] = bound; ourMap[key] = bound;
} }
if (custom) if (custom)
for (var key in custom) if (custom.hasOwnProperty(key)) for (var key in custom) if (custom.hasOwnProperty(key))
addBinding(key, custom[key]); addBinding(key, custom[key]);
@ -254,22 +274,38 @@
node.style.paddingRight = cm.display.nativeBarWidth + "px" node.style.paddingRight = cm.display.nativeBarWidth + "px"
cm.addKeyMap(this.keyMap = buildKeyMap(completion, { cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); }, moveFocus: function (n, avoidWrap) {
setFocus: function(n) { widget.changeActive(n); }, widget.changeActive(widget.selectedHint + n, avoidWrap);
menuSize: function() { return widget.screenAmount(); }, },
setFocus: function (n) {
widget.changeActive(n);
},
menuSize: function () {
return widget.screenAmount();
},
length: completions.length, length: completions.length,
close: function() { completion.close(); }, close: function () {
pick: function() { widget.pick(); }, completion.close();
},
pick: function () {
widget.pick();
},
data: data data: data
})); }));
if (completion.options.closeOnUnfocus) { if (completion.options.closeOnUnfocus) {
var closingOnBlur; var closingOnBlur;
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); }); cm.on("blur", this.onBlur = function () {
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); }); closingOnBlur = setTimeout(function () {
completion.close();
}, 100);
});
cm.on("focus", this.onFocus = function () {
clearTimeout(closingOnBlur);
});
} }
cm.on("scroll", this.onScroll = function() { cm.on("scroll", this.onScroll = function () {
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect(); var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
var newTop = top + startScroll.top - curScroll.top; var newTop = top + startScroll.top - curScroll.top;
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop); var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
@ -279,12 +315,15 @@
hints.style.left = (left + startScroll.left - curScroll.left) + "px"; hints.style.left = (left + startScroll.left - curScroll.left) + "px";
}); });
CodeMirror.on(hints, "dblclick", function(e) { CodeMirror.on(hints, "dblclick", function (e) {
var t = getHintElement(hints, e.target || e.srcElement); var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();} if (t && t.hintId != null) {
widget.changeActive(t.hintId);
widget.pick();
}
}); });
CodeMirror.on(hints, "click", function(e) { CodeMirror.on(hints, "click", function (e) {
var t = getHintElement(hints, e.target || e.srcElement); var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) { if (t && t.hintId != null) {
widget.changeActive(t.hintId); widget.changeActive(t.hintId);
@ -292,8 +331,10 @@
} }
}); });
CodeMirror.on(hints, "mousedown", function() { CodeMirror.on(hints, "mousedown", function () {
setTimeout(function(){cm.focus();}, 20); setTimeout(function () {
cm.focus();
}, 20);
}); });
CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]); CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
@ -301,7 +342,7 @@
} }
Widget.prototype = { Widget.prototype = {
close: function() { close: function () {
if (this.completion.widget != this) return; if (this.completion.widget != this) return;
this.completion.widget = null; this.completion.widget = null;
this.hints.parentNode.removeChild(this.hints); this.hints.parentNode.removeChild(this.hints);
@ -315,18 +356,22 @@
cm.off("scroll", this.onScroll); cm.off("scroll", this.onScroll);
}, },
disable: function() { disable: function () {
this.completion.cm.removeKeyMap(this.keyMap); this.completion.cm.removeKeyMap(this.keyMap);
var widget = this; var widget = this;
this.keyMap = {Enter: function() { widget.picked = true; }}; this.keyMap = {
Enter: function () {
widget.picked = true;
}
};
this.completion.cm.addKeyMap(this.keyMap); this.completion.cm.addKeyMap(this.keyMap);
}, },
pick: function() { pick: function () {
this.completion.pick(this.data, this.selectedHint); this.completion.pick(this.data, this.selectedHint);
}, },
changeActive: function(i, avoidWrap) { changeActive: function (i, avoidWrap) {
if (i >= this.data.list.length) if (i >= this.data.list.length)
i = avoidWrap ? this.data.list.length - 1 : 0; i = avoidWrap ? this.data.list.length - 1 : 0;
else if (i < 0) else if (i < 0)
@ -343,7 +388,7 @@
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node); CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
}, },
screenAmount: function() { screenAmount: function () {
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1; return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
} }
}; };
@ -369,26 +414,33 @@
function resolveAutoHints(cm, pos) { function resolveAutoHints(cm, pos) {
var helpers = cm.getHelpers(pos, "hint"), words var helpers = cm.getHelpers(pos, "hint"), words
if (helpers.length) { if (helpers.length) {
var resolved = function(cm, callback, options) { var resolved = function (cm, callback, options) {
var app = applicableHelpers(cm, helpers); var app = applicableHelpers(cm, helpers);
function run(i) { function run(i) {
if (i == app.length) return callback(null) if (i == app.length) return callback(null)
fetchHints(app[i], cm, options, function(result) { fetchHints(app[i], cm, options, function (result) {
if (result && result.list.length > 0) callback(result) if (result && result.list.length > 0) callback(result)
else run(i + 1) else run(i + 1)
}) })
} }
run(0) run(0)
} }
resolved.async = true resolved.async = true
resolved.supportsSelection = true resolved.supportsSelection = true
return resolved return resolved
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) { } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) } return function (cm) {
return CodeMirror.hint.fromList(cm, {words: words})
}
} else if (CodeMirror.hint.anyword) { } else if (CodeMirror.hint.anyword) {
return function(cm, options) { return CodeMirror.hint.anyword(cm, options) } return function (cm, options) {
return CodeMirror.hint.anyword(cm, options)
}
} else { } else {
return function() {} return function () {
}
} }
} }
@ -396,7 +448,7 @@
resolve: resolveAutoHints resolve: resolveAutoHints
}); });
CodeMirror.registerHelper("hint", "fromList", function(cm, options) { CodeMirror.registerHelper("hint", "fromList", function (cm, options) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur); var cur = cm.getCursor(), token = cm.getTokenAt(cur);
var to = CodeMirror.Pos(cur.line, token.end); var to = CodeMirror.Pos(cur.line, token.end);
if (token.string && /\w/.test(token.string[token.string.length - 1])) { if (token.string && /\w/.test(token.string[token.string.length - 1])) {
@ -429,4 +481,4 @@
}; };
CodeMirror.defineOption("hintOptions", null); CodeMirror.defineOption("hintOptions", null);
}); });

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,74 +1,74 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="96px" height="124px"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="96px" height="124px">
<style type="text/css"> <style type="text/css">
#background { #background {
fill: none; fill: none;
} }
.arrows { .arrows {
fill: #000; fill: #000;
stroke: none; stroke: none;
} }
.selected>.arrows { .selected>.arrows {
fill: #fff; fill: #fff;
} }
.checkmark { .checkmark {
fill: #000; fill: #000;
font-family: sans-serif; font-family: sans-serif;
font-size: 10pt; font-size: 10pt;
text-anchor: middle; text-anchor: middle;
} }
.trash { .trash {
fill: #888; fill: #888;
} }
.zoom { .zoom {
fill: none; fill: none;
stroke: #888; stroke: #888;
stroke-width: 2; stroke-width: 2;
stroke-linecap: round; stroke-linecap: round;
} }
.zoom>.center { .zoom>.center {
fill: #888; fill: #888;
stroke-width: 0; stroke-width: 0;
} }
</style> </style>
<rect id="background" width="96" height="124" x="0" y="0" /> <rect id="background" width="96" height="124" x="0" y="0"/>
<g> <g>
<path class="arrows" d="M 13,1.5 13,14.5 1.74,8 z" /> <path class="arrows" d="M 13,1.5 13,14.5 1.74,8 z"/>
<path class="arrows" d="M 17.5,3 30.5,3 24,14.26 z" /> <path class="arrows" d="M 17.5,3 30.5,3 24,14.26 z"/>
<path class="arrows" d="M 35,1.5 35,14.5 46.26,8 z" /> <path class="arrows" d="M 35,1.5 35,14.5 46.26,8 z"/>
</g> </g>
<g class="selected" transform="translate(0, 16)"> <g class="selected" transform="translate(0, 16)">
<path class="arrows" d="M 13,1.5 13,14.5 1.74,8 z" /> <path class="arrows" d="M 13,1.5 13,14.5 1.74,8 z"/>
<path class="arrows" d="M 17.5,3 30.5,3 24,14.26 z" /> <path class="arrows" d="M 17.5,3 30.5,3 24,14.26 z"/>
<path class="arrows" d="M 35,1.5 35,14.5 46.26,8 z" /> <path class="arrows" d="M 35,1.5 35,14.5 46.26,8 z"/>
</g> </g>
<text class="checkmark" x="55.5" y="28">&#10003;</text> <text class="checkmark" x="55.5" y="28">&#10003;</text>
<g class="trash"> <g class="trash">
<path d="M 2,41 v 6 h 42 v -6 h -10.5 l -3,-3 h -15 l -3,3 z" /> <path d="M 2,41 v 6 h 42 v -6 h -10.5 l -3,-3 h -15 l -3,3 z"/>
<rect width="36" height="20" x="5" y="50" /> <rect width="36" height="20" x="5" y="50"/>
<rect width="36" height="42" x="5" y="50" rx="4" ry="4" /> <rect width="36" height="42" x="5" y="50" rx="4" ry="4"/>
</g> </g>
<g class="zoom"> <g class="zoom">
<circle r="11.5" cx="16" cy="108" /> <circle r="11.5" cx="16" cy="108"/>
<circle r="4.3" cx="16" cy="108" class="center" /> <circle r="4.3" cx="16" cy="108" class="center"/>
<path d="m 28,108 h3" /> <path d="m 28,108 h3"/>
<path d="m 1,108 h3" /> <path d="m 1,108 h3"/>
<path d="m 16,120 v3" /> <path d="m 16,120 v3"/>
<path d="m 16,93 v3" /> <path d="m 16,93 v3"/>
</g> </g>
<g class="zoom"> <g class="zoom">
<circle r="15" cx="48" cy="108" /> <circle r="15" cx="48" cy="108"/>
<path d="m 48,101.6 v12.8" /> <path d="m 48,101.6 v12.8"/>
<path d="m 41.6,108 h12.8" /> <path d="m 41.6,108 h12.8"/>
</g> </g>
<g class="zoom"> <g class="zoom">
<circle r="15" cx="80" cy="108" /> <circle r="15" cx="80" cy="108"/>
<path d="m 73.6,108 h12.8" /> <path d="m 73.6,108 h12.8"/>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,9 +1,14 @@
html,body,div,img{margin:0;padding:0;} html, body, div, img {
body{ margin: 0;
font-family: Roboto,"Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;; padding: 0;
}
body {
font-family: Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;;
background-color: #F5F5F5; background-color: #F5F5F5;
} }
/* ::-webkit-scrollbar { /* ::-webkit-scrollbar {
width: 5px; width: 5px;
} */ } */
@ -12,12 +17,14 @@ body{
min-height: 500px; min-height: 500px;
margin: 0 auto; margin: 0 auto;
} }
#left, #mid, #right{
#left, #mid, #right {
border-radius: 2px; border-radius: 2px;
box-sizing: border-box; box-sizing: border-box;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12); box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
} }
#left{
#left {
position: absolute; position: absolute;
left: 5px; left: 5px;
top: 10px; top: 10px;
@ -25,7 +32,7 @@ body{
height: 630px; height: 630px;
} }
#editArea{ #editArea {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 70%; height: 70%;
@ -34,7 +41,8 @@ body{
/* padding: 10px 5px; */ /* padding: 10px 5px; */
box-sizing: border-box; box-sizing: border-box;
} }
#pout{
#pout {
display: block; display: block;
width: 410px; width: 410px;
height: 100%; height: 100%;
@ -49,14 +57,16 @@ body{
border-radius: 2px; border-radius: 2px;
overflow: auto; overflow: auto;
} }
#editTip{
#editTip {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 80px; margin-bottom: 120px;
bottom:10px; bottom: 0;
left: 10px; left: 10px;
} }
#editArea p{
#editArea p {
margin: 10px; margin: 10px;
display: block; display: block;
width: 70%; width: 70%;
@ -64,18 +74,21 @@ body{
text-align: left; text-align: left;
font-size: 14px; font-size: 14px;
} }
#editTip .btn{
#editTip .btn {
float: right; float: right;
margin-right: 20px; margin-right: 20px;
margin-top: 5px; margin-top: 5px;
} }
#mid{
#mid {
position: absolute; position: absolute;
left: 448px; left: 448px;
top: 10px; top: 10px;
width: 440px; width: 440px;
height: 630px; height: 630px;
} }
.map { .map {
position: absolute; position: absolute;
left: 20px; left: 20px;
@ -83,7 +96,8 @@ body{
width: 416px; width: 416px;
height: 416px; height: 416px;
} }
#mid .tools{
#mid .tools {
position: absolute; position: absolute;
width: 425px; width: 425px;
height: 180px; height: 180px;
@ -94,7 +108,8 @@ body{
margin-left: 8px;; margin-left: 8px;;
box-sizing: border-box; box-sizing: border-box;
} }
#tip{
#tip {
float: right; float: right;
width: 50%; width: 50%;
height: 95%; height: 95%;
@ -106,13 +121,15 @@ body{
font-size: 15px; font-size: 15px;
line-height: 14px; line-height: 14px;
} }
.files { .files {
width: 50%; width: 50%;
height: 120px; height: 120px;
/* padding: 10px; */ /* padding: 10px; */
margin-top: 15px; margin-top: 15px;
} }
.input{
.input {
display: block; display: block;
max-width: 150px; max-width: 150px;
height: 20px; height: 20px;
@ -123,23 +140,27 @@ body{
background-color: #fff; background-color: #fff;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 3px; border-radius: 3px;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
} }
#bgSelect{
#bgSelect {
width: 50%; width: 50%;
height: 100px; height: 100px;
margin-top: 10px; margin-top: 10px;
} }
#bgSelect span{
#bgSelect span {
/* display: block; */ /* display: block; */
font-size: 14px; font-size: 14px;
line-height: 30px; line-height: 30px;
} }
#printOut{
#printOut {
margin-top: 10px; margin-top: 10px;
height: 20px; height: 20px;
} }
.btn { .btn {
width: 80px; width: 80px;
border-radius: 2px; border-radius: 2px;
@ -159,16 +180,18 @@ body{
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
border: 0; border: 0;
background: rgba(158,158,158,.2); background: rgba(158, 158, 158, .2);
box-shadow: 0 1px 1px 0 rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.2), 0 1px 3px 0 rgba(0,0,0,.12); box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .14), 0 2px 1px -1px rgba(0, 0, 0, .2), 0 1px 3px 0 rgba(0, 0, 0, .12);
color: #fff; color: #fff;
background-color: #26A69A; background-color: #26A69A;
} }
.btn:hover { .btn:hover {
background-color: #009688; background-color: #009688;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12); box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
} }
#right{
#right {
position: absolute; position: absolute;
left: 900px; left: 900px;
top: 10px; top: 10px;
@ -176,7 +199,8 @@ body{
height: 630px; height: 630px;
/* border: 1px solid rgb(238, 13, 13); */ /* border: 1px solid rgb(238, 13, 13); */
} }
#iconLib{
#iconLib {
position: absolute; position: absolute;
width: 435px; width: 435px;
height: 620px; height: 620px;
@ -184,38 +208,44 @@ body{
top: 5px; top: 5px;
overflow: auto; overflow: auto;
} }
.egameCanvas { .egameCanvas {
position: absolute; position: absolute;
} }
.gameCanvas { .gameCanvas {
position: absolute; position: absolute;
} }
#dataSelection , .appendSelection{
#dataSelection, .appendSelection {
position: absolute; position: absolute;
/* top:0; /* top:0;
left:320px; */ left:320px; */
z-index:75; z-index: 75;
width:26px; width: 26px;
height:26px; height: 26px;
margin: 3px 0 0 3px; margin: 3px 0 0 3px;
padding:0; padding: 0;
/* display: none; */ /* display: none; */
box-sizing: border-box; box-sizing: border-box;
background-color:rgba(255, 255, 255, 0.0); background-color: rgba(255, 255, 255, 0.0);
border: 1px solid #000; border: 1px solid #000;
box-shadow: 0 0 0 2px #fff, box-shadow: 0 0 0 2px #fff,
0 0 0 3px #000; 0 0 0 3px #000;
} }
.warnText{
.warnText {
color: #D50000; color: #D50000;
font-weight: 700; font-weight: 700;
font-size: 14px; font-size: 14px;
line-height: 1.2em; line-height: 1.2em;
} }
.infoText{
.infoText {
color: #2196F3; color: #2196F3;
} }
.successText{
.successText {
color: #00897B; color: #00897B;
line-height: 1.2em; line-height: 1.2em;
} }
@ -223,20 +253,24 @@ body{
table, td { table, td {
border: 1px solid #fff; border: 1px solid #fff;
color: #fff; color: #fff;
cursor:crosshair; cursor: crosshair;
} }
table.col{
table.col {
position: relative; position: relative;
text-align: center; text-align: center;
border-collapse: collapse; border-collapse: collapse;
} }
table.col td{
table.col td {
background-color: #4DB6AC; background-color: #4DB6AC;
} }
#arrColMark td{
#arrColMark td {
width: 16px; width: 16px;
} }
#arrColMark { #arrColMark {
top: 2px; top: 2px;
left: 36px; left: 36px;
@ -244,6 +278,7 @@ table.col td{
height: 16px; height: 16px;
font-size: 13px; font-size: 13px;
} }
#mapColMark { #mapColMark {
top: 2px; top: 2px;
left: 19px; left: 19px;
@ -251,51 +286,60 @@ table.col td{
height: 16px; height: 16px;
font-size: 13px; font-size: 13px;
} }
#mapColMark td{
#mapColMark td {
width: 29px; width: 29px;
} }
#mapColMark td:hover .colBlock{
#mapColMark td:hover .colBlock {
position: absolute; position: absolute;
top: 19px; top: 19px;
height: 416px; height: 416px;
width: 32px; width: 32px;
z-index: 100; z-index: 100;
background-color: rgba(38,166,154,.5); background-color: rgba(38, 166, 154, .5);
} }
table.row{
table.row {
position: relative; position: relative;
text-align: right; text-align: right;
vertical-align:middle; vertical-align: middle;
border-collapse: collapse; border-collapse: collapse;
} }
table.row td{
table.row td {
background-color: #4C221B; background-color: #4C221B;
} }
#arrRowMark{
#arrRowMark {
top: 5px; top: 5px;
left: 2px; left: 2px;
width: 16px; width: 16px;
height: 262px; height: 262px;
font-size: 12px; font-size: 12px;
} }
#mapRowMark{
#mapRowMark {
top: 1px; top: 1px;
left: 2px; left: 2px;
width: 16px; width: 16px;
height: 416px; height: 416px;
font-size: 12px; font-size: 12px;
} }
#mapRowMark td{
#mapRowMark td {
height: 29px; height: 29px;
} }
#mapRowMark td:hover .rowBlock{
#mapRowMark td:hover .rowBlock {
position: absolute; position: absolute;
left: 18px; left: 18px;
height: 32px; height: 32px;
width: 416px; width: 416px;
z-index: 100; z-index: 100;
background-color: rgba(76,34,27,.5); background-color: rgba(76, 34, 27, .5);
} }
/* for vue dom */ /* for vue dom */
[v-cloak] { [v-cloak] {
display: none !important; display: none !important;

View File

@ -1,7 +1,7 @@
.leftTab { .leftTab {
border-radius: 2px; border-radius: 2px;
box-sizing: border-box; box-sizing: border-box;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12); box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
} }
.leftTab { .leftTab {
@ -9,9 +9,18 @@
position: absolute; position: absolute;
height: 630px; height: 630px;
} }
.leftTab > *{margin:2.5px 5px;}
.leftTab > :first-child{margin-top:5px;} .leftTab > * {
.leftTab > :last-child{margin-bottom:5px;} margin: 2.5px 5px;
}
.leftTab > :first-child {
margin-top: 5px;
}
.leftTab > :last-child {
margin-bottom: 5px;
}
.leftTab { .leftTab {
left: 5px; left: 5px;
@ -31,7 +40,7 @@
#appendPicSelection span { #appendPicSelection span {
position: absolute; position: absolute;
font-size:11px; font-size: 11px;
-webkit-text-stroke: 1px red; -webkit-text-stroke: 1px red;
text-shadow: black 1px 0, black 0 1px, black -1px 0, black 0 -1px; text-shadow: black 1px 0, black 0 1px, black -1px 0, black 0 -1px;
} }
@ -63,7 +72,12 @@
height: 95%; height: 95%;
width: 35%; width: 35%;
} }
#left6 #codeArea {width: 99.5%; height: 15.4em;overflow:y;/* resize:none; */}
#left6 #codeArea {
width: 99.5%;
height: 15.4em;
overflow: y; /* resize:none; */
}
#left7 { #left7 {
/* height: 440px; width: 375px;float:left; */ /* height: 440px; width: 375px;float:left; */
@ -75,6 +89,7 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
#left7 .CodeMirror { #left7 .CodeMirror {
/* border-top: 1px solid black; /* border-top: 1px solid black;
border-bottom: 1px solid black; */ border-bottom: 1px solid black; */
@ -95,36 +110,54 @@
border-spacing: 0; border-spacing: 0;
border-collapse: collapse; border-collapse: collapse;
} }
.etable table { .etable table {
margin-top: 0; margin-top: 0;
margin-bottom: 16px; margin-bottom: 16px;
} }
.etable table { .etable table {
display: block; display: block;
width: 100%; width: 100%;
overflow: auto; overflow: auto;
} }
.etable table th { .etable table th {
font-weight: 600; font-weight: 600;
} }
.etable table th, .etable table th,
.etable table td { .etable table td {
padding: 6px 13px; padding: 6px 13px;
border: 1px solid #dfe2e5; border: 1px solid #dfe2e5;
} }
.etable table tr { .etable table tr {
background-color: #fff; background-color: #fff;
border-top: 1px solid #c6cbd1; border-top: 1px solid #c6cbd1;
} }
.etable table tr:nth-child(2n) { .etable table tr:nth-child(2n) {
background-color: #f6f8fa; background-color: #f6f8fa;
} }
/* copy end --------------------------------------------- */ /* copy end --------------------------------------------- */
.etable tr {width:100%} .etable tr {
.etable tr > :nth-child(1) {width:20%} width: 100%
.etable tr > :nth-child(2) {width:20%} }
.etable tr > :nth-child(3) {width:60%}
.etable tr > :nth-child(1) {
width: 20%
}
.etable tr > :nth-child(2) {
width: 20%
}
.etable tr > :nth-child(3) {
width: 60%
}
.etable table { .etable table {
overflow: visible; overflow: visible;
@ -188,6 +221,7 @@ div.etableInputDiv {
.etableInputDiv textarea { .etableInputDiv textarea {
resize: none; resize: none;
} }
.etableInputDiv textarea:hover { .etableInputDiv textarea:hover {
margin: -5px; margin: -5px;
} }

View File

@ -3,39 +3,55 @@ function editor() {
this.material = {}; this.material = {};
} }
editor.prototype.init = function(callback){ editor.prototype.init = function (callback) {
var afterCoreReset = function(){ var afterCoreReset = function () {
main.editor.disableGlobalAnimate=false;//允许GlobalAnimate main.editor.disableGlobalAnimate = false;//允许GlobalAnimate
/* core.setHeroMoveTriggerInterval(); */ /* core.setHeroMoveTriggerInterval(); */
editor.reset(function(){ editor.reset(function () {
editor.drawMapBg(); editor.drawMapBg();
var mapArray = core.maps.save(core.status.maps,core.status.floorId); var mapArray = core.maps.save(core.status.maps, core.status.floorId);
editor.map = mapArray.map(function(v){return v.map(function(v){return editor.ids[[editor.indexs[parseInt(v)][0]]]})}); editor.map = mapArray.map(function (v) {
return v.map(function (v) {
return editor.ids[[editor.indexs[parseInt(v)][0]]]
})
});
editor.updateMap(); editor.updateMap();
editor.currentFloorId=core.status.floorId; editor.currentFloorId = core.status.floorId;
editor.currentFloorData = core.floors[core.status.floorId]; editor.currentFloorData = core.floors[core.status.floorId];
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
}); });
} }
var afterMainInit = function(){ var afterMainInit = function () {
core.floors=JSON.parse(JSON.stringify(core.floors,function(k,v){if(v instanceof Function){return v.toString()}else return v})); core.floors = JSON.parse(JSON.stringify(core.floors, function (k, v) {
core.data=JSON.parse(JSON.stringify(core.data,function(k,v){if(v instanceof Function){return v.toString()}else return v})); if (v instanceof Function) {
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d=JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d,function(k,v){if(v instanceof Function){return v.toString()}else return v})); return v.toString()
editor.main=main; } else return v
editor.core=core; }));
editor.fs=fs; core.data = JSON.parse(JSON.stringify(core.data, function (k, v) {
editor_file = editor_file(editor, function() { if (v instanceof Function) {
editor.file=editor_file; return v.toString()
} else return v
}));
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, function (k, v) {
if (v instanceof Function) {
return v.toString()
} else return v
}));
editor.main = main;
editor.core = core;
editor.fs = fs;
editor_file = editor_file(editor, function () {
editor.file = editor_file;
editor_mode = editor_mode(editor); editor_mode = editor_mode(editor);
editor.mode=editor_mode; editor.mode = editor_mode;
editor.material.images=core.material.images; editor.material.images = core.material.images;
editor.listen(); // 开始监听事件 editor.listen(); // 开始监听事件
core.resetStatus(core.firstData.hero, null, core.firstData.floorId, null, core.initStatus.maps); core.resetStatus(core.firstData.hero, null, core.firstData.floorId, null, core.initStatus.maps);
core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() { core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function () {
afterCoreReset(); afterCoreReset();
}, true); }, true);
core.events.setInitData(null); core.events.setInitData(null);
@ -44,90 +60,90 @@ editor.prototype.init = function(callback){
afterMainInit(); afterMainInit();
} }
editor.prototype.reset = function(callback){ editor.prototype.reset = function (callback) {
editor.idsInit(core.maps, core.icons.icons); // 初始化图片素材信息 editor.idsInit(core.maps, core.icons.icons); // 初始化图片素材信息
editor.drawInitData(core.icons.icons); // 初始化绘图 editor.drawInitData(core.icons.icons); // 初始化绘图
if(Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
editor.prototype.idsInit = function(maps, icons){ editor.prototype.idsInit = function (maps, icons) {
editor.ids = [0]; editor.ids = [0];
editor.indexs = []; editor.indexs = [];
var MAX_NUM = 1000; var MAX_NUM = 1000;
var getInfoById = function(id){ var getInfoById = function (id) {
var block = maps.initBlock(0, 0, id); var block = maps.initBlock(0, 0, id);
if(hasOwnProp(block, 'event')){ if (hasOwnProp(block, 'event')) {
return block; return block;
} }
} }
var point = 0; var point = 0;
for(var i=0; i<MAX_NUM; i++){ for (var i = 0; i < MAX_NUM; i++) {
var indexBlock = getInfoById(i); var indexBlock = getInfoById(i);
editor.indexs[i] = []; editor.indexs[i] = [];
if(indexBlock){ if (indexBlock) {
var id = indexBlock.event.id; var id = indexBlock.event.id;
var indexId = indexBlock.id; var indexId = indexBlock.id;
var allCls = Object.keys(icons); var allCls = Object.keys(icons);
for(var j=0; j<allCls.length; j++){ for (var j = 0; j < allCls.length; j++) {
if(id in icons[allCls[j]] ){ if (id in icons[allCls[j]]) {
editor.ids.push({'idnum':indexId,'id':id,'images':allCls[j],'y':icons[allCls[j]][id]}); editor.ids.push({'idnum': indexId, 'id': id, 'images': allCls[j], 'y': icons[allCls[j]][id]});
point++; point++;
editor.indexs[i].push(point); editor.indexs[i].push(point);
} }
} }
} }
} }
editor.indexs[0]=[0]; editor.indexs[0] = [0];
} }
editor.prototype.drawInitData = function (icons) { editor.prototype.drawInitData = function (icons) {
var ratio=1; var ratio = 1;
var images=editor.material.images; var images = editor.material.images;
var maxHeight=700; var maxHeight = 700;
var sumWidth=0; var sumWidth = 0;
editor.widthsX={}; editor.widthsX = {};
// var imgNames = Object.keys(images); //还是固定顺序吧; // var imgNames = Object.keys(images); //还是固定顺序吧;
var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"]; var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"];
for(var ii=0; ii<imgNames.length; ii++){ for (var ii = 0; ii < imgNames.length; ii++) {
var img=imgNames[ii], tempy = 0; var img = imgNames[ii], tempy = 0;
if(img == 'autotile'){ if (img == 'autotile') {
var autotiles = images[img]; var autotiles = images[img];
for(var im in autotiles){ for (var im in autotiles) {
tempy += autotiles[im].height; tempy += autotiles[im].height;
} }
editor.widthsX[img]=[img, sumWidth/32, (sumWidth+3*32)/32, tempy]; editor.widthsX[img] = [img, sumWidth / 32, (sumWidth + 3 * 32) / 32, tempy];
sumWidth += 3*32; sumWidth += 3 * 32;
maxHeight = Math.max(maxHeight, tempy); maxHeight = Math.max(maxHeight, tempy);
continue; continue;
} }
if(img == 'terrains'){ if (img == 'terrains') {
editor.widthsX[img]=[img, sumWidth/32, (sumWidth+images[img].width)/32, images[img].height+32] editor.widthsX[img] = [img, sumWidth / 32, (sumWidth + images[img].width) / 32, images[img].height + 32]
sumWidth += images[img].width; sumWidth += images[img].width;
maxHeight = Math.max(maxHeight, images[img].height+32); maxHeight = Math.max(maxHeight, images[img].height + 32);
continue; continue;
} }
editor.widthsX[img]=[img, sumWidth/32, (sumWidth+images[img].width)/32, images[img].height]; editor.widthsX[img] = [img, sumWidth / 32, (sumWidth + images[img].width) / 32, images[img].height];
sumWidth += images[img].width; sumWidth += images[img].width;
maxHeight = Math.max(maxHeight, images[img].height); maxHeight = Math.max(maxHeight, images[img].height);
} }
var fullWidth=~~(sumWidth*ratio); var fullWidth = ~~(sumWidth * ratio);
var fullHeight=~~(maxHeight*ratio); var fullHeight = ~~(maxHeight * ratio);
if (fullWidth > edata.width) edata.style.width = (edata.width = fullWidth)/ratio + 'px'; if (fullWidth > edata.width) edata.style.width = (edata.width = fullWidth) / ratio + 'px';
edata.style.height = (edata.height = fullHeight)/ratio + 'px'; edata.style.height = (edata.height = fullHeight) / ratio + 'px';
var dc = edata.getContext('2d'); var dc = edata.getContext('2d');
var nowx = 0; var nowx = 0;
var nowy = 0; var nowy = 0;
for(var ii=0; ii<imgNames.length; ii++){ for (var ii = 0; ii < imgNames.length; ii++) {
var img=imgNames[ii]; var img = imgNames[ii];
if(img == 'terrains'){ if (img == 'terrains') {
dc.drawImage(images[img], nowx, 32); dc.drawImage(images[img], nowx, 32);
nowx += images[img].width; nowx += images[img].width;
continue; continue;
} }
if(img == 'autotile'){ if (img == 'autotile') {
var autotiles = images[img]; var autotiles = images[img];
for(var im in autotiles){ for (var im in autotiles) {
dc.drawImage(autotiles[im], nowx, nowy); dc.drawImage(autotiles[im], nowx, nowy);
nowy += autotiles[im].height; nowy += autotiles[im].height;
} }
@ -140,65 +156,69 @@ editor.prototype.drawInitData = function (icons) {
//editor.drawMapBg(); //editor.drawMapBg();
//editor.mapInit(); //editor.mapInit();
} }
editor.prototype.mapInit = function(){ editor.prototype.mapInit = function () {
var ec = document.getElementById('event').getContext('2d'); var ec = document.getElementById('event').getContext('2d');
ec.clearRect(0, 0, 416, 416); ec.clearRect(0, 0, 416, 416);
document.getElementById('event2').getContext('2d').clearRect(0,0,416,416); document.getElementById('event2').getContext('2d').clearRect(0, 0, 416, 416);
editor.map = []; editor.map = [];
for(var y=0; y<13; y++){ for (var y = 0; y < 13; y++) {
editor.map[y] = []; editor.map[y] = [];
for(var x = 0; x<13; x++){ for (var x = 0; x < 13; x++) {
editor.map[y][x] = 0; editor.map[y][x] = 0;
} }
} }
editor.currentFloorData.map=editor.map; editor.currentFloorData.map = editor.map;
editor.currentFloorData.firstArrive=[]; editor.currentFloorData.firstArrive = [];
editor.currentFloorData.events={}; editor.currentFloorData.events = {};
editor.currentFloorData.changeFloor={}; editor.currentFloorData.changeFloor = {};
editor.currentFloorData.afterBattle={}; editor.currentFloorData.afterBattle = {};
editor.currentFloorData.afterGetItem={}; editor.currentFloorData.afterGetItem = {};
editor.currentFloorData.afterOpenDoor={}; editor.currentFloorData.afterOpenDoor = {};
editor.currentFloorData.cannotMove={}; editor.currentFloorData.cannotMove = {};
} }
editor.prototype.drawMapBg = function(img){ editor.prototype.drawMapBg = function (img) {
var bgc = bg.getContext('2d'); var bgc = bg.getContext('2d');
if (!core.isset(editor.bgY) || editor.bgY == 0){ if (!core.isset(editor.bgY) || editor.bgY == 0) {
editor.main.editor.drawMapBg(); editor.main.editor.drawMapBg();
return; return;
} }
for (var ii = 0; ii < 13; ii++) for (var ii = 0; ii < 13; ii++)
for (var jj = 0; jj < 13; jj++) { for (var jj = 0; jj < 13; jj++) {
bgc.clearRect(ii*32, jj*32, 32, 32); bgc.clearRect(ii * 32, jj * 32, 32, 32);
bgc.drawImage(editor.material.images['terrains'], 0, 32*(editor.bgY||0), 32, 32, ii*32, jj*32, 32, 32); bgc.drawImage(editor.material.images['terrains'], 0, 32 * (editor.bgY || 0), 32, 32, ii * 32, jj * 32, 32, 32);
} }
if(img){ if (img) {
bgc.drawImage(img, 0, 0, 416, 416); bgc.drawImage(img, 0, 0, 416, 416);
} }
} }
editor.prototype.updateMap = function(){ editor.prototype.updateMap = function () {
var blocks = main.editor.mapIntoBlocks(editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})}),{'events':{},'changeFloor':{}}); var blocks = main.editor.mapIntoBlocks(editor.map.map(function (v) {
return v.map(function (v) {
return v.idnum || v || 0
})
}), {'events': {}, 'changeFloor': {}});
core.status.thisMap.blocks = blocks; core.status.thisMap.blocks = blocks;
main.editor.updateMap(); main.editor.updateMap();
var drawTile = function(ctx, x, y, tileInfo){ // 绘制一个普通块 var drawTile = function (ctx, x, y, tileInfo) { // 绘制一个普通块
//ctx.clearRect(x*32, y*32, 32, 32); //ctx.clearRect(x*32, y*32, 32, 32);
if(tileInfo == 0) return; if (tileInfo == 0) return;
if(typeof(tileInfo) == typeof([][0]) || !hasOwnProp(tileInfo, 'idnum')) {//未定义块画红块 if (typeof(tileInfo) == typeof([][0]) || !hasOwnProp(tileInfo, 'idnum')) {//未定义块画红块
if(typeof(tileInfo) != typeof([][0]) && hasOwnProp(tileInfo, 'images')){ if (typeof(tileInfo) != typeof([][0]) && hasOwnProp(tileInfo, 'images')) {
ctx.drawImage(editor.material.images[tileInfo.images], 0, tileInfo.y*32, 32, 32, x*32, y*32, 32, 32); ctx.drawImage(editor.material.images[tileInfo.images], 0, tileInfo.y * 32, 32, 32, x * 32, y * 32, 32, 32);
} }
ctx.strokeStyle = 'red'; ctx.strokeStyle = 'red';
var OFFSET = 2; var OFFSET = 2;
ctx.lineWidth = OFFSET; ctx.lineWidth = OFFSET;
ctx.strokeRect(x*32+OFFSET, y*32+OFFSET, 32-OFFSET*2, 32-OFFSET*2); ctx.strokeRect(x * 32 + OFFSET, y * 32 + OFFSET, 32 - OFFSET * 2, 32 - OFFSET * 2);
ctx.font = "30px Verdana"; ctx.font = "30px Verdana";
ctx.textAlign = 'center' ctx.textAlign = 'center'
ctx.fillStyle = 'red'; ctx.fillStyle = 'red';
ctx.fillText("?", x*32+16, y*32+27); ctx.fillText("?", x * 32 + 16, y * 32 + 27);
return; return;
} }
//ctx.drawImage(editor.material.images[tileInfo.images], 0, tileInfo.y*32, 32, 32, x*32, y*32, 32, 32); //ctx.drawImage(editor.material.images[tileInfo.images], 0, tileInfo.y*32, 32, 32, x*32, y*32, 32, 32);
@ -291,43 +311,53 @@ editor.prototype.updateMap = function(){
*/ */
// 绘制地图 start // 绘制地图 start
var eventCtx = document.getElementById('event').getContext("2d"); var eventCtx = document.getElementById('event').getContext("2d");
for(var y=0; y<13; y++) for (var y = 0; y < 13; y++)
for(var x=0; x<13; x++){ for (var x = 0; x < 13; x++) {
var tileInfo = editor.map[y][x]; var tileInfo = editor.map[y][x];
if(false && isAutotile(tileInfo)){ if (false && isAutotile(tileInfo)) {
addIndexToAutotileInfo(x, y); addIndexToAutotileInfo(x, y);
drawAutotile(eventCtx, x, y, tileInfo); drawAutotile(eventCtx, x, y, tileInfo);
}else drawTile(eventCtx, x, y, tileInfo); } else drawTile(eventCtx, x, y, tileInfo);
} }
// 绘制地图 end // 绘制地图 end
} }
editor.prototype.changeFloor = function(floorId,callback) { editor.prototype.changeFloor = function (floorId, callback) {
editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})}); editor.currentFloorData.map = editor.map.map(function (v) {
core.changeFloor(floorId, null, core.firstData.hero.loc, null, function(){ return v.map(function (v) {
return v.idnum || v || 0
})
});
core.changeFloor(floorId, null, core.firstData.hero.loc, null, function () {
editor.drawMapBg(); editor.drawMapBg();
var mapArray = core.maps.save(core.status.maps,core.status.floorId); var mapArray = core.maps.save(core.status.maps, core.status.floorId);
editor.map = mapArray.map(function(v){return v.map(function(v){return editor.ids[[editor.indexs[parseInt(v)][0]]]})}); editor.map = mapArray.map(function (v) {
return v.map(function (v) {
return editor.ids[[editor.indexs[parseInt(v)][0]]]
})
});
editor.updateMap(); editor.updateMap();
editor.currentFloorId=core.status.floorId; editor.currentFloorId = core.status.floorId;
editor.currentFloorData = core.floors[core.status.floorId]; editor.currentFloorData = core.floors[core.status.floorId];
editor_mode.floor(); editor_mode.floor();
if (core.isset(callback))callback(); if (core.isset(callback)) callback();
}); });
} }
editor.prototype.guid = function() { editor.prototype.guid = function () {
return 'id_'+'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'id_' + 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16); return v.toString(16);
}); });
} }
editor.prototype.HTMLescape = function(str_) { editor.prototype.HTMLescape = function (str_) {
return String(str_).split('').map(function(v){return '&#'+v.charCodeAt(0)+';'}).join(''); return String(str_).split('').map(function (v) {
return '&#' + v.charCodeAt(0) + ';'
}).join('');
} }
editor.prototype.listen = function() { editor.prototype.listen = function () {
var uc = eui.getContext('2d'); var uc = eui.getContext('2d');
@ -340,14 +370,15 @@ editor.prototype.listen = function() {
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
editor.loc = { editor.loc = {
'x': scrollLeft+e.clientX - mid.offsetLeft-mapEdit.offsetLeft, 'x': scrollLeft + e.clientX - mid.offsetLeft - mapEdit.offsetLeft,
'y': scrollTop+e.clientY - mid.offsetTop-mapEdit.offsetTop, 'y': scrollTop + e.clientY - mid.offsetTop - mapEdit.offsetTop,
'size': 32 'size': 32
}; };
return editor.loc; }//返回可用的组件内坐标 return editor.loc;
}//返回可用的组件内坐标
function locToPos(loc) { function locToPos(loc) {
editor.pos = { 'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.size) } editor.pos = {'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.size)}
return editor.pos; return editor.pos;
} }
@ -355,6 +386,7 @@ editor.prototype.listen = function() {
var stepPostfix = null;//用于存放寻路检测的第一个点之后的后续移动 var stepPostfix = null;//用于存放寻路检测的第一个点之后的后续移动
var mouseOutCheck = 2; var mouseOutCheck = 2;
function clear1() { function clear1() {
if (mouseOutCheck > 1) { if (mouseOutCheck > 1) {
mouseOutCheck--; mouseOutCheck--;
@ -367,7 +399,7 @@ editor.prototype.listen = function() {
}//用于鼠标移出canvas时的自动清除状态 }//用于鼠标移出canvas时的自动清除状态
eui.onmousedown = function (e) { eui.onmousedown = function (e) {
if(!selectBox.isSelected) { if (!selectBox.isSelected) {
var loc = eToLoc(e); var loc = eToLoc(e);
var pos = locToPos(loc); var pos = locToPos(loc);
editor_mode.onmode('nextChange'); editor_mode.onmode('nextChange');
@ -390,12 +422,14 @@ editor.prototype.listen = function() {
} }
eui.onmousemove = function (e) { eui.onmousemove = function (e) {
if(!selectBox.isSelected) { if (!selectBox.isSelected) {
// tip.whichShow = 1; // tip.whichShow = 1;
return; return;
} }
if (holdingPath == 0) { return; } if (holdingPath == 0) {
return;
}
mouseOutCheck = 2; mouseOutCheck = 2;
e.stopPropagation(); e.stopPropagation();
var loc = eToLoc(e); var loc = eToLoc(e);
@ -409,7 +443,7 @@ editor.prototype.listen = function() {
max = directionDistance[i]; max = directionDistance[i];
} }
} }
var pos = [{ 'x': 0, 'y': 1 }, { 'x': -1, 'y': 0 }, { 'x': 0, 'y': -1 }, { 'x': 1, 'y': 0 }, false][index] var pos = [{'x': 0, 'y': 1}, {'x': -1, 'y': 0}, {'x': 0, 'y': -1}, {'x': 1, 'y': 0}, false][index]
if (pos) { if (pos) {
pos.x += pos0.x; pos.x += pos0.x;
pos.y += pos0.y; pos.y += pos0.y;
@ -419,7 +453,7 @@ editor.prototype.listen = function() {
} }
eui.onmouseup = function (e) { eui.onmouseup = function (e) {
if(!selectBox.isSelected) { if (!selectBox.isSelected) {
tip.whichShow = 1; tip.whichShow = 1;
return; return;
} }
@ -448,22 +482,22 @@ editor.prototype.listen = function() {
info: {} info: {}
}; };
var reDo = null; var reDo = null;
document.body.onkeydown = function(e) { document.body.onkeydown = function (e) {
// 禁止快捷键的默认行为 // 禁止快捷键的默认行为
if( e.ctrlKey && ( e.keyCode == 90 || e.keyCode == 89 ) ) if (e.ctrlKey && ( e.keyCode == 90 || e.keyCode == 89 ))
e.preventDefault(); e.preventDefault();
//Ctrl+z 撤销上一步undo //Ctrl+z 撤销上一步undo
if(e.keyCode == 90 && e.ctrlKey && preMapData && currDrawData.pos.length && selectBox.isSelected){ if (e.keyCode == 90 && e.ctrlKey && preMapData && currDrawData.pos.length && selectBox.isSelected) {
editor.map = JSON.parse(JSON.stringify(preMapData)); editor.map = JSON.parse(JSON.stringify(preMapData));
editor.updateMap(); editor.updateMap();
reDo = JSON.parse(JSON.stringify(currDrawData)); reDo = JSON.parse(JSON.stringify(currDrawData));
currDrawData = {pos: [],info: {}}; currDrawData = {pos: [], info: {}};
preMapData = null; preMapData = null;
} }
//Ctrl+y 重做一步redo //Ctrl+y 重做一步redo
if(e.keyCode == 89 && e.ctrlKey && reDo && reDo.pos.length && selectBox.isSelected){ if (e.keyCode == 89 && e.ctrlKey && reDo && reDo.pos.length && selectBox.isSelected) {
preMapData = JSON.parse(JSON.stringify(editor.map)); preMapData = JSON.parse(JSON.stringify(editor.map));
for(var j=0; j<reDo.pos.length;j++) for (var j = 0; j < reDo.pos.length; j++)
editor.map[reDo.pos[j].y][reDo.pos[j].x] = JSON.parse(JSON.stringify(reDo.info)); editor.map[reDo.pos[j].y][reDo.pos[j].x] = JSON.parse(JSON.stringify(reDo.info));
editor.updateMap(); editor.updateMap();
@ -477,54 +511,54 @@ editor.prototype.listen = function() {
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var loc = { var loc = {
'x': scrollLeft + e.clientX + iconLib.scrollLeft - right.offsetLeft-iconLib.offsetLeft, 'x': scrollLeft + e.clientX + iconLib.scrollLeft - right.offsetLeft - iconLib.offsetLeft,
'y': scrollTop + e.clientY + iconLib.scrollTop - right.offsetTop-iconLib.offsetTop, 'y': scrollTop + e.clientY + iconLib.scrollTop - right.offsetTop - iconLib.offsetTop,
'size': 32 'size': 32
}; };
editor.loc = loc; editor.loc = loc;
var pos = locToPos(loc); var pos = locToPos(loc);
for (var spriter in editor.widthsX){ for (var spriter in editor.widthsX) {
if(pos.x>=editor.widthsX[spriter][1] && pos.x<editor.widthsX[spriter][2]){ if (pos.x >= editor.widthsX[spriter][1] && pos.x < editor.widthsX[spriter][2]) {
var ysize = spriter.indexOf('48')===-1?32:48; var ysize = spriter.indexOf('48') === -1 ? 32 : 48;
loc.ysize = ysize; loc.ysize = ysize;
pos.y = ~~(loc.y / loc.ysize); pos.y = ~~(loc.y / loc.ysize);
pos.x=editor.widthsX[spriter][1]; pos.x = editor.widthsX[spriter][1];
pos.images = editor.widthsX[spriter][0]; pos.images = editor.widthsX[spriter][0];
var autotiles = editor.material.images['autotile']; var autotiles = editor.material.images['autotile'];
if(pos.images=='autotile'){ if (pos.images == 'autotile') {
var imNames = Object.keys(autotiles); var imNames = Object.keys(autotiles);
if((pos.y+1)*ysize > editor.widthsX[spriter][3]) if ((pos.y + 1) * ysize > editor.widthsX[spriter][3])
pos.y = ~~(editor.widthsX[spriter][3]/ysize)-4; pos.y = ~~(editor.widthsX[spriter][3] / ysize) - 4;
else{ else {
for(var i=0; i<imNames.length; i++){ for (var i = 0; i < imNames.length; i++) {
if(pos.y >= 4*i && pos.y < 4*(i+1)){ if (pos.y >= 4 * i && pos.y < 4 * (i + 1)) {
pos.images = imNames[i]; pos.images = imNames[i];
pos.y = 4*i; pos.y = 4 * i;
} }
} }
} }
}else if((pos.y+1)*ysize > editor.widthsX[spriter][3]) } else if ((pos.y + 1) * ysize > editor.widthsX[spriter][3])
pos.y = ~~(editor.widthsX[spriter][3]/ysize)-1; pos.y = ~~(editor.widthsX[spriter][3] / ysize) - 1;
selectBox.isSelected = true; selectBox.isSelected = true;
// console.log(pos,editor.material.images[pos.images].height) // console.log(pos,editor.material.images[pos.images].height)
dataSelection.style.left = pos.x*32 +'px'; dataSelection.style.left = pos.x * 32 + 'px';
dataSelection.style.top = pos.y*ysize +'px'; dataSelection.style.top = pos.y * ysize + 'px';
dataSelection.style.height = ysize-6+'px'; dataSelection.style.height = ysize - 6 + 'px';
if(pos.x==0&&pos.y==0){ if (pos.x == 0 && pos.y == 0) {
// editor.info={idnum:0, id:'empty','images':'清除块', 'y':0}; // editor.info={idnum:0, id:'empty','images':'清除块', 'y':0};
editor.info=0; editor.info = 0;
}else{ } else {
if(hasOwnProp(autotiles, pos.images)) editor.info={'images':pos.images, 'y':0}; if (hasOwnProp(autotiles, pos.images)) editor.info = {'images': pos.images, 'y': 0};
else if(pos.images == 'terrains') editor.info={'images':pos.images, 'y':pos.y-1}; else if (pos.images == 'terrains') editor.info = {'images': pos.images, 'y': pos.y - 1};
else editor.info={'images':pos.images, 'y':pos.y}; else editor.info = {'images': pos.images, 'y': pos.y};
for (var ii=0;ii<editor.ids.length;ii++){ for (var ii = 0; ii < editor.ids.length; ii++) {
if( ( editor.info.images==editor.ids[ii].images if (( editor.info.images == editor.ids[ii].images
&& editor.info.y==editor.ids[ii].y ) && editor.info.y == editor.ids[ii].y )
|| (hasOwnProp(autotiles, pos.images) && editor.info.images==editor.ids[ii].id || (hasOwnProp(autotiles, pos.images) && editor.info.images == editor.ids[ii].id
&& editor.info.y==editor.ids[ii].y)){ && editor.info.y == editor.ids[ii].y)) {
editor.info = editor.ids[ii]; editor.info = editor.ids[ii];
break; break;

View File

@ -1,8 +1,8 @@
editor_blockly = function(){ editor_blockly = function () {
var editor_blockly = {}; var editor_blockly = {};
initscript=String.raw` initscript = String.raw`
(function(){ (function(){
var getCategory = function(name){ var getCategory = function(name){
for(var node of document.getElementById('toolbox').children) { for(var node of document.getElementById('toolbox').children) {
@ -278,8 +278,8 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){
})(); })();
`; `;
var input_=''; var input_ = '';
editor_blockly.runOne = function (){ editor_blockly.runOne = function () {
//var printf = console.log; //var printf = console.log;
//var printf = function(){}; //var printf = function(){};
var grammerFile = input_; var grammerFile = input_;
@ -293,43 +293,42 @@ editor_blockly.runOne = function (){
//console.log(converter); //console.log(converter);
var script = document.createElement('script'); var script = document.createElement('script');
//var initscript = document.getElementById('initscript').innerText; //var initscript = document.getElementById('initscript').innerText;
script.innerHTML = converter.mainFile[5]+initscript; script.innerHTML = converter.mainFile[5] + initscript;
document.body.appendChild(script); document.body.appendChild(script);
} }
var xhr=new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function (){ xhr.onreadystatechange = function () {
if(xhr.readyState!=4) return; if (xhr.readyState != 4) return;
if(xhr.status!=200) { if (xhr.status != 200) {
alert("无法在file://下加载"); alert("无法在file://下加载");
return; return;
} }
input_=xhr.responseText; input_ = xhr.responseText;
editor_blockly.runOne(); editor_blockly.runOne();
} }
xhr.open('GET','_server/blockly/MotaAction.g4',true); xhr.open('GET', '_server/blockly/MotaAction.g4', true);
xhr.send(null); xhr.send(null);
codeAreaHL = CodeMirror.fromTextArea(document.getElementById("codeArea"), { codeAreaHL = CodeMirror.fromTextArea(document.getElementById("codeArea"), {
lineNumbers: true, lineNumbers: true,
matchBrackets: true, matchBrackets: true,
lineWrapping: true, lineWrapping: true,
continueComments: "Enter", continueComments: "Enter",
extraKeys: {"Ctrl-Q": "toggleComment"} extraKeys: {"Ctrl-Q": "toggleComment"}
}); });
editor_blockly.showXML = function () { editor_blockly.showXML = function () {
var xml = Blockly.Xml.workspaceToDom(editor_blockly.workspace); var xml = Blockly.Xml.workspaceToDom(editor_blockly.workspace);
var xml_text = Blockly.Xml.domToPrettyText(xml); var xml_text = Blockly.Xml.domToPrettyText(xml);
console.log(xml_text); console.log(xml_text);
var xml_text = Blockly.Xml.domToText(xml); var xml_text = Blockly.Xml.domToText(xml);
console.log(xml_text); console.log(xml_text);
console.log(xml); console.log(xml);
} }
editor_blockly.runCode = function () { editor_blockly.runCode = function () {
// Generate JavaScript code and run it. // Generate JavaScript code and run it.
window.LoopTrap = 1000; window.LoopTrap = 1000;
Blockly.JavaScript.INFINITE_LOOP_TRAP = Blockly.JavaScript.INFINITE_LOOP_TRAP =
@ -342,97 +341,100 @@ editor_blockly.runCode = function () {
} catch (e) { } catch (e) {
alert(e); alert(e);
} }
} }
editor_blockly.parse = function () { editor_blockly.parse = function () {
MotaActionFunctions.parse( MotaActionFunctions.parse(
eval('obj=' + codeAreaHL.getValue().replace(/[<>&]/g,function(c){return {'<':'&lt;','>':'&gt;','&':'&amp;'}[c];})), eval('obj=' + codeAreaHL.getValue().replace(/[<>&]/g, function (c) {
return {'<': '&lt;', '>': '&gt;', '&': '&amp;'}[c];
})),
document.getElementById('entryType').value document.getElementById('entryType').value
); );
} }
editor_blockly.id=''; editor_blockly.id = '';
editor_blockly.import = function(id_,args){ editor_blockly.import = function (id_, args) {
var thisTr = document.getElementById(id_); var thisTr = document.getElementById(id_);
if(!thisTr)return false; if (!thisTr) return false;
var input = thisTr.children[2].children[0].children[0]; var input = thisTr.children[2].children[0].children[0];
var field = thisTr.children[0].getAttribute('title'); var field = thisTr.children[0].getAttribute('title');
var type = args.type; var type = args.type;
if(!type)return false; if (!type) return false;
editor_blockly.id=id_; editor_blockly.id = id_;
codeAreaHL.setValue(input.value); codeAreaHL.setValue(input.value);
document.getElementById('entryType').value = type; document.getElementById('entryType').value = type;
editor_blockly.parse(); editor_blockly.parse();
editor_blockly.show(); editor_blockly.show();
return true; return true;
} }
var blocklyWidgetDiv = document.getElementsByClassName('blocklyWidgetDiv'); var blocklyWidgetDiv = document.getElementsByClassName('blocklyWidgetDiv');
editor_blockly.show = function(){ editor_blockly.show = function () {
if(typeof(selectBox)!==typeof(undefined))selectBox.isSelected = false; if (typeof(selectBox) !== typeof(undefined)) selectBox.isSelected = false;
document.getElementById('left6').style=''; document.getElementById('left6').style = '';
for(var ii =0,node;node=blocklyWidgetDiv[ii];ii++){ for (var ii = 0, node; node = blocklyWidgetDiv[ii]; ii++) {
node.style.zIndex = 201; node.style.zIndex = 201;
node.style.opacity = ''; node.style.opacity = '';
} }
} }
editor_blockly.hide = function(){ editor_blockly.hide = function () {
document.getElementById('left6').style='z-index:-1;opacity: 0;'; document.getElementById('left6').style = 'z-index:-1;opacity: 0;';
for(var ii =0,node;node=blocklyWidgetDiv[ii];ii++){ for (var ii = 0, node; node = blocklyWidgetDiv[ii]; ii++) {
node.style.zIndex = -1; node.style.zIndex = -1;
node.style.opacity = 0; node.style.opacity = 0;
} }
} }
editor_blockly.cancel = function(){ editor_blockly.cancel = function () {
editor_blockly.id=''; editor_blockly.id = '';
editor_blockly.hide(); editor_blockly.hide();
} }
editor_blockly.confirm = function (){ editor_blockly.confirm = function () {
if(!editor_blockly.id){ if (!editor_blockly.id) {
editor_blockly.id=''; editor_blockly.id = '';
return; return;
} }
var setvalue = function(value){ var setvalue = function (value) {
var thisTr = document.getElementById(editor_blockly.id); var thisTr = document.getElementById(editor_blockly.id);
editor_blockly.id=''; editor_blockly.id = '';
var input = thisTr.children[2].children[0].children[0]; var input = thisTr.children[2].children[0].children[0];
input.value = value; input.value = value;
editor_blockly.hide(); editor_blockly.hide();
input.onchange(); input.onchange();
} }
if(codeAreaHL.getValue()===''){ if (codeAreaHL.getValue() === '') {
setvalue('null'); setvalue('null');
return; return;
} }
var code = Blockly.JavaScript.workspaceToCode(editor_blockly.workspace); var code = Blockly.JavaScript.workspaceToCode(editor_blockly.workspace);
eval('var obj=' + code); eval('var obj=' + code);
setvalue(JSON.stringify(obj)); setvalue(JSON.stringify(obj));
} }
editor_blockly.doubleClickBlock = function (blockId){ editor_blockly.doubleClickBlock = function (blockId) {
var b=editor_blockly.workspace.getBlockById(blockId); var b = editor_blockly.workspace.getBlockById(blockId);
//console.log(b); //console.log(b);
var textStringDict = { var textStringDict = {
'text_0_s':'EvalString_0', 'text_0_s': 'EvalString_0',
'text_1_s':'EvalString_2', 'text_1_s': 'EvalString_2',
'autoText_s':'EvalString_2', 'autoText_s': 'EvalString_2',
'choices_s':'EvalString_0', 'choices_s': 'EvalString_0',
'function_s':'RawEvalString_0', 'function_s': 'RawEvalString_0',
} }
var f=b?textStringDict[b.type]:null; var f = b ? textStringDict[b.type] : null;
if(f){ if (f) {
var value = b.getFieldValue(f); var value = b.getFieldValue(f);
//多行编辑 //多行编辑
editor_multi.multiLineEdit(value,b,f,{'lint':f==='RawEvalString_0'},function(newvalue,b,f){ editor_multi.multiLineEdit(value, b, f, {'lint': f === 'RawEvalString_0'}, function (newvalue, b, f) {
if(textStringDict[b.type]!=='RawEvalString_0'){} if (textStringDict[b.type] !== 'RawEvalString_0') {
b.setFieldValue(newvalue.split('\n').join('\\n'),f); }
b.setFieldValue(newvalue.split('\n').join('\\n'), f);
}); });
} }
} }
return editor_blockly; return editor_blockly;
} }
//editor_blockly=editor_blockly(); //editor_blockly=editor_blockly();

View File

@ -1,44 +1,54 @@
editor_file = function(editor, callback){ editor_file = function (editor, callback) {
var editor_file = {}; var editor_file = {};
var commentjs={ var commentjs = {
'comment':'comment', 'comment': 'comment',
'data.comment':'dataComment', 'data.comment': 'dataComment',
'functions.comment':'functionsComment', 'functions.comment': 'functionsComment',
} }
for(var key in commentjs){ for (var key in commentjs) {
(function(key){ (function (key) {
var value = commentjs[key]; var value = commentjs[key];
var script = document.createElement('script'); var script = document.createElement('script');
if (window.location.href.indexOf('_server')!==-1) if (window.location.href.indexOf('_server') !== -1)
script.src = '../project/'+key+'.js'; script.src = '../project/' + key + '.js';
else else
script.src = 'project/'+key+'.js'; script.src = 'project/' + key + '.js';
document.body.appendChild(script); document.body.appendChild(script);
script.onload = function () { script.onload = function () {
editor_file[value]=eval(key.replace('.','_')+'_c456ea59_6018_45ef_8bcc_211a24c627dc'); editor_file[value] = eval(key.replace('.', '_') + '_c456ea59_6018_45ef_8bcc_211a24c627dc');
var loaded = Boolean(callback); var loaded = Boolean(callback);
for(var key_ in commentjs){loaded = loaded && editor_file[commentjs[key_]]} for (var key_ in commentjs) {
if (loaded)callback(); loaded = loaded && editor_file[commentjs[key_]]
}
if (loaded) callback();
} }
})(key); })(key);
} }
editor_file.getFloorFileList = function(callback){ editor_file.getFloorFileList = function (callback) {
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
/* var fs = editor.fs; /* var fs = editor.fs;
fs.readdir('project/floors',function(err, data){ fs.readdir('project/floors',function(err, data){
callback([data,err]); callback([data,err]);
}); */ }); */
callback([editor.core.floorIds,null]); callback([editor.core.floorIds, null]);
} }
//callback([Array<String>,err:String]) //callback([Array<String>,err:String])
editor_file.loadFloorFile = function(filename,callback){ editor_file.loadFloorFile = function (filename, callback) {
//filename不含'/'不含'.js' //filename不含'/'不含'.js'
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
/* var fs = editor.fs; /* var fs = editor.fs;
fs.readFile('project/floors/'+filename+'.js','utf-8',function(err, data){ fs.readFile('project/floors/'+filename+'.js','utf-8',function(err, data){
if (err!=null){callback(err);return;} if (err!=null){callback(err);return;}
@ -58,63 +68,97 @@ editor_file = function(editor, callback){
editor.currentFloorData = floorData; editor.currentFloorData = floorData;
callback(null) callback(null)
}); */ }); */
editor.currentFloorId=editor.core.status.floorId; editor.currentFloorId = editor.core.status.floorId;
editor.currentFloorData = editor.core.floors[editor.currentFloorId]; editor.currentFloorData = editor.core.floors[editor.currentFloorId];
} }
//callback(err:String) //callback(err:String)
editor_file.saveFloorFile = function(callback){ editor_file.saveFloorFile = function (callback) {
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
/* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) { /* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) {
callback('未选中文件或无数据'); callback('未选中文件或无数据');
} */ } */
var filename = 'project/floors/' + editor.currentFloorId + '.js'; var filename = 'project/floors/' + editor.currentFloorId + '.js';
var datastr = ['main.floors.' , editor.currentFloorId , '=\n{']; var datastr = ['main.floors.', editor.currentFloorId, '=\n{'];
if (editor.currentFloorData.map == 'new') if (editor.currentFloorData.map == 'new')
editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(){return 0})}); editor.currentFloorData.map = editor.map.map(function (v) {
return v.map(function () {
return 0
})
});
else else
editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})}); editor.currentFloorData.map = editor.map.map(function (v) {
for(var ii in editor.currentFloorData) return v.map(function (v) {
return v.idnum || v || 0
})
});
for (var ii in editor.currentFloorData)
if (editor.currentFloorData.hasOwnProperty(ii)) { if (editor.currentFloorData.hasOwnProperty(ii)) {
if (ii=='map') if (ii == 'map')
datastr=datastr.concat(['\n"',ii,'": [\n',formatMap(editor.currentFloorData[ii]),'\n],']); datastr = datastr.concat(['\n"', ii, '": [\n', formatMap(editor.currentFloorData[ii]), '\n],']);
else else
datastr=datastr.concat(['\n"',ii,'": ',JSON.stringify(editor.currentFloorData[ii],null,4),',']); datastr = datastr.concat(['\n"', ii, '": ', JSON.stringify(editor.currentFloorData[ii], null, 4), ',']);
} }
datastr=datastr.concat(['\n}']); datastr = datastr.concat(['\n}']);
datastr=datastr.join(''); datastr = datastr.join('');
fs.writeFile(filename,encode(datastr),'base64',function(err, data){ fs.writeFile(filename, encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
} }
//callback(err:String) //callback(err:String)
editor_file.saveNewFile = function(saveFilename,callback){ editor_file.saveNewFile = function (saveFilename, callback) {
//saveAsFilename不含'/'不含'.js' //saveAsFilename不含'/'不含'.js'
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
if (!isset(editor.currentFloorData)) { if (!isset(editor.currentFloorData)) {
callback('无数据'); callback('无数据');
} }
editor.currentFloorData={floorId: saveFilename, title: "新建楼层", name: "0", canFlyTo: true, canUseQuickShop: true, images: [], item_ratio: 1, editor.currentFloorData = {
firstArrive: [], events: {}, changeFloor: {}, afterBattle: {}, afterGetItem: {}, afterOpenDoor: {}, cannotMove: {}}; floorId: saveFilename,
title: "新建楼层",
name: "0",
canFlyTo: true,
canUseQuickShop: true,
images: [],
item_ratio: 1,
firstArrive: [],
events: {},
changeFloor: {},
afterBattle: {},
afterGetItem: {},
afterOpenDoor: {},
cannotMove: {}
};
editor.currentFloorData.map = "new"; editor.currentFloorData.map = "new";
editor.currentFloorId=saveFilename; editor.currentFloorId = saveFilename;
editor_file.saveFloorFile(callback); editor_file.saveFloorFile(callback);
} }
//callback(err:String) //callback(err:String)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
editor_file.changeIdAndIdnum = function(id,idnum,info,callback){ editor_file.changeIdAndIdnum = function (id, idnum, info, callback) {
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
//检查maps中是否有重复的idnum或id //检查maps中是否有重复的idnum或id
var change = -1; var change = -1;
for(var ii in editor.core.maps.blocksInfo){ for (var ii in editor.core.maps.blocksInfo) {
if (ii==idnum) { if (ii == idnum) {
//暂时只允许创建新的不允许修改已有的 //暂时只允许创建新的不允许修改已有的
//if (info.idnum==idnum){change=ii;break;}//修改id //if (info.idnum==idnum){change=ii;break;}//修改id
callback('idnum重复了'); callback('idnum重复了');
return; return;
} }
if (editor.core.maps.blocksInfo[ii].id==id) { if (editor.core.maps.blocksInfo[ii].id == id) {
//if (info.id==id){change=ii;break;}//修改idnum //if (info.id==id){change=ii;break;}//修改idnum
callback('id重复了'); callback('id重复了');
return; return;
@ -138,30 +182,40 @@ editor_file = function(editor, callback){
editor.core.icons.icons[info.images][id]=info.y; editor.core.icons.icons[info.images][id]=info.y;
} }
*/ */
var templist=[]; var templist = [];
var tempcallback = function (err) { var tempcallback = function (err) {
templist.push(err); templist.push(err);
if (templist.length ==2 ) { if (templist.length == 2) {
if (templist[0]!=null || templist[1]!=null) if (templist[0] != null || templist[1] != null)
callback((templist[0]||'')+'\n'+(templist[1]||'')); callback((templist[0] || '') + '\n' + (templist[1] || ''));
//这里如果一个成功一个失败会出严重bug //这里如果一个成功一个失败会出严重bug
else else
callback(null); callback(null);
} }
} }
saveSetting('maps',[["add","['"+idnum+"']",{'cls': info.images, 'id':id}]],tempcallback); saveSetting('maps', [["add", "['" + idnum + "']", {'cls': info.images, 'id': id}]], tempcallback);
saveSetting('icons',[["add","['"+info.images+"']['"+id+"']",info.y]],tempcallback); saveSetting('icons', [["add", "['" + info.images + "']['" + id + "']", info.y]], tempcallback);
if(info.images==='items'){ if (info.images === 'items') {
saveSetting('items',[["add","['items']['"+id+"']",editor_file.comment._data.items_template]],function(err){if(err){printe(err);throw(err)}}); saveSetting('items', [["add", "['items']['" + id + "']", editor_file.comment._data.items_template]], function (err) {
if (err) {
printe(err);
throw(err)
} }
if(info.images==='enemys' || info.images==='enemy48'){ });
saveSetting('enemys',[["add","['"+id+"']",editor_file.comment._data.enemys_template]],function(err){if(err){printe(err);throw(err)}}); }
if (info.images === 'enemys' || info.images === 'enemy48') {
saveSetting('enemys', [["add", "['" + id + "']", editor_file.comment._data.enemys_template]], function (err) {
if (err) {
printe(err);
throw(err)
}
});
} }
callback(null); callback(null);
} }
//callback(err:String) //callback(err:String)
editor_file.editItem = function(id,actionList,callback){ editor_file.editItem = function (id, actionList, callback) {
/*actionList:[ /*actionList:[
["change","['items']['name']","红宝石的新名字"], ["change","['items']['name']","红宝石的新名字"],
["add","['items']['新的和name同级的属性']",123], ["add","['items']['新的和name同级的属性']",123],
@ -169,27 +223,31 @@ editor_file = function(editor, callback){
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
var tempindex = value[1].indexOf(']')+1; var tempindex = value[1].indexOf(']') + 1;
value[1] = [value[1].slice(0,tempindex),"['"+id+"']",value[1].slice(tempindex)].join(''); value[1] = [value[1].slice(0, tempindex), "['" + id + "']", value[1].slice(tempindex)].join('');
}); });
saveSetting('items',actionList,function (err) { saveSetting('items', actionList, function (err) {
callback([ callback([
(function(){ (function () {
var locObj_ ={}; var locObj_ = {};
Object.keys(editor_file.comment._data.items._data).forEach(function(v){ Object.keys(editor_file.comment._data.items._data).forEach(function (v) {
if (isset(editor.core.items[v][id]) && v!=='items') if (isset(editor.core.items[v][id]) && v !== 'items')
locObj_[v]=editor.core.items[v][id]; locObj_[v] = editor.core.items[v][id];
else else
locObj_[v]=null; locObj_[v] = null;
}); });
locObj_['items']=(function(){ locObj_['items'] = (function () {
var locObj=Object.assign({},editor.core.items.items[id]); var locObj = Object.assign({}, editor.core.items.items[id]);
Object.keys(editor_file.comment._data.items._data.items._data).forEach(function(v){ Object.keys(editor_file.comment._data.items._data.items._data).forEach(function (v) {
if (!isset(editor.core.items.items[id][v])) if (!isset(editor.core.items.items[id][v]))
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(); })();
@ -200,19 +258,19 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
var locObj_ ={}; var locObj_ = {};
Object.keys(editor_file.comment._data.items._data).forEach(function(v){ Object.keys(editor_file.comment._data.items._data).forEach(function (v) {
if (isset(editor.core.items[v][id]) && v!=='items') if (isset(editor.core.items[v][id]) && v !== 'items')
locObj_[v]=editor.core.items[v][id]; locObj_[v] = editor.core.items[v][id];
else else
locObj_[v]=null; locObj_[v] = null;
}); });
locObj_['items']=(function(){ locObj_['items'] = (function () {
var locObj=Object.assign({},editor.core.items.items[id]); var locObj = Object.assign({}, editor.core.items.items[id]);
Object.keys(editor_file.comment._data.items._data.items._data).forEach(function(v){ Object.keys(editor_file.comment._data.items._data.items._data).forEach(function (v) {
if (!isset(editor.core.items.items[id][v])) if (!isset(editor.core.items.items[id][v]))
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(); })();
@ -224,7 +282,7 @@ editor_file = function(editor, callback){
//只有items.cls是items的才有itemEffect和itemEffectTip,keys和constants和tools只有items //只有items.cls是items的才有itemEffect和itemEffectTip,keys和constants和tools只有items
} }
//callback([obj,commentObj,err:String]) //callback([obj,commentObj,err:String])
editor_file.editEnemy = function(id,actionList,callback){ editor_file.editEnemy = function (id, actionList, callback) {
/*actionList:[ /*actionList:[
["change","['name']","初级巫师的新名字"], ["change","['name']","初级巫师的新名字"],
["add","['新的和name同级的属性']",123], ["add","['新的和name同级的属性']",123],
@ -232,20 +290,24 @@ editor_file = function(editor, callback){
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
value[1] = "['"+id+"']"+value[1]; value[1] = "['" + id + "']" + value[1];
}); });
saveSetting('enemys',actionList,function (err) { saveSetting('enemys', actionList, function (err) {
callback([ callback([
(function(){ (function () {
var locObj=Object.assign({},editor.core.enemys.enemys[id]); var locObj = Object.assign({}, editor.core.enemys.enemys[id]);
Object.keys(editor_file.comment._data.enemys._data).forEach(function(v){ Object.keys(editor_file.comment._data.enemys._data).forEach(function (v) {
if (!isset(editor.core.enemys.enemys[id][v])) if (!isset(editor.core.enemys.enemys[id][v]))
/* locObj[v]=editor.core.enemys.enemys[id][v]; /* locObj[v]=editor.core.enemys.enemys[id][v];
else */ else */
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(), })(),
@ -254,13 +316,13 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
var locObj=Object.assign({},editor.core.enemys.enemys[id]); var locObj = Object.assign({}, editor.core.enemys.enemys[id]);
Object.keys(editor_file.comment._data.enemys._data).forEach(function(v){ Object.keys(editor_file.comment._data.enemys._data).forEach(function (v) {
if (!isset(editor.core.enemys.enemys[id][v])) if (!isset(editor.core.enemys.enemys[id][v]))
/* locObj[v]=editor.core.enemys.enemys[id][v]; /* locObj[v]=editor.core.enemys.enemys[id][v];
else */ else */
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(), })(),
@ -270,25 +332,29 @@ editor_file = function(editor, callback){
} }
//callback([obj,commentObj,err:String]) //callback([obj,commentObj,err:String])
editor_file.editMapBlocksInfo = function(idnum,actionList,callback){ editor_file.editMapBlocksInfo = function (idnum, actionList, callback) {
/*actionList:[ /*actionList:[
["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值可参见样板中初级巫师的写法。"]], ["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值可参见样板中初级巫师的写法。"]],
["change","['afterBattle']",null], ["change","['afterBattle']",null],
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
value[1] = "['"+idnum+"']"+value[1]; value[1] = "['" + idnum + "']" + value[1];
}); });
saveSetting('maps',actionList,function (err) { saveSetting('maps', actionList, function (err) {
callback([ callback([
(function(){ (function () {
var locObj=Object.assign({},editor.core.maps.blocksInfo[idnum]); var locObj = Object.assign({}, editor.core.maps.blocksInfo[idnum]);
Object.keys(editor_file.comment._data.maps._data).forEach(function(v){ Object.keys(editor_file.comment._data.maps._data).forEach(function (v) {
if (!isset(editor.core.maps.blocksInfo[idnum][v])) if (!isset(editor.core.maps.blocksInfo[idnum][v]))
locObj[v]=null; locObj[v] = null;
}); });
locObj.idnum = idnum; locObj.idnum = idnum;
return locObj; return locObj;
@ -298,11 +364,11 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
var locObj=Object.assign({},editor.core.maps.blocksInfo[idnum]); var locObj = Object.assign({}, editor.core.maps.blocksInfo[idnum]);
Object.keys(editor_file.comment._data.maps._data).forEach(function(v){ Object.keys(editor_file.comment._data.maps._data).forEach(function (v) {
if (!isset(editor.core.maps.blocksInfo[idnum][v])) if (!isset(editor.core.maps.blocksInfo[idnum][v]))
locObj[v]=null; locObj[v] = null;
}); });
locObj.idnum = idnum; locObj.idnum = idnum;
return locObj; return locObj;
@ -315,27 +381,31 @@ editor_file = function(editor, callback){
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
editor_file.editLoc = function(x,y,actionList,callback){ editor_file.editLoc = function (x, y, actionList, callback) {
/*actionList:[ /*actionList:[
["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值可参见样板中初级巫师的写法。"]], ["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值可参见样板中初级巫师的写法。"]],
["change","['afterBattle']",null], ["change","['afterBattle']",null],
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) { actionList.forEach(function (value) {
value[1] = value[1]+"['"+x+","+y+"']"; value[1] = value[1] + "['" + x + "," + y + "']";
}); });
saveSetting('floors',actionList,function (err) { saveSetting('floors', actionList, function (err) {
callback([ callback([
(function(){ (function () {
var locObj={}; var locObj = {};
Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function(v){ Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function (v) {
if (isset(editor.currentFloorData[v][x+','+y])) if (isset(editor.currentFloorData[v][x + ',' + y]))
locObj[v]=editor.currentFloorData[v][x+','+y]; locObj[v] = editor.currentFloorData[v][x + ',' + y];
else else
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(), })(),
@ -344,13 +414,13 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
var locObj={}; var locObj = {};
Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function(v){ Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function (v) {
if (isset(editor.currentFloorData[v][x+','+y])) if (isset(editor.currentFloorData[v][x + ',' + y]))
locObj[v]=editor.currentFloorData[v][x+','+y]; locObj[v] = editor.currentFloorData[v][x + ',' + y];
else else
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(), })(),
@ -363,26 +433,30 @@ editor_file = function(editor, callback){
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
editor_file.editFloor = function(actionList,callback){ editor_file.editFloor = function (actionList, callback) {
/*actionList:[ /*actionList:[
["change","['title']",'样板 3 层'], ["change","['title']",'样板 3 层'],
["change","['color']",null], ["change","['color']",null],
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
saveSetting('floors',actionList,function (err) { throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
saveSetting('floors', actionList, function (err) {
callback([ callback([
(function(){ (function () {
var locObj=Object.assign({},editor.currentFloorData); var locObj = Object.assign({}, editor.currentFloorData);
Object.keys(editor_file.comment._data.floors._data.floor._data).forEach(function(v){ Object.keys(editor_file.comment._data.floors._data.floor._data).forEach(function (v) {
if (!isset(editor.currentFloorData[v])) if (!isset(editor.currentFloorData[v]))
/* locObj[v]=editor.currentFloorData[v]; /* locObj[v]=editor.currentFloorData[v];
else */ else */
locObj[v]=null; locObj[v] = null;
}); });
Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function(v){ Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function (v) {
delete(locObj[v]); delete(locObj[v]);
}); });
delete(locObj.map); delete(locObj.map);
@ -393,15 +467,15 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
var locObj=Object.assign({},editor.currentFloorData); var locObj = Object.assign({}, editor.currentFloorData);
Object.keys(editor_file.comment._data.floors._data.floor._data).forEach(function(v){ Object.keys(editor_file.comment._data.floors._data.floor._data).forEach(function (v) {
if (!isset(editor.currentFloorData[v])) if (!isset(editor.currentFloorData[v]))
/* locObj[v]=editor.currentFloorData[v]; /* locObj[v]=editor.currentFloorData[v];
else */ else */
locObj[v]=null; locObj[v] = null;
}); });
Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function(v){ Object.keys(editor_file.comment._data.floors._data.loc._data).forEach(function (v) {
delete(locObj[v]); delete(locObj[v]);
}); });
delete(locObj.map); delete(locObj.map);
@ -415,7 +489,7 @@ editor_file = function(editor, callback){
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
editor_file.editTower = function(actionList,callback){ editor_file.editTower = function (actionList, callback) {
/*actionList:[ /*actionList:[
["change","['firstData']['version']",'Ver 1.0.1 (Beta)'], ["change","['firstData']['version']",'Ver 1.0.1 (Beta)'],
["change","['values']['lavaDamage']",200], ["change","['values']['lavaDamage']",200],
@ -423,18 +497,22 @@ editor_file = function(editor, callback){
[]时只查询不修改 []时只查询不修改
*/ */
var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d; var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
saveSetting('data',actionList,function (err) { throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
saveSetting('data', actionList, function (err) {
callback([ callback([
(function(){ (function () {
//var locObj=Object.assign({'main':{}},editor.core.data); //var locObj=Object.assign({'main':{}},editor.core.data);
var locObj=Object.assign({},data_obj,{'main':{}}); var locObj = Object.assign({}, data_obj, {'main': {}});
Object.keys(editor_file.dataComment._data.main._data).forEach(function(v){ Object.keys(editor_file.dataComment._data.main._data).forEach(function (v) {
if (isset(editor.main[v])) if (isset(editor.main[v]))
locObj.main[v]=data_obj.main[v]; locObj.main[v] = data_obj.main[v];
else else
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(), })(),
@ -443,14 +521,14 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
//var locObj=Object.assign({'main':{}},editor.core.data); //var locObj=Object.assign({'main':{}},editor.core.data);
var locObj=Object.assign({},data_obj,{'main':{}}); var locObj = Object.assign({}, data_obj, {'main': {}});
Object.keys(editor_file.dataComment._data.main._data).forEach(function(v){ Object.keys(editor_file.dataComment._data.main._data).forEach(function (v) {
if (isset(editor.main[v])) if (isset(editor.main[v]))
locObj.main[v]=data_obj.main[v]; locObj.main[v] = data_obj.main[v];
else else
locObj[v]=null; locObj[v] = null;
}); });
return locObj; return locObj;
})(), })(),
@ -463,30 +541,40 @@ editor_file = function(editor, callback){
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
var fmap = {}; var fmap = {};
var fjson = JSON.stringify(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a,function(k,v){if(v instanceof Function){var id_ = editor.guid();fmap[id_]=v.toString();return id_;}else return v},4); var fjson = JSON.stringify(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a, function (k, v) {
if (v instanceof Function) {
var id_ = editor.guid();
fmap[id_] = v.toString();
return id_;
} else return v
}, 4);
var fobj = JSON.parse(fjson); var fobj = JSON.parse(fjson);
editor_file.functionsMap = fmap; editor_file.functionsMap = fmap;
editor_file.functionsJSON = fjson; editor_file.functionsJSON = fjson;
var buildlocobj = function(locObj){ var buildlocobj = function (locObj) {
for(var key in locObj){ for (var key in locObj) {
if(typeof(locObj[key])!==typeof(''))buildlocobj(locObj[key]); if (typeof(locObj[key]) !== typeof('')) buildlocobj(locObj[key]);
else locObj[key]=fmap[locObj[key]]; else locObj[key] = fmap[locObj[key]];
} }
}; };
editor_file.editFunctions = function(actionList,callback){ editor_file.editFunctions = function (actionList, callback) {
/*actionList:[ /*actionList:[
["change","['events']['afterChangeLight']","function(x,y){console.log(x,y)}"], ["change","['events']['afterChangeLight']","function(x,y){console.log(x,y)}"],
["change","['ui']['drawAbout']","function(){...}"], ["change","['ui']['drawAbout']","function(){...}"],
] ]
[]时只查询不修改 []时只查询不修改
*/ */
if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; if (!isset(callback)) {
if (isset(actionList) && actionList.length > 0){ printe('未设置callback');
saveSetting('functions',actionList,function (err) { throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
saveSetting('functions', actionList, function (err) {
callback([ callback([
(function(){ (function () {
var locObj=JSON.parse(fjson); var locObj = JSON.parse(fjson);
buildlocobj(locObj); buildlocobj(locObj);
return locObj; return locObj;
})(), })(),
@ -495,8 +583,8 @@ editor_file = function(editor, callback){
}); });
} else { } else {
callback([ callback([
(function(){ (function () {
var locObj=JSON.parse(fjson); var locObj = JSON.parse(fjson);
buildlocobj(locObj); buildlocobj(locObj);
return locObj; return locObj;
})(), })(),
@ -515,122 +603,134 @@ editor_file = function(editor, callback){
return true return true
} }
var formatMap = function(mapArr){ var formatMap = function (mapArr) {
//把13*13或者1*169数组格式化 //把13*13或者1*169数组格式化
var formatArrStr = ''; var formatArrStr = '';
var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],['); var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],[');
for(var i =0; i<13; i++){ for (var i = 0; i < 13; i++) {
var a = []; var a = [];
formatArrStr +=' ['; formatArrStr += ' [';
if(i==0||i==12) a = arr[i].split(/\D+/).join(' ').trim().split(' '); if (i == 0 || i == 12) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
else a = arr[i].split(/\D+/); else a = arr[i].split(/\D+/);
for(var k=0; k<13; k++){ for (var k = 0; k < 13; k++) {
var num = parseInt(a[k]); var num = parseInt(a[k]);
formatArrStr += Array(Math.max(4-String(num).length,0)).join(' ')+num+(k==12?'':','); formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == 12 ? '' : ',');
} }
formatArrStr += ']'+(i==12?'':',\n'); formatArrStr += ']' + (i == 12 ? '' : ',\n');
} }
return formatArrStr; return formatArrStr;
} }
var encode = function (str) { var encode = function (str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode(parseInt(p1, 16)) return String.fromCharCode(parseInt(p1, 16))
})) }))
} }
var saveSetting = function(file,actionList,callback) { var saveSetting = function (file, actionList, callback) {
//console.log(file); //console.log(file);
//console.log(actionList); //console.log(actionList);
if (file=='icons') { if (file == 'icons') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1"+value[1]+'='+JSON.stringify(value[2])); eval("icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1" + value[1] + '=' + JSON.stringify(value[2]));
}); });
var datastr='icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = \n'; var datastr = 'icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = \n';
datastr+=JSON.stringify(icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1,null,'\t'); datastr += JSON.stringify(icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1, null, '\t');
fs.writeFile('project/icons.js',encode(datastr),'base64',function(err, data){ fs.writeFile('project/icons.js', encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
return; return;
} }
if (file=='maps') { if (file == 'maps') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("maps_90f36752_8815_4be8_b32b_d7fad1d0542e"+value[1]+'='+JSON.stringify(value[2])); eval("maps_90f36752_8815_4be8_b32b_d7fad1d0542e" + value[1] + '=' + JSON.stringify(value[2]));
}); });
var datastr='maps_90f36752_8815_4be8_b32b_d7fad1d0542e = \n'; var datastr = 'maps_90f36752_8815_4be8_b32b_d7fad1d0542e = \n';
//datastr+=JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e,null,4); //datastr+=JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e,null,4);
var emap={}; var emap = {};
var estr = JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e,function(k,v){if(v.id!=null){var id_ = editor.guid();emap[id_]=JSON.stringify(v);return id_;}else return v},'\t'); var estr = JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e, function (k, v) {
for(var id_ in emap){ if (v.id != null) {
estr = estr.replace('"'+id_+'"',emap[id_]) var id_ = editor.guid();
emap[id_] = JSON.stringify(v);
return id_;
} else return v
}, '\t');
for (var id_ in emap) {
estr = estr.replace('"' + id_ + '"', emap[id_])
} }
datastr+=estr; datastr += estr;
fs.writeFile('project/maps.js',encode(datastr),'base64',function(err, data){ fs.writeFile('project/maps.js', encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
return; return;
} }
if (file=='items') { if (file == 'items') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a"+value[1]+'='+JSON.stringify(value[2])); eval("items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a" + value[1] + '=' + JSON.stringify(value[2]));
}); });
var datastr='items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = \n'; var datastr = 'items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = \n';
datastr+=JSON.stringify(items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a,null,'\t'); datastr += JSON.stringify(items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a, null, '\t');
fs.writeFile('project/items.js',encode(datastr),'base64',function(err, data){ fs.writeFile('project/items.js', encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
return; return;
} }
if (file=='enemys') { if (file == 'enemys') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80"+value[1]+'='+JSON.stringify(value[2])); eval("enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80" + value[1] + '=' + JSON.stringify(value[2]));
}); });
var datastr='enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = \n'; var datastr = 'enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = \n';
var emap={}; var emap = {};
var estr = JSON.stringify(enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80,function(k,v){if(v.hp!=null){var id_ = editor.guid();emap[id_]=JSON.stringify(v);return id_;}else return v},'\t'); var estr = JSON.stringify(enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80, function (k, v) {
for(var id_ in emap){ if (v.hp != null) {
estr = estr.replace('"'+id_+'"',emap[id_]) var id_ = editor.guid();
emap[id_] = JSON.stringify(v);
return id_;
} else return v
}, '\t');
for (var id_ in emap) {
estr = estr.replace('"' + id_ + '"', emap[id_])
} }
datastr+=estr; datastr += estr;
fs.writeFile('project/enemys.js',encode(datastr),'base64',function(err, data){ fs.writeFile('project/enemys.js', encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
return; return;
} }
if (file=='data') { if (file == 'data') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d"+value[1]+'='+JSON.stringify(value[2])); eval("data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d" + value[1] + '=' + JSON.stringify(value[2]));
}); });
if (data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds.indexOf(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId)<0) if (data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds.indexOf(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId) < 0)
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds[0]; data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds[0];
var datastr='data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = \n'; var datastr = 'data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = \n';
datastr+=JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d,null,'\t'); datastr += JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, null, '\t');
fs.writeFile('project/data.js',encode(datastr),'base64',function(err, data){ fs.writeFile('project/data.js', encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
return; return;
} }
if (file=='functions') { if (file == 'functions') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("fmap[fobj"+value[1]+']='+JSON.stringify(value[2])); eval("fmap[fobj" + value[1] + ']=' + JSON.stringify(value[2]));
}); });
var fraw = fjson; var fraw = fjson;
for(var id_ in fmap){ for (var id_ in fmap) {
fraw = fraw.replace('"'+id_+'"',fmap[id_]) fraw = fraw.replace('"' + id_ + '"', fmap[id_])
} }
var datastr='functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = \n'; var datastr = 'functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = \n';
datastr+=fraw; datastr += fraw;
fs.writeFile('project/functions.js',encode(datastr),'base64',function(err, data){ fs.writeFile('project/functions.js', encode(datastr), 'base64', function (err, data) {
callback(err); callback(err);
}); });
return; return;
} }
if (file=='floors') { if (file == 'floors') {
actionList.forEach(function (value) { actionList.forEach(function (value) {
eval("editor.currentFloorData"+value[1]+'='+JSON.stringify(value[2])); eval("editor.currentFloorData" + value[1] + '=' + JSON.stringify(value[2]));
}); });
editor_file.saveFloorFile(callback); editor_file.saveFloorFile(callback);
return; return;

View File

@ -1,94 +1,95 @@
editor_mode = function(editor){ editor_mode = function (editor) {
var core = editor.core; var core = editor.core;
function editor_mode(){ function editor_mode() {
this.ids={ this.ids = {
'loc':'left2', 'loc': 'left2',
'emenyitem':'left3', 'emenyitem': 'left3',
'floor':'left4', 'floor': 'left4',
'tower':'left5', 'tower': 'left5',
'functions':'left8', 'functions': 'left8',
'map':'left', 'map': 'left',
'appendpic':'left1', 'appendpic': 'left1',
}
this._ids = {}
this.dom = {}
this.actionList = [];
this.mode = '';
this.info = {};
this.appendPic = {};
} }
this._ids={}
this.dom={}
this.actionList=[];
this.mode='';
this.info={};
this.appendPic={};
}
editor_mode.prototype.init = function(callback){
if (Boolean(callback))callback();
}
editor_mode.prototype.init_dom_ids = function(callback){ editor_mode.prototype.init = function (callback) {
if (Boolean(callback)) callback();
}
Object.keys(editor_mode.ids).forEach(function(v){ editor_mode.prototype.init_dom_ids = function (callback) {
editor_mode.dom[v]=document.getElementById(editor_mode.ids[v]);
editor_mode._ids[editor_mode.ids[v]]=v; Object.keys(editor_mode.ids).forEach(function (v) {
editor_mode.dom[v] = document.getElementById(editor_mode.ids[v]);
editor_mode._ids[editor_mode.ids[v]] = v;
}); });
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
editor_mode.prototype.objToTable_ = function(obj,commentObj){ editor_mode.prototype.objToTable_ = function (obj, commentObj) {
var outstr=["\n<tr><td>条目</td><td>注释</td><td>值</td></tr>\n"]; var outstr = ["\n<tr><td>条目</td><td>注释</td><td>值</td></tr>\n"];
var guids=[]; var guids = [];
var defaultcobj={ var defaultcobj = {
_type:'textarea', _type: 'textarea',
_data:'', _data: '',
_string:function(args){//object~[field,cfield,vobj,cobj] _string: function (args) {//object~[field,cfield,vobj,cobj]
var thiseval = args.vobj; var thiseval = args.vobj;
return (typeof(thiseval) === typeof('')) && thiseval[0]==='"'; return (typeof(thiseval) === typeof('')) && thiseval[0] === '"';
}, },
_leaf:function(args){//object~[field,cfield,vobj,cobj] _leaf: function (args) {//object~[field,cfield,vobj,cobj]
var thiseval = args.vobj; var thiseval = args.vobj;
if (thiseval == null || thiseval == undefined)return true;//null,undefined if (thiseval == null || thiseval == undefined) return true;//null,undefined
if (typeof(thiseval) === typeof(''))return true;//字符串 if (typeof(thiseval) === typeof('')) return true;//字符串
if (Object.keys(thiseval).length === 0)return true;//数字,true,false,空数组,空对象 if (Object.keys(thiseval).length === 0) return true;//数字,true,false,空数组,空对象
return false; return false;
}, },
} }
var recursionParse = function(pfield,pcfield,pvobj,pcobj) { var recursionParse = function (pfield, pcfield, pvobj, pcobj) {
for(var ii in pvobj){ for (var ii in pvobj) {
var field = pfield+"['"+ii+"']"; var field = pfield + "['" + ii + "']";
var cfield = pcfield+"['_data']['"+ii+"']"; var cfield = pcfield + "['_data']['" + ii + "']";
var vobj = pvobj[ii]; var vobj = pvobj[ii];
var cobj = null; var cobj = null;
if(pcobj && pcobj['_data'] && pcobj['_data'][ii]){ if (pcobj && pcobj['_data'] && pcobj['_data'][ii]) {
cobj = Object.assign({},defaultcobj,pcobj['_data'][ii]); cobj = Object.assign({}, defaultcobj, pcobj['_data'][ii]);
} else { } else {
if(pcobj && (pcobj['_data'] instanceof Function))cobj = Object.assign({},defaultcobj,pcobj['_data'](ii)); if (pcobj && (pcobj['_data'] instanceof Function)) cobj = Object.assign({}, defaultcobj, pcobj['_data'](ii));
else cobj = Object.assign({},defaultcobj); else cobj = Object.assign({}, defaultcobj);
} }
var args = {field:field,cfield:cfield,vobj:vobj,cobj:cobj} var args = {field: field, cfield: cfield, vobj: vobj, cobj: cobj}
if(cobj._leaf instanceof Function)cobj._leaf=cobj._leaf(args); if (cobj._leaf instanceof Function) cobj._leaf = cobj._leaf(args);
for(var key in cobj){ for (var key in cobj) {
if(key==='_data')continue; if (key === '_data') continue;
if(cobj[key] instanceof Function)cobj[key]=cobj[key](args); if (cobj[key] instanceof Function) cobj[key] = cobj[key](args);
} }
if (cobj._leaf) { if (cobj._leaf) {
var leafnode = editor_mode.objToTr_(obj,commentObj,field,cfield,vobj,cobj); var leafnode = editor_mode.objToTr_(obj, commentObj, field, cfield, vobj, cobj);
outstr.push(leafnode[0]); outstr.push(leafnode[0]);
guids.push(leafnode[1]); guids.push(leafnode[1]);
} else { } else {
outstr.push(["<tr><td>----</td><td>----</td><td>",field,"</td></tr>\n"].join('')); outstr.push(["<tr><td>----</td><td>----</td><td>", field, "</td></tr>\n"].join(''));
recursionParse(field,cfield,vobj,cobj); recursionParse(field, cfield, vobj, cobj);
} }
} }
} }
recursionParse("","",obj,commentObj); recursionParse("", "", obj, commentObj);
var checkRange = function(evalstr,thiseval){ var checkRange = function (evalstr, thiseval) {
if(evalstr){ if (evalstr) {
return eval(evalstr); return eval(evalstr);
} }
return true; return true;
} }
var listen = function(guids) { var listen = function (guids) {
guids.forEach(function(guid){ guids.forEach(function (guid) {
// tr>td[title=field] // tr>td[title=field]
// >td[title=comment,cobj=cobj:json] // >td[title=comment,cobj=cobj:json]
// >td>div>input[value=thiseval] // >td>div>input[value=thiseval]
@ -96,240 +97,306 @@ editor_mode.prototype.objToTable_ = function(obj,commentObj){
var input = thisTr.children[2].children[0].children[0]; var input = thisTr.children[2].children[0].children[0];
var field = thisTr.children[0].getAttribute('title'); var field = thisTr.children[0].getAttribute('title');
var cobj = JSON.parse(thisTr.children[1].getAttribute('cobj')); var cobj = JSON.parse(thisTr.children[1].getAttribute('cobj'));
input.onchange = function(){ input.onchange = function () {
var node = thisTr.parentNode; var node = thisTr.parentNode;
while (!editor_mode._ids.hasOwnProperty(node.getAttribute('id'))) { while (!editor_mode._ids.hasOwnProperty(node.getAttribute('id'))) {
node = node.parentNode; node = node.parentNode;
} }
editor_mode.onmode(editor_mode._ids[node.getAttribute('id')]); editor_mode.onmode(editor_mode._ids[node.getAttribute('id')]);
var thiseval=null; var thiseval = null;
if(input.checked!=null)input.value=input.checked; if (input.checked != null) input.value = input.checked;
try{ try {
thiseval = JSON.parse(input.value); thiseval = JSON.parse(input.value);
}catch(ee){ } catch (ee) {
printe(field+' : '+ee); printe(field + ' : ' + ee);
throw ee; throw ee;
} }
if(checkRange(cobj._range,thiseval)){ if (checkRange(cobj._range, thiseval)) {
editor_mode.addAction(['change',field,thiseval]); editor_mode.addAction(['change', field, thiseval]);
editor_mode.onmode('save');//自动保存 editor_mode.onmode('save');//自动保存
} else { } else {
printe(field+' : 输入的值不合要求,请鼠标放置在注释上查看说明'); printe(field + ' : 输入的值不合要求,请鼠标放置在注释上查看说明');
} }
} }
input.ondblclick = function(){ input.ondblclick = function () {
if(cobj._type==='event')editor_blockly.import(guid,{type:cobj._event}); if (cobj._type === 'event') editor_blockly.import(guid, {type: cobj._event});
if(cobj._type==='textarea')editor_multi.import(guid,{lint:cobj._lint}); if (cobj._type === 'textarea') editor_multi.import(guid, {lint: cobj._lint});
} }
}); });
} }
return {"HTML":outstr.join(''),"guids":guids,"listen":listen}; return {"HTML": outstr.join(''), "guids": guids, "listen": listen};
} }
editor_mode.prototype.objToTr_ = function(obj,commentObj,field,cfield,vobj,cobj){ editor_mode.prototype.objToTr_ = function (obj, commentObj, field, cfield, vobj, cobj) {
var guid = editor.guid(); var guid = editor.guid();
var thiseval = vobj; var thiseval = vobj;
var comment = cobj._data; var comment = cobj._data;
var charlength=10; var charlength = 10;
var shortField = field.split("']").slice(-2)[0].split("['").slice(-1)[0]; var shortField = field.split("']").slice(-2)[0].split("['").slice(-1)[0];
shortField = (shortField.length<charlength?shortField:shortField.slice(0,charlength)+'...'); shortField = (shortField.length < charlength ? shortField : shortField.slice(0, charlength) + '...');
var commentHTMLescape=editor.HTMLescape(comment); var commentHTMLescape = editor.HTMLescape(comment);
var shortCommentHTMLescape=(comment.length<charlength?commentHTMLescape:editor.HTMLescape(comment.slice(0,charlength))+'...'); var shortCommentHTMLescape = (comment.length < charlength ? commentHTMLescape : editor.HTMLescape(comment.slice(0, charlength)) + '...');
var cobjstr = Object.assign({},cobj); var cobjstr = Object.assign({}, cobj);
delete cobjstr._data; delete cobjstr._data;
cobjstr = editor.HTMLescape(JSON.stringify(cobjstr)); cobjstr = editor.HTMLescape(JSON.stringify(cobjstr));
var outstr=['<tr id="',guid,'"><td title="',field,'">',shortField,'</td>', var outstr = ['<tr id="', guid, '"><td title="', field, '">', shortField, '</td>',
'<td title="',commentHTMLescape,'" cobj="',cobjstr,'">',shortCommentHTMLescape,'</td>', '<td title="', commentHTMLescape, '" cobj="', cobjstr, '">', shortCommentHTMLescape, '</td>',
'<td><div class="etableInputDiv">',editor_mode.objToTd_(obj,commentObj,field,cfield,vobj,cobj),'</div></td></tr>\n', '<td><div class="etableInputDiv">', editor_mode.objToTd_(obj, commentObj, field, cfield, vobj, cobj), '</div></td></tr>\n',
]; ];
return [outstr.join(''),guid]; return [outstr.join(''), guid];
} }
editor_mode.prototype.objToTd_ = function(obj,commentObj,field,cfield,vobj,cobj){ editor_mode.prototype.objToTd_ = function (obj, commentObj, field, cfield, vobj, cobj) {
var thiseval = vobj; var thiseval = vobj;
if(cobj._select){ if (cobj._select) {
var values = cobj._select.values; var values = cobj._select.values;
var outstr = ['<select>\n',"<option value='",JSON.stringify(thiseval),"'>",JSON.stringify(thiseval),'</option>\n']; var outstr = ['<select>\n', "<option value='", JSON.stringify(thiseval), "'>", JSON.stringify(thiseval), '</option>\n'];
values.forEach(function(v){ values.forEach(function (v) {
outstr.push(["<option value='",JSON.stringify(v),"'>",JSON.stringify(v),'</option>\n'].join('')) outstr.push(["<option value='", JSON.stringify(v), "'>", JSON.stringify(v), '</option>\n'].join(''))
}); });
outstr.push('</select>'); outstr.push('</select>');
return outstr.join(''); return outstr.join('');
} else if(cobj._input){ } else if (cobj._input) {
return ["<input type='text' spellcheck='false' value='",JSON.stringify(thiseval),"'/>\n"].join(''); return ["<input type='text' spellcheck='false' value='", JSON.stringify(thiseval), "'/>\n"].join('');
} else if(cobj._bool){ } else if (cobj._bool) {
return ["<input type='checkbox' ",(thiseval?'checked ':''),"/>\n"].join(''); return ["<input type='checkbox' ", (thiseval ? 'checked ' : ''), "/>\n"].join('');
} else { } else {
var num = 0;//editor_mode.indent(field); var num = 0;//editor_mode.indent(field);
return ["<textarea spellcheck='false' >",JSON.stringify(thiseval,null,num),'</textarea>\n'].join(''); return ["<textarea spellcheck='false' >", JSON.stringify(thiseval, null, num), '</textarea>\n'].join('');
}
} }
}
editor_mode.prototype.indent = function(field){ editor_mode.prototype.indent = function (field) {
var num = '\t'; var num = '\t';
if(field.indexOf("['main']")===0)return 0; if (field.indexOf("['main']") === 0) return 0;
if(field.indexOf("['flyRange']")!==-1)return 0; if (field.indexOf("['flyRange']") !== -1) return 0;
if(field==="['special']")return 0; if (field === "['special']") return 0;
return num; return num;
} }
editor_mode.prototype.addAction = function(action){ editor_mode.prototype.addAction = function (action) {
editor_mode.actionList.push(action); editor_mode.actionList.push(action);
} }
editor_mode.prototype.doActionList = function(mode,actionList){ editor_mode.prototype.doActionList = function (mode, actionList) {
if (actionList.length==0)return; if (actionList.length == 0) return;
printf('修改中...'); printf('修改中...');
switch (mode) { switch (mode) {
case 'loc': case 'loc':
editor.file.editLoc(editor_mode.pos.x,editor_mode.pos.y,actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); editor.file.editLoc(editor_mode.pos.x, editor_mode.pos.y, actionList, function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
break; break;
case 'emenyitem': case 'emenyitem':
if (editor_mode.info.images=='enemys'||editor_mode.info.images=='enemy48'){ if (editor_mode.info.images == 'enemys' || editor_mode.info.images == 'enemy48') {
editor.file.editEnemy(editor_mode.info.id,actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); editor.file.editEnemy(editor_mode.info.id, actionList, function (objs_) {/*console.log(objs_);*/
} else if (editor_mode.info.images=='items'){ if (objs_.slice(-1)[0] != null) {
editor.file.editItem(editor_mode.info.id,actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
} else if (editor_mode.info.images == 'items') {
editor.file.editItem(editor_mode.info.id, actionList, function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
} else { } else {
editor.file.editMapBlocksInfo(editor_mode.info.idnum,actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); editor.file.editMapBlocksInfo(editor_mode.info.idnum, actionList, function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
} }
break; break;
case 'floor': case 'floor':
editor.file.editFloor(actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); editor.file.editFloor(actionList, function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
break; break;
case 'tower': case 'tower':
editor.file.editTower(actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); editor.file.editTower(actionList, function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
break; break;
case 'functions': case 'functions':
editor.file.editFunctions(actionList,function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); editor.file.editFunctions(actionList, function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
break; break;
default: default:
break; break;
} }
}
editor_mode.prototype.onmode = function (mode) {
if (editor_mode.mode!=mode) {
if(mode==='save')editor_mode.doActionList(editor_mode.mode,editor_mode.actionList);
if(editor_mode.mode==='nextChange' && mode)editor_mode.showMode(mode);
editor_mode.mode=mode;
editor_mode.actionList=[];
} }
}
editor_mode.prototype.showMode = function (mode) { editor_mode.prototype.onmode = function (mode) {
for(var name in this.dom){ if (editor_mode.mode != mode) {
editor_mode.dom[name].style='z-index:-1;opacity: 0;'; if (mode === 'save') editor_mode.doActionList(editor_mode.mode, editor_mode.actionList);
if (editor_mode.mode === 'nextChange' && mode) editor_mode.showMode(mode);
editor_mode.mode = mode;
editor_mode.actionList = [];
} }
editor_mode.dom[mode].style=''; }
if(editor_mode[mode])editor_mode[mode]();
document.getElementById('editModeSelect').value=mode; editor_mode.prototype.showMode = function (mode) {
for (var name in this.dom) {
editor_mode.dom[name].style = 'z-index:-1;opacity: 0;';
}
editor_mode.dom[mode].style = '';
if (editor_mode[mode]) editor_mode[mode]();
document.getElementById('editModeSelect').value = mode;
var tips = tip_in_showMode; var tips = tip_in_showMode;
if(!selectBox.isSelected)printf('tips: '+tips[~~(tips.length*Math.random())]); if (!selectBox.isSelected) printf('tips: ' + tips[~~(tips.length * Math.random())]);
} }
editor_mode.prototype.loc = function(callback){ editor_mode.prototype.loc = function (callback) {
//editor.pos={x: 0, y: 0}; //editor.pos={x: 0, y: 0};
if (!core.isset(editor.pos))return; if (!core.isset(editor.pos)) return;
editor_mode.pos=editor.pos; editor_mode.pos = editor.pos;
document.getElementById('pos_a6771a78_a099_417c_828f_0a24851ebfce').innerText=editor_mode.pos.x+','+editor_mode.pos.y; document.getElementById('pos_a6771a78_a099_417c_828f_0a24851ebfce').innerText = editor_mode.pos.x + ',' + editor_mode.pos.y;
var objs=[]; var objs = [];
editor.file.editLoc(editor_mode.pos.x,editor_mode.pos.y,[],function(objs_){objs=objs_;/*console.log(objs_)*/}); editor.file.editLoc(editor_mode.pos.x, editor_mode.pos.y, [], function (objs_) {
objs = objs_;
/*console.log(objs_)*/
});
//只查询不修改时,内部实现不是异步的,所以可以这么写 //只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo=editor_mode.objToTable_(objs[0],objs[1]); var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_3d846fc4_7644_44d1_aa04_433d266a73df').innerHTML=tableinfo.HTML; document.getElementById('table_3d846fc4_7644_44d1_aa04_433d266a73df').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids); tableinfo.listen(tableinfo.guids);
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
editor_mode.prototype.emenyitem = function(callback){ editor_mode.prototype.emenyitem = function (callback) {
//editor.info=editor.ids[editor.indexs[201]]; //editor.info=editor.ids[editor.indexs[201]];
if (!core.isset(editor.info))return; if (!core.isset(editor.info)) return;
if(Object.keys(editor.info).length!==0)editor_mode.info=editor.info;//避免editor.info被清空导致无法获得是物品还是怪物 if (Object.keys(editor.info).length !== 0) editor_mode.info = editor.info;//避免editor.info被清空导致无法获得是物品还是怪物
if (!core.isset(editor_mode.info.id)){ if (!core.isset(editor_mode.info.id)) {
document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML=''; document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML = '';
document.getElementById('newIdIdnum').style.display=''; document.getElementById('newIdIdnum').style.display = '';
return; return;
} }
document.getElementById('newIdIdnum').style.display='none'; document.getElementById('newIdIdnum').style.display = 'none';
var objs=[]; var objs = [];
if (editor_mode.info.images=='enemys' || editor_mode.info.images=='enemy48'){ if (editor_mode.info.images == 'enemys' || editor_mode.info.images == 'enemy48') {
editor.file.editEnemy(editor_mode.info.id,[],function(objs_){objs=objs_;/*console.log(objs_)*/}); editor.file.editEnemy(editor_mode.info.id, [], function (objs_) {
} else if (editor_mode.info.images=='items'){ objs = objs_;
editor.file.editItem(editor_mode.info.id,[],function(objs_){objs=objs_;/*console.log(objs_)*/}); /*console.log(objs_)*/
});
} else if (editor_mode.info.images == 'items') {
editor.file.editItem(editor_mode.info.id, [], function (objs_) {
objs = objs_;
/*console.log(objs_)*/
});
} else { } else {
/* document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML=''; /* document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML='';
return; */ return; */
editor.file.editMapBlocksInfo(editor_mode.info.idnum,[],function(objs_){objs=objs_;/*console.log(objs_)*/}); editor.file.editMapBlocksInfo(editor_mode.info.idnum, [], function (objs_) {
objs = objs_;
/*console.log(objs_)*/
});
} }
//只查询不修改时,内部实现不是异步的,所以可以这么写 //只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo=editor_mode.objToTable_(objs[0],objs[1]); var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML=tableinfo.HTML; document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids); tableinfo.listen(tableinfo.guids);
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
editor_mode.prototype.floor = function(callback){ editor_mode.prototype.floor = function (callback) {
var objs=[]; var objs = [];
editor.file.editFloor([],function(objs_){objs=objs_;/*console.log(objs_)*/}); editor.file.editFloor([], function (objs_) {
objs = objs_;
/*console.log(objs_)*/
});
//只查询不修改时,内部实现不是异步的,所以可以这么写 //只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo=editor_mode.objToTable_(objs[0],objs[1]); var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_4a3b1b09_b2fb_4bdf_b9ab_9f4cdac14c74').innerHTML=tableinfo.HTML; document.getElementById('table_4a3b1b09_b2fb_4bdf_b9ab_9f4cdac14c74').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids); tableinfo.listen(tableinfo.guids);
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
editor_mode.prototype.tower = function(callback){ editor_mode.prototype.tower = function (callback) {
var objs=[]; var objs = [];
editor.file.editTower([],function(objs_){objs=objs_;/*console.log(objs_)*/}); editor.file.editTower([], function (objs_) {
objs = objs_;
/*console.log(objs_)*/
});
//只查询不修改时,内部实现不是异步的,所以可以这么写 //只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo=editor_mode.objToTable_(objs[0],objs[1]); var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_b6a03e4c_5968_4633_ac40_0dfdd2c9cde5').innerHTML=tableinfo.HTML; document.getElementById('table_b6a03e4c_5968_4633_ac40_0dfdd2c9cde5').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids); tableinfo.listen(tableinfo.guids);
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
editor_mode.prototype.functions = function(callback){ editor_mode.prototype.functions = function (callback) {
var objs=[]; var objs = [];
editor.file.editFunctions([],function(objs_){objs=objs_;/*console.log(objs_)*/}); editor.file.editFunctions([], function (objs_) {
objs = objs_;
/*console.log(objs_)*/
});
//只查询不修改时,内部实现不是异步的,所以可以这么写 //只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo=editor_mode.objToTable_(objs[0],objs[1]); var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_e260a2be_5690_476a_b04e_dacddede78b3').innerHTML=tableinfo.HTML; document.getElementById('table_e260a2be_5690_476a_b04e_dacddede78b3').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids); tableinfo.listen(tableinfo.guids);
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
editor_mode.prototype.listen = function(callback){ editor_mode.prototype.listen = function (callback) {
var newIdIdnum = document.getElementById('newIdIdnum'); var newIdIdnum = document.getElementById('newIdIdnum');
newIdIdnum.children[2].onclick = function(){ newIdIdnum.children[2].onclick = function () {
if (newIdIdnum.children[0].value && newIdIdnum.children[1].value){ if (newIdIdnum.children[0].value && newIdIdnum.children[1].value) {
var id = newIdIdnum.children[0].value; var id = newIdIdnum.children[0].value;
var idnum = parseInt(newIdIdnum.children[1].value); var idnum = parseInt(newIdIdnum.children[1].value);
if (!core.isset(idnum)) { if (!core.isset(idnum)) {
printe('不合法的idnum'); printe('不合法的idnum');
return; return;
} }
editor.file.changeIdAndIdnum(id,idnum,editor_mode.info,function(err){ editor.file.changeIdAndIdnum(id, idnum, editor_mode.info, function (err) {
if(err){printe(err);throw(err)} if (err) {
printe(err);
throw(err)
}
printe('添加id的idnum成功,请F5刷新编辑器'); printe('添加id的idnum成功,请F5刷新编辑器');
}); });
} else { } else {
@ -338,14 +405,14 @@ editor_mode.prototype.listen = function(callback){
} }
var selectFloor = document.getElementById('selectFloor'); var selectFloor = document.getElementById('selectFloor');
editor.file.getFloorFileList(function(floors){ editor.file.getFloorFileList(function (floors) {
var outstr=[]; var outstr = [];
floors[0].forEach(function(floor){ floors[0].forEach(function (floor) {
outstr.push(["<option value='",floor,"'>",floor,'</option>\n'].join('')); outstr.push(["<option value='", floor, "'>", floor, '</option>\n'].join(''));
}); });
selectFloor.innerHTML=outstr.join(''); selectFloor.innerHTML = outstr.join('');
selectFloor.value=core.status.floorId; selectFloor.value = core.status.floorId;
selectFloor.onchange = function(){ selectFloor.onchange = function () {
editor_mode.onmode('nextChange'); editor_mode.onmode('nextChange');
editor_mode.onmode('floor'); editor_mode.onmode('floor');
editor.changeFloor(selectFloor.value); editor.changeFloor(selectFloor.value);
@ -353,24 +420,39 @@ editor_mode.prototype.listen = function(callback){
}); });
var saveFloor = document.getElementById('saveFloor'); var saveFloor = document.getElementById('saveFloor');
saveFloor.onclick = function(){ saveFloor.onclick = function () {
editor_mode.onmode(''); editor_mode.onmode('');
editor.file.saveFloorFile(function(err){if(err){printe(err);throw(err)};printf('保存成功');}); editor.file.saveFloorFile(function (err) {
if (err) {
printe(err);
throw(err)
} }
;printf('保存成功');
var saveFloorAs = document.getElementById('saveFloorAs');
var saveAsName = document.getElementById('saveAsName');
saveFloorAs.onclick = function(){
if (!saveAsName.value)return;
editor_mode.onmode('');
editor.file.saveNewFile(saveAsName.value,function(err){
if(err){printe(err);throw(err)}
core.floorIds.push(saveAsName.value);
editor.file.editTower([['change',"['main']['floorIds']",core.floorIds]],function(objs_){/*console.log(objs_);*/if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printe('新建成功,请F5刷新编辑器生效');});
}); });
} }
var ratio=1; var newMap = document.getElementById('newMap');
var newFileName = document.getElementById('newFileName');
newMap.onclick = function () {
if (!newFileName.value) return;
editor_mode.onmode('');
editor.file.saveNewFile(newFileName.value, function (err) {
if (err) {
printe(err);
throw(err)
}
core.floorIds.push(newFileName.value);
editor.file.editTower([['change', "['main']['floorIds']", core.floorIds]], function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printe('新建成功,请F5刷新编辑器生效');
});
});
}
var ratio = 1;
var appendPicCanvas = document.getElementById('appendPicCanvas'); var appendPicCanvas = document.getElementById('appendPicCanvas');
var bg = appendPicCanvas.children[0]; var bg = appendPicCanvas.children[0];
var source = appendPicCanvas.children[1]; var source = appendPicCanvas.children[1];
@ -379,37 +461,37 @@ editor_mode.prototype.listen = function(callback){
var appendPicSelection = document.getElementById('appendPicSelection'); var appendPicSelection = document.getElementById('appendPicSelection');
var selectAppend = document.getElementById('selectAppend'); var selectAppend = document.getElementById('selectAppend');
var selectAppend_str=[]; var selectAppend_str = [];
["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48"].forEach(function(image){ ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48"].forEach(function (image) {
selectAppend_str.push(["<option value='",image,"'>",image,'</option>\n'].join('')); selectAppend_str.push(["<option value='", image, "'>", image, '</option>\n'].join(''));
}); });
selectAppend.innerHTML=selectAppend_str.join(''); selectAppend.innerHTML = selectAppend_str.join('');
selectAppend.onchange = function(){ selectAppend.onchange = function () {
var value = selectAppend.value; var value = selectAppend.value;
var ysize = selectAppend.value.indexOf('48')===-1?32:48; var ysize = selectAppend.value.indexOf('48') === -1 ? 32 : 48;
editor_mode.appendPic.imageName = value; editor_mode.appendPic.imageName = value;
var img = editor.material.images[value]; var img = editor.material.images[value];
editor_mode.appendPic.toImg = img; editor_mode.appendPic.toImg = img;
var num = ~~img.width/32; var num = ~~img.width / 32;
editor_mode.appendPic.num = num; editor_mode.appendPic.num = num;
editor_mode.appendPic.index = 0; editor_mode.appendPic.index = 0;
var selectStr = ''; var selectStr = '';
for(var ii=0;ii<num;ii++){ for (var ii = 0; ii < num; ii++) {
appendPicSelection.children[ii].style='left:0;top:0;height:'+(ysize-6)+'px'; appendPicSelection.children[ii].style = 'left:0;top:0;height:' + (ysize - 6) + 'px';
selectStr+='{"x":0,"y":0},' selectStr += '{"x":0,"y":0},'
} }
editor_mode.appendPic.selectPos = eval('['+selectStr+']'); editor_mode.appendPic.selectPos = eval('[' + selectStr + ']');
for(var jj=num;jj<4;jj++){ for (var jj = num; jj < 4; jj++) {
appendPicSelection.children[jj].style='display:none'; appendPicSelection.children[jj].style = 'display:none';
} }
sprite.style.width = (sprite.width = img.width)/ratio + 'px'; sprite.style.width = (sprite.width = img.width) / ratio + 'px';
sprite.style.height = (sprite.height = img.height+ysize)/ratio + 'px'; sprite.style.height = (sprite.height = img.height + ysize) / ratio + 'px';
sprite.getContext('2d').drawImage(img, 0, 0); sprite.getContext('2d').drawImage(img, 0, 0);
} }
selectAppend.onchange(); selectAppend.onchange();
var selectFileBtn = document.getElementById('selectFileBtn'); var selectFileBtn = document.getElementById('selectFileBtn');
selectFileBtn.onclick = function(){ selectFileBtn.onclick = function () {
var loadImage = function (content, callback) { var loadImage = function (content, callback) {
var image = new Image(); var image = new Image();
try { try {
@ -426,29 +508,29 @@ editor_mode.prototype.listen = function(callback){
printe(e); printe(e);
} }
} }
core.readFile(function(content){ core.readFile(function (content) {
loadImage(content,function(image){ loadImage(content, function (image) {
editor_mode.appendPic.img = image; editor_mode.appendPic.img = image;
editor_mode.appendPic.width = image.width; editor_mode.appendPic.width = image.width;
editor_mode.appendPic.height = image.height; editor_mode.appendPic.height = image.height;
var ysize = selectAppend.value.indexOf('48')===-1?32:48; var ysize = selectAppend.value.indexOf('48') === -1 ? 32 : 48;
for(var ii=0;ii<3;ii++){ for (var ii = 0; ii < 3; ii++) {
var newsprite = appendPicCanvas.children[ii]; var newsprite = appendPicCanvas.children[ii];
newsprite.style.width = (newsprite.width = Math.floor(image.width/32)*32)/ratio + 'px'; newsprite.style.width = (newsprite.width = Math.floor(image.width / 32) * 32) / ratio + 'px';
newsprite.style.height = (newsprite.height = Math.floor(image.height/ysize)*ysize)/ratio + 'px'; newsprite.style.height = (newsprite.height = Math.floor(image.height / ysize) * ysize) / ratio + 'px';
} }
//画灰白相间的格子 //画灰白相间的格子
var bgc = bg.getContext('2d'); var bgc = bg.getContext('2d');
var colorA = ["#f8f8f8", "#cccccc"]; var colorA = ["#f8f8f8", "#cccccc"];
var colorIndex; var colorIndex;
var sratio=4; var sratio = 4;
for (var ii = 0; ii < image.width/32*sratio; ii++){ for (var ii = 0; ii < image.width / 32 * sratio; ii++) {
colorIndex = 1-ii%2; colorIndex = 1 - ii % 2;
for (var jj = 0; jj < image.height/32*sratio; jj++) { for (var jj = 0; jj < image.height / 32 * sratio; jj++) {
bgc.fillStyle = colorA[colorIndex]; bgc.fillStyle = colorA[colorIndex];
colorIndex = 1 - colorIndex; colorIndex = 1 - colorIndex;
bgc.fillRect(ii * 32/sratio, jj * 32/sratio, 32/sratio, 32/sratio); bgc.fillRect(ii * 32 / sratio, jj * 32 / sratio, 32 / sratio, 32 / sratio);
} }
} }
@ -458,7 +540,7 @@ editor_mode.prototype.listen = function(callback){
//重置临时变量 //重置临时变量
selectAppend.onchange(); selectAppend.onchange();
}); });
},null,'img'); }, null, 'img');
return; return;
} }
@ -468,65 +550,68 @@ editor_mode.prototype.listen = function(callback){
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
var loc = { var loc = {
'x': scrollLeft+e.clientX + appendPicCanvas.scrollLeft - left1.offsetLeft-appendPicCanvas.offsetLeft, 'x': scrollLeft + e.clientX + appendPicCanvas.scrollLeft - left1.offsetLeft - appendPicCanvas.offsetLeft,
'y': scrollTop+e.clientY + appendPicCanvas.scrollTop - left1.offsetTop-appendPicCanvas.offsetTop, 'y': scrollTop + e.clientY + appendPicCanvas.scrollTop - left1.offsetTop - appendPicCanvas.offsetTop,
'size': 32, 'size': 32,
'ysize': selectAppend.value.indexOf('48')===-1?32:48 'ysize': selectAppend.value.indexOf('48') === -1 ? 32 : 48
}; };
return loc; return loc;
}//返回可用的组件内坐标 }//返回可用的组件内坐标
var locToPos = function (loc) { var locToPos = function (loc) {
var pos = { 'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.ysize) ,'ysize': loc.ysize} var pos = {'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.ysize), 'ysize': loc.ysize}
return pos; return pos;
} }
picClick.onclick = function(e){ picClick.onclick = function (e) {
var loc = eToLoc(e); var loc = eToLoc(e);
var pos = locToPos(loc); var pos = locToPos(loc);
/*console.log(e,loc,pos);*/ /*console.log(e,loc,pos);*/
var num = editor_mode.appendPic.num; var num = editor_mode.appendPic.num;
var ii = editor_mode.appendPic.index; var ii = editor_mode.appendPic.index;
if(ii+1>=num)editor_mode.appendPic.index=ii+1-num; if (ii + 1 >= num) editor_mode.appendPic.index = ii + 1 - num;
else editor_mode.appendPic.index++; else editor_mode.appendPic.index++;
editor_mode.appendPic.selectPos[ii]=pos; editor_mode.appendPic.selectPos[ii] = pos;
appendPicSelection.children[ii].style=[ appendPicSelection.children[ii].style = [
'left:',pos.x*32,'px;', 'left:', pos.x * 32, 'px;',
'top:',pos.y*pos.ysize,'px;', 'top:', pos.y * pos.ysize, 'px;',
'height:',pos.ysize-6,'px;' 'height:', pos.ysize - 6, 'px;'
].join(''); ].join('');
} }
var appendConfirm = document.getElementById('appendConfirm'); var appendConfirm = document.getElementById('appendConfirm');
appendConfirm.onclick = function(){ appendConfirm.onclick = function () {
var ysize = selectAppend.value.indexOf('48')===-1?32:48; var ysize = selectAppend.value.indexOf('48') === -1 ? 32 : 48;
var sprited = sprite.getContext('2d'); var sprited = sprite.getContext('2d');
//sprited.drawImage(img, 0, 0); //sprited.drawImage(img, 0, 0);
var height = editor_mode.appendPic.toImg.height; var height = editor_mode.appendPic.toImg.height;
var sourced = source.getContext('2d'); var sourced = source.getContext('2d');
for(var ii=0,v;v=editor_mode.appendPic.selectPos[ii];ii++){ for (var ii = 0, v; v = editor_mode.appendPic.selectPos[ii]; ii++) {
var imgData=sourced.getImageData(v.x*32,v.y*ysize,32,ysize); var imgData = sourced.getImageData(v.x * 32, v.y * ysize, 32, ysize);
sprited.putImageData(imgData,ii*32,height); sprited.putImageData(imgData, ii * 32, height);
} }
var imgbase64 = sprite.toDataURL().split(',')[1]; var imgbase64 = sprite.toDataURL().split(',')[1];
fs.writeFile('./project/images/'+editor_mode.appendPic.imageName+'.png',imgbase64,'base64',function(err,data){ fs.writeFile('./project/images/' + editor_mode.appendPic.imageName + '.png', imgbase64, 'base64', function (err, data) {
if(err){printe(err);throw(err)} if (err) {
printe(err);
throw(err)
}
printe('追加素材成功,请F5刷新编辑器'); printe('追加素材成功,请F5刷新编辑器');
}); });
} }
var editModeSelect = document.getElementById('editModeSelect'); var editModeSelect = document.getElementById('editModeSelect');
editModeSelect.onchange = function(){ editModeSelect.onchange = function () {
editor_mode.onmode('nextChange'); editor_mode.onmode('nextChange');
editor_mode.onmode(editModeSelect.value); editor_mode.onmode(editModeSelect.value);
} }
if (Boolean(callback))callback(); if (Boolean(callback)) callback();
} }
var editor_mode = new editor_mode(); var editor_mode = new editor_mode();
editor_mode.init_dom_ids(); editor_mode.init_dom_ids();
return editor_mode; return editor_mode;
} }
//editor_mode = editor_mode(editor); //editor_mode = editor_mode(editor);

View File

@ -1,8 +1,8 @@
editor_multi = function(){ editor_multi = function () {
var editor_multi = {}; var editor_multi = {};
var codeEditor = CodeMirror.fromTextArea(document.getElementById("multiLineCode"), { var codeEditor = CodeMirror.fromTextArea(document.getElementById("multiLineCode"), {
lineNumbers: true, lineNumbers: true,
matchBrackets: true, matchBrackets: true,
indentUnit: 4, indentUnit: 4,
@ -16,127 +16,142 @@ var codeEditor = CodeMirror.fromTextArea(document.getElementById("multiLineCode"
lint: true, lint: true,
autocomplete: true, autocomplete: true,
extraKeys: {"Ctrl-Q": "toggleComment"}, extraKeys: {"Ctrl-Q": "toggleComment"},
}); });
codeEditor.on("keyup", function (cm, event) { codeEditor.on("keyup", function (cm, event) {
if (codeEditor.getOption("autocomplete") && (event.keyCode >= 65 && event.keyCode<=90) || (event.keyCode>=49 && event.keyCode<=57) || event.keyCode==190) { if (codeEditor.getOption("autocomplete") && (event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 49 && event.keyCode <= 57) || event.keyCode == 190) {
try { try {
CodeMirror.commands.autocomplete(cm, null, {completeSingle: false}); CodeMirror.commands.autocomplete(cm, null, {completeSingle: false});
} catch (e) {} } catch (e) {
} }
}); }
});
editor_multi.id=''; editor_multi.id = '';
editor_multi.isString=false; editor_multi.isString = false;
editor_multi.lintAutocomplete=false; editor_multi.lintAutocomplete = false;
editor_multi.show = function(){ editor_multi.show = function () {
if(typeof(selectBox)!==typeof(undefined))selectBox.isSelected = false; if (typeof(selectBox) !== typeof(undefined)) selectBox.isSelected = false;
var valueNow = codeEditor.getValue(); var valueNow = codeEditor.getValue();
//try{eval('function _asdygakufyg_() { return '+valueNow+'\n}');editor_multi.lintAutocomplete=true;}catch(ee){} //try{eval('function _asdygakufyg_() { return '+valueNow+'\n}');editor_multi.lintAutocomplete=true;}catch(ee){}
if(valueNow.slice(0,8)==='function')editor_multi.lintAutocomplete=true; if (valueNow.slice(0, 8) === 'function') editor_multi.lintAutocomplete = true;
editor_multi.setLint(); editor_multi.setLint();
document.getElementById('left7').style=''; document.getElementById('left7').style = '';
} }
editor_multi.hide = function(){document.getElementById('left7').style='z-index:-1;opacity: 0;';} editor_multi.hide = function () {
editor_multi.setLint = function() { document.getElementById('left7').style = 'z-index:-1;opacity: 0;';
}
editor_multi.setLint = function () {
codeEditor.setOption("lint", editor_multi.lintAutocomplete); codeEditor.setOption("lint", editor_multi.lintAutocomplete);
codeEditor.setOption("autocomplete", editor_multi.lintAutocomplete); codeEditor.setOption("autocomplete", editor_multi.lintAutocomplete);
document.getElementById("lintCheckbox").checked = editor_multi.lintAutocomplete; document.getElementById("lintCheckbox").checked = editor_multi.lintAutocomplete;
} }
editor_multi.toggerLint = function() { editor_multi.toggerLint = function () {
editor_multi.lintAutocomplete = document.getElementById("lintCheckbox").checked; editor_multi.lintAutocomplete = document.getElementById("lintCheckbox").checked;
editor_multi.setLint(); editor_multi.setLint();
} }
editor_multi.indent = function(field){ editor_multi.indent = function (field) {
if(typeof(editor)!==typeof(undefined) && editor && editor.mode && editor.mode.indent)return editor.mode.indent(field); if (typeof(editor) !== typeof(undefined) && editor && editor.mode && editor.mode.indent) return editor.mode.indent(field);
return '\t'; return '\t';
} }
editor_multi.import = function(id_,args){ editor_multi.import = function (id_, args) {
var thisTr = document.getElementById(id_); var thisTr = document.getElementById(id_);
if(!thisTr)return false; if (!thisTr) return false;
var input = thisTr.children[2].children[0].children[0]; var input = thisTr.children[2].children[0].children[0];
var field = thisTr.children[0].getAttribute('title'); var field = thisTr.children[0].getAttribute('title');
var comment = thisTr.children[1].getAttribute('title'); var comment = thisTr.children[1].getAttribute('title');
if(!input.type || input.type!=='textarea')return false; if (!input.type || input.type !== 'textarea') return false;
editor_multi.id=id_; editor_multi.id = id_;
editor_multi.isString=false; editor_multi.isString = false;
editor_multi.lintAutocomplete=false; editor_multi.lintAutocomplete = false;
if(args.lint===true)editor_multi.lintAutocomplete=true; if (args.lint === true) editor_multi.lintAutocomplete = true;
if(field.indexOf('Effect') !== -1)editor_multi.lintAutocomplete=true; if (field.indexOf('Effect') !== -1) editor_multi.lintAutocomplete = true;
if(input.value.slice(0,1)==='"'){ if (input.value.slice(0, 1) === '"') {
editor_multi.isString=true; editor_multi.isString = true;
codeEditor.setValue(JSON.parse(input.value)||''); codeEditor.setValue(JSON.parse(input.value) || '');
} else { } else {
var num = editor_multi.indent(field); var num = editor_multi.indent(field);
eval('var tobj='+(input.value||'null')); eval('var tobj=' + (input.value || 'null'));
var tmap={}; var tmap = {};
var tstr = JSON.stringify(tobj,function(k,v){if(typeof(v)===typeof('') && v.slice(0,8)==='function'){var id_ = editor.guid();tmap[id_]=v.toString();return id_;}else return v},num); var tstr = JSON.stringify(tobj, function (k, v) {
for(var id_ in tmap){ if (typeof(v) === typeof('') && v.slice(0, 8) === 'function') {
tstr = tstr.replace('"'+id_+'"',tmap[id_]) var id_ = editor.guid();
tmap[id_] = v.toString();
return id_;
} else return v
}, num);
for (var id_ in tmap) {
tstr = tstr.replace('"' + id_ + '"', tmap[id_])
} }
codeEditor.setValue(tstr||''); codeEditor.setValue(tstr || '');
} }
editor_multi.show(); editor_multi.show();
return true; return true;
} }
editor_multi.cancel = function(){ editor_multi.cancel = function () {
editor_multi.hide(); editor_multi.hide();
editor_multi.id=''; editor_multi.id = '';
multiLineArgs=[null,null,null]; multiLineArgs = [null, null, null];
} }
editor_multi.confirm = function (){ editor_multi.confirm = function () {
if(!editor_multi.id){ if (!editor_multi.id) {
editor_multi.id=''; editor_multi.id = '';
return; return;
} }
if(editor_multi.id==='callFromBlockly'){ if (editor_multi.id === 'callFromBlockly') {
editor_multi.id=''; editor_multi.id = '';
editor_multi.multiLineDone(); editor_multi.multiLineDone();
return; return;
} }
var setvalue = function(value){ var setvalue = function (value) {
var thisTr = document.getElementById(editor_multi.id); var thisTr = document.getElementById(editor_multi.id);
editor_multi.id=''; editor_multi.id = '';
var input = thisTr.children[2].children[0].children[0]; var input = thisTr.children[2].children[0].children[0];
if(editor_multi.isString){ if (editor_multi.isString) {
input.value = JSON.stringify(value); input.value = JSON.stringify(value);
} else { } else {
eval('var tobj='+(value||'null')); eval('var tobj=' + (value || 'null'));
var tmap={}; var tmap = {};
var tstr = JSON.stringify(tobj,function(k,v){if(v instanceof Function){var id_ = editor.guid();tmap[id_]=v.toString();return id_;}else return v},4); var tstr = JSON.stringify(tobj, function (k, v) {
for(var id_ in tmap){ if (v instanceof Function) {
tstr = tstr.replace('"'+id_+'"',JSON.stringify(tmap[id_])) var id_ = editor.guid();
tmap[id_] = v.toString();
return id_;
} else return v
}, 4);
for (var id_ in tmap) {
tstr = tstr.replace('"' + id_ + '"', JSON.stringify(tmap[id_]))
} }
input.value = tstr; input.value = tstr;
} }
editor_multi.hide(); editor_multi.hide();
input.onchange(); input.onchange();
} }
setvalue(codeEditor.getValue()||''); setvalue(codeEditor.getValue() || '');
} }
var multiLineArgs=[null,null,null]; var multiLineArgs = [null, null, null];
editor_multi.multiLineEdit = function(value,b,f,args,callback){ editor_multi.multiLineEdit = function (value, b, f, args, callback) {
editor_multi.id='callFromBlockly'; editor_multi.id = 'callFromBlockly';
codeEditor.setValue(value.split('\\n').join('\n')||''); codeEditor.setValue(value.split('\\n').join('\n') || '');
multiLineArgs[0]=b; multiLineArgs[0] = b;
multiLineArgs[1]=f; multiLineArgs[1] = f;
multiLineArgs[2]=callback; multiLineArgs[2] = callback;
editor_multi.lintAutocomplete=Boolean(args.lint); editor_multi.lintAutocomplete = Boolean(args.lint);
editor_multi.show(); editor_multi.show();
} }
editor_multi.multiLineDone = function(){ editor_multi.multiLineDone = function () {
editor_multi.hide(); editor_multi.hide();
if(!multiLineArgs[0] || !multiLineArgs[1] || !multiLineArgs[2])return; if (!multiLineArgs[0] || !multiLineArgs[1] || !multiLineArgs[2]) return;
var newvalue = codeEditor.getValue()||''; var newvalue = codeEditor.getValue() || '';
multiLineArgs[2](newvalue,multiLineArgs[0],multiLineArgs[1]) multiLineArgs[2](newvalue, multiLineArgs[0], multiLineArgs[1])
} }
return editor_multi; return editor_multi;
} }
//editor_multi=editor_multi(); //editor_multi=editor_multi();

View File

@ -1,87 +1,87 @@
(function(){ (function () {
fs = {}; fs = {};
var postsomething = function (data,_ip,callback) { var postsomething = function (data, _ip, callback) {
//callback:function(err, data) //callback:function(err, data)
//data:字符串 //data:字符串
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){ xhr.onreadystatechange = function () {
switch(xhr.readyState){ switch (xhr.readyState) {
case 4 : case 4 :
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) { if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
if (Boolean(callback)){ if (Boolean(callback)) {
if (xhr.responseText.slice(0,6)=='error:'){ if (xhr.responseText.slice(0, 6) == 'error:') {
callback(xhr.responseText,null); callback(xhr.responseText, null);
} else { } else {
callback(null,xhr.responseText); callback(null, xhr.responseText);
} }
} }
//printf(xhr.responseText) //printf(xhr.responseText)
}else{ } else {
if (Boolean(callback))callback(xhr.status,null); if (Boolean(callback)) callback(xhr.status, null);
//printf('error:' + xhr.status+'<br>'+(xhr.responseText||'')); //printf('error:' + xhr.status+'<br>'+(xhr.responseText||''));
} }
break; break;
} }
} }
xhr.open('post',_ip); xhr.open('post', _ip);
xhr.setRequestHeader('Content-Type','text/plain'); xhr.setRequestHeader('Content-Type', 'text/plain');
if(typeof(data)==typeof([][0]) || data==null)data=JSON.stringify({1:2}); if (typeof(data) == typeof([][0]) || data == null) data = JSON.stringify({1: 2});
xhr.send(data); xhr.send(data);
} }
fs.readFile = function (filename,encoding,callback) { fs.readFile = function (filename, encoding, callback) {
if (typeof(filename)!=typeof('')) if (typeof(filename) != typeof(''))
throw 'Type Error in fs.readFile'; throw 'Type Error in fs.readFile';
if (encoding=='utf-8'){ if (encoding == 'utf-8') {
//读文本文件 //读文本文件
//filename:支持"/"做分隔符 //filename:支持"/"做分隔符
//callback:function(err, data) //callback:function(err, data)
//data:字符串 //data:字符串
var data=''; var data = '';
data+='type=utf8&'; data += 'type=utf8&';
data+='name='+filename; data += 'name=' + filename;
postsomething(data,'/readFile',callback); postsomething(data, '/readFile', callback);
return; return;
} }
if (encoding=='base64'){ if (encoding == 'base64') {
//读二进制文件 //读二进制文件
//filename:支持"/"做分隔符 //filename:支持"/"做分隔符
//callback:function(err, data) //callback:function(err, data)
//data:base64字符串 //data:base64字符串
var data=''; var data = '';
data+='type=base64&'; data += 'type=base64&';
data+='name='+filename; data += 'name=' + filename;
postsomething(data,'/readFile',callback); postsomething(data, '/readFile', callback);
return; return;
} }
throw 'Type Error in fs.readFile'; throw 'Type Error in fs.readFile';
} }
fs.writeFile = function (filename,datastr,encoding,callback) { fs.writeFile = function (filename, datastr, encoding, callback) {
if (typeof(filename)!=typeof('') || typeof(datastr)!=typeof('')) if (typeof(filename) != typeof('') || typeof(datastr) != typeof(''))
throw 'Type Error in fs.writeFile'; throw 'Type Error in fs.writeFile';
if (encoding=='utf-8'){ if (encoding == 'utf-8') {
//写文本文件 //写文本文件
//filename:支持"/"做分隔符 //filename:支持"/"做分隔符
//callback:function(err) //callback:function(err)
//datastr:字符串 //datastr:字符串
var data=''; var data = '';
data+='type=utf8&'; data += 'type=utf8&';
data+='name='+filename; data += 'name=' + filename;
data+='&value='+datastr; data += '&value=' + datastr;
postsomething(data,'/writeFile',callback); postsomething(data, '/writeFile', callback);
return; return;
} }
if (encoding=='base64'){ if (encoding == 'base64') {
//写二进制文件 //写二进制文件
//filename:支持"/"做分隔符 //filename:支持"/"做分隔符
//callback:function(err) //callback:function(err)
//datastr:base64字符串 //datastr:base64字符串
var data=''; var data = '';
data+='type=base64&'; data += 'type=base64&';
data+='name='+filename; data += 'name=' + filename;
data+='&value='+datastr; data += '&value=' + datastr;
postsomething(data,'/writeFile',callback); postsomething(data, '/writeFile', callback);
return; return;
} }
throw 'Type Error in fs.writeFile'; throw 'Type Error in fs.writeFile';
@ -91,11 +91,13 @@
//callback:function(err, data) //callback:function(err, data)
//path:支持"/"做分隔符,不以"/"结尾 //path:支持"/"做分隔符,不以"/"结尾
//data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录 //data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录
if (typeof(path)!=typeof('')) if (typeof(path) != typeof(''))
throw 'Type Error in fs.readdir'; throw 'Type Error in fs.readdir';
var data=''; var data = '';
data+='name='+path; data += 'name=' + path;
postsomething(data,'/listFile',function(err, data){callback(err,JSON.parse(data))}); postsomething(data, '/listFile', function (err, data) {
callback(err, JSON.parse(data))
});
return; return;
} }
})(); })();

View File

@ -1,24 +1,41 @@
<!doctype html> <!doctype html>
<html> <html>
<head><meta charset="utf-8"></head> <head>
<body> <meta charset="utf-8">
<script src="./fs.js"></script> </head>
<script> <body>
fs.writeFile('_test.txt','123中a文bc','utf-8',function(e,d){console.log(e);console.log(d);}) <script src="./fs.js"></script>
setTimeout(function() { <script>
fs.writeFile('_test_bin.txt','abc=','base64',function(e,d){console.log(e);console.log(d);}) fs.writeFile('_test.txt', '123中a文bc', 'utf-8', function (e, d) {
console.log(e);
console.log(d);
})
setTimeout(function () {
fs.writeFile('_test_bin.txt', 'abc=', 'base64', function (e, d) {
console.log(e);
console.log(d);
})
}, 1000); }, 1000);
setTimeout(function() { setTimeout(function () {
fs.readFile('_test.txt','utf-8',function(e,d){console.log(e);console.log(d);}) fs.readFile('_test.txt', 'utf-8', function (e, d) {
console.log(e);
console.log(d);
})
}, 2000); }, 2000);
setTimeout(function() { setTimeout(function () {
fs.readFile('_test_bin.txt','base64',function(e,d){console.log(e);console.log(d);}) fs.readFile('_test_bin.txt', 'base64', function (e, d) {
console.log(e);
console.log(d);
})
}, 3000); }, 3000);
setTimeout(function() { setTimeout(function () {
fs.readdir('.',function(e,d){console.log(e);console.log(d);}) fs.readdir('.', function (e, d) {
console.log(e);
console.log(d);
})
}, 4000); }, 4000);
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,22 +1,28 @@
// vue 相关处理 // vue 相关处理
document.body.onmousedown = function(e){ document.body.onmousedown = function (e) {
//console.log(e); //console.log(e);
var eid=[]; var eid = [];
e.path.forEach(function(node){ e.path.forEach(function (node) {
if(!node.getAttribute)return; if (!node.getAttribute) return;
var id_ = node.getAttribute('id'); var id_ = node.getAttribute('id');
if (id_){ if (id_) {
if(['left','left1','left2','left3','left4','left5','left8'].indexOf(id_)!==-1)eid.push('edit'); if (['left', 'left1', 'left2', 'left3', 'left4', 'left5', 'left8'].indexOf(id_) !== -1) eid.push('edit');
eid.push(id_); eid.push(id_);
} }
}); });
//console.log(eid); //console.log(eid);
if(eid.indexOf('edit')===-1){ if (eid.indexOf('edit') === -1) {
if(eid.indexOf('tip')===-1) { if (eid.indexOf('tip') === -1) {
if (selectBox.isSelected) { if (selectBox.isSelected) {
editor_mode.onmode(''); editor_mode.onmode('');
editor.file.saveFloorFile(function(err){if(err){printe(err);throw(err)};printf('地图保存成功');}); editor.file.saveFloorFile(function (err) {
if (err) {
printe(err);
throw(err)
}
;printf('地图保存成功');
});
} }
selectBox.isSelected = false; selectBox.isSelected = false;
} }
@ -24,40 +30,40 @@ document.body.onmousedown = function(e){
//editor.mode.onmode(''); //editor.mode.onmode('');
editor.info = {}; editor.info = {};
} }
iconLib.onmousedown = function(e){ iconLib.onmousedown = function (e) {
e.stopPropagation(); e.stopPropagation();
} }
var exportM = new Vue({ var exportMap = new Vue({
el: '#exportM', el: '#exportMap',
data: { data: {
isExport: false, isExport: false,
}, },
methods: { methods: {
exportMap: function(){ exportMap: function () {
editor.updateMap(); editor.updateMap();
var filestr=''; var filestr = '';
for (var yy = 0; yy < 13; yy++){ for (var yy = 0; yy < 13; yy++) {
filestr+='[' filestr += '['
for (var xx = 0; xx < 13; xx++) { for (var xx = 0; xx < 13; xx++) {
var mapxy=editor.map[yy][xx]; var mapxy = editor.map[yy][xx];
if(typeof(mapxy)==typeof({})){ if (typeof(mapxy) == typeof({})) {
if ('idnum' in mapxy)mapxy=mapxy.idnum; if ('idnum' in mapxy) mapxy = mapxy.idnum;
else { else {
// mapxy='!!?'; // mapxy='!!?';
tip.whichShow = 3; tip.whichShow = 3;
return; return;
} }
}else if(typeof(mapxy)=='undefined'){ } else if (typeof(mapxy) == 'undefined') {
tip.whichShow = 3; tip.whichShow = 3;
return; return;
} }
mapxy=String(mapxy); mapxy = String(mapxy);
mapxy=Array(Math.max(4-mapxy.length,0)).join(' ')+mapxy; mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy;
filestr+=mapxy+(xx==12?'':',') filestr += mapxy + (xx == 12 ? '' : ',')
} }
filestr += ']'+(yy==12?'':',\n'); filestr += ']' + (yy == 12 ? '' : ',\n');
} }
pout.value = filestr; pout.value = filestr;
editArea.mapArr = filestr; editArea.mapArr = filestr;
@ -83,116 +89,124 @@ var editArea = new Vue({
watch: { watch: {
mapArr: function (val, oldval) { mapArr: function (val, oldval) {
var that = this; var that = this;
if(val=='') return; if (val == '') return;
if(exportM.isExport){ if (exportMap.isExport) {
exportM.isExport = false; exportMap.isExport = false;
return; return;
} }
if(that.formatArr()){ if (that.formatArr()) {
that.error = 0; that.error = 0;
setTimeout(function(){ setTimeout(function () {
that.mapArr = that.formatArr(); that.mapArr = that.formatArr();
that.drawMap(); that.drawMap();
tip.whichShow = 8 tip.whichShow = 8
}, 1000); }, 1000);
that.formatTimer = setTimeout(function(){ that.formatTimer = setTimeout(function () {
pout.value = that.formatArr(); pout.value = that.formatArr();
}, 5000); //5s后再格式化不然光标跳到最后很烦 }, 5000); //5s后再格式化不然光标跳到最后很烦
}else{ } else {
that.error = 1; that.error = 1;
} }
}, },
error: function(){ error: function () {
// console.log(editArea.mapArr); // console.log(editArea.mapArr);
} }
}, },
methods: { methods: {
drawMap: function(){ drawMap: function () {
var that = this; var that = this;
// var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' '); // var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' ');
var mapArray = JSON.parse('['+that.mapArr+']'); var mapArray = JSON.parse('[' + that.mapArr + ']');
for(var y=0; y<13; y++) for (var y = 0; y < 13; y++)
for(var x=0; x<13; x++){ for (var x = 0; x < 13; x++) {
var num = mapArray[y][x]; var num = mapArray[y][x];
if(num == 0 ) if (num == 0)
editor.map[y][x] = 0; editor.map[y][x] = 0;
else if(num >= 1000){ else if (num >= 1000) {
that.error = 3; that.error = 3;
editor.map[y][x] = undefined; editor.map[y][x] = undefined;
}else if(typeof(editor.indexs[num][0]) == 'undefined'){ } else if (typeof(editor.indexs[num][0]) == 'undefined') {
that.error = 2; that.error = 2;
editor.map[y][x] = undefined; editor.map[y][x] = undefined;
}else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]]; } else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];
} }
editor.updateMap(); editor.updateMap();
}, },
formatArr: function(){ formatArr: function () {
var formatArrStr = ''; var formatArrStr = '';
var that = this; var that = this;
clearTimeout(that.formatTimer); clearTimeout(that.formatTimer);
if(this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != 169) return false; if (this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != 169) return false;
var arr = this.mapArr.replace(/\s+/g, '').split('],['); var arr = this.mapArr.replace(/\s+/g, '').split('],[');
if(arr.length != 13) return ; if (arr.length != 13) return;
for(var i =0; i<13; i++){ for (var i = 0; i < 13; i++) {
var a = []; var a = [];
formatArrStr +='['; formatArrStr += '[';
if(i==0||i==12) a = arr[i].split(/\D+/).join(' ').trim().split(' '); if (i == 0 || i == 12) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
else a = arr[i].split(/\D+/); else a = arr[i].split(/\D+/);
if(a.length != 13){ if (a.length != 13) {
formatArrStr = ''; formatArrStr = '';
return ; return;
} }
for(var k=0; k<13; k++){ for (var k = 0; k < 13; k++) {
var num = parseInt(a[k]); var num = parseInt(a[k]);
formatArrStr += Array(Math.max(4-String(num).length,0)).join(' ')+num+(k==12?'':','); formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == 12 ? '' : ',');
} }
formatArrStr += ']'+(i==12?'':',\n'); formatArrStr += ']' + (i == 12 ? '' : ',\n');
} }
return formatArrStr; return formatArrStr;
} }
} }
}); });
var editTip = new Vue({ var copyMap = new Vue({
el: '#editTip', el: '#copyMap',
data: { data: {
err: '' err: ''
}, },
methods: { methods: {
copyMap: function(){ copyMap: function () {
tip.whichShow = 0; tip.whichShow = 0;
if(pout.value.trim() != ''){ if (pout.value.trim() != '') {
if(editArea.error) { if (editArea.error) {
this.err = editArea.errors[editArea.error-1]; this.err = editArea.errors[editArea.error - 1];
tip.whichShow = 5 tip.whichShow = 5
return; return;
} }
try{ try {
pout.select(); pout.select();
document.execCommand("Copy"); document.execCommand("Copy");
tip.whichShow = 6; tip.whichShow = 6;
}catch(e){ } catch (e) {
this.err= e; this.err = e;
tip.whichShow = 5; tip.whichShow = 5;
} }
}else{ } else {
tip.whichShow = 7; tip.whichShow = 7;
} }
} }
}, },
}) })
var clear = new Vue({ var clearMap = new Vue({
el: '#clear', el: '#clearMap',
methods: { methods: {
clearMap: function(){ clearMap: function () {
editor.mapInit(); editor.mapInit();
editor_mode.onmode('');
editor.file.saveFloorFile(function (err) {
if (err) {
printe(err);
throw(err)
}
;printf('地图清除成功');
});
editor.updateMap(); editor.updateMap();
clearTimeout(editArea.formatTimer); clearTimeout(editArea.formatTimer);
clearTimeout(tip.timer); clearTimeout(tip.timer);
@ -203,24 +217,46 @@ var clear = new Vue({
} }
} }
}) })
printf = function(str_,type) { var deleteMap = new Vue({
el: '#deleteMap',
methods: {
deleteMap: function () {
editor_mode.onmode('');
var index = core.floorIds.indexOf(editor.currentFloorId);
if (index>=0) {
core.floorIds.splice(index,1);
editor.file.editTower([['change', "['main']['floorIds']", core.floorIds]], function (objs_) {/*console.log(objs_);*/
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printe('删除成功,请F5刷新编辑器生效');
});
}
else printe('删除成功,请F5刷新编辑器生效');
}
}
})
printf = function (str_, type) {
selectBox.isSelected = false; selectBox.isSelected = false;
if(!type){ if (!type) {
tip.whichShow=11; tip.whichShow = 11;
} else { } else {
tip.whichShow=12; tip.whichShow = 12;
} }
setTimeout(function(){ setTimeout(function () {
if(!type){ if (!type) {
tip.msgs[11]=String(str_); tip.msgs[11] = String(str_);
tip.whichShow=12; tip.whichShow = 12;
} else { } else {
tip.msgs[10]=String(str_); tip.msgs[10] = String(str_);
tip.whichShow=11; tip.whichShow = 11;
} }
},1); }, 1);
}
printe = function (str_) {
printf(str_, 'error')
} }
printe = function(str_){printf(str_,'error')}
tip_in_showMode = [ tip_in_showMode = [
'涉及图片的更改需要F5刷新浏览器来生效', '涉及图片的更改需要F5刷新浏览器来生效',
'文本域可以通过双击,在文本编辑器或事件编辑器中编辑', '文本域可以通过双击,在文本编辑器或事件编辑器中编辑',
@ -256,34 +292,34 @@ var tip = new Vue({
}, },
watch: { watch: {
infos: { infos: {
handler: function(val, oldval){ handler: function (val, oldval) {
this.isClearBlock = false; this.isClearBlock = false;
if(typeof(val) != 'undefined'){ if (typeof(val) != 'undefined') {
if(val==0) { if (val == 0) {
this.isClearBlock = true; this.isClearBlock = true;
return; return;
} }
if('id' in val){ if ('id' in val) {
this.hasId = true; this.hasId = true;
}else{ } else {
this.hasId = false; this.hasId = false;
} }
this.isAutotile = false; this.isAutotile = false;
if(val.images == "autotile" && this.hasId) this.isAutotile = true; if (val.images == "autotile" && this.hasId) this.isAutotile = true;
} }
}, },
deep: true deep: true
}, },
whichShow: function(){ whichShow: function () {
var that = this; var that = this;
that.mapMsg = ''; that.mapMsg = '';
that.msgs[4] = "复制失败!"+editTip.err; that.msgs[4] = "复制失败!" + editTip.err;
clearTimeout(that.timer); clearTimeout(that.timer);
if(that.whichShow){ if (that.whichShow) {
that.mapMsg = that.msgs[that.whichShow-1]; that.mapMsg = that.msgs[that.whichShow - 1];
that.timer = setTimeout(function() { that.timer = setTimeout(function () {
if(!(that.whichShow%2)) if (!(that.whichShow % 2))
that.whichShow = 0; that.whichShow = 0;
}, 5000); //5秒后自动清除successwarn不清除 }, 5000); //5秒后自动清除successwarn不清除
} }
@ -297,7 +333,7 @@ var selectBox = new Vue({
isSelected: false isSelected: false
}, },
watch: { watch: {
isSelected: function(){ isSelected: function () {
tip.isSelectedBlock = this.isSelected; tip.isSelectedBlock = this.isSelected;
tip.whichShow = 0; tip.whichShow = 0;
clearTimeout(tip.timer); clearTimeout(tip.timer);
@ -312,26 +348,26 @@ var bgSelect = new Vue({
selectedBg: 'ground', selectedBg: 'ground',
imgname: '' imgname: ''
}, },
watch:{ watch: {
selectedBg: function(){ selectedBg: function () {
editor.bgY = this.bgs.indexOf(this.selectedBg); editor.bgY = this.bgs.indexOf(this.selectedBg);
editor.drawMapBg(); editor.drawMapBg();
} }
}, },
methods: { methods: {
updatebg: function(){ updatebg: function () {
tip.whichShow = 0; tip.whichShow = 0;
var regx = /\S+\.(png|bmp|jpg|jpeg|gif)$/i; var regx = /\S+\.(png|bmp|jpg|jpeg|gif)$/i;
if(regx.test(this.imgname)){ if (regx.test(this.imgname)) {
var url = 'images/'+this.imgname; var url = 'images/' + this.imgname;
editor.loadImg(url).then(function(img){ editor.loadImg(url).then(function (img) {
editor.drawMapBg(img); editor.drawMapBg(img);
tip.whichShow = 10; tip.whichShow = 10;
}).catch(function(err){ }).catch(function (err) {
console.log(err); console.log(err);
tip.whichShow = 9; tip.whichShow = 9;
}); });
}else{ } else {
tip.whichShow = 9; tip.whichShow = 9;
} }
} }

View File

@ -1,15 +1,15 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<link href="_server/css/editor.css" rel="stylesheet"> <link href="_server/css/editor.css" rel="stylesheet">
<link href="_server/CodeMirror/codemirror.css" rel="stylesheet"> <link href="_server/CodeMirror/codemirror.css" rel="stylesheet">
<link href="_server/CodeMirror/show-hint.css" rel="stylesheet"> <link href="_server/CodeMirror/show-hint.css" rel="stylesheet">
<link href="_server/CodeMirror/lint.css" rel="stylesheet"> <link href="_server/CodeMirror/lint.css" rel="stylesheet">
<link href="_server/css/editor_mode.css" rel="stylesheet"> <link href="_server/css/editor_mode.css" rel="stylesheet">
</head> </head>
<body> <body>
<div class="main"> <div class="main">
<div id="left" style="z-index:-1;opacity: 0;"><!-- map --> <div id="left" style="z-index:-1;opacity: 0;"><!-- map -->
<div id="arrEditor"> <div id="arrEditor">
<table class="col" id='arrColMark'></table> <table class="col" id='arrColMark'></table>
@ -18,15 +18,15 @@
<textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea> <textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea>
<p class="warnText" v-if="error">{{ errors[error-1] }}</p> <p class="warnText" v-if="error">{{ errors[error-1] }}</p>
</div> </div>
<div id="editTip" v-cloak> <div id="editTip">
<br> <input type="button" value="新建空白地图" id='newMap'/>
<input type="button" value="新建空白地图" id='saveFloorAs'/> <input id='newFileName' placeholder="输入新楼层id"/>
<input id='saveAsName' placeholder="输入新楼层id"/>
<input class='btn' type="button" value="复制地图" v-on:click="copyMap"/>
</div> </div>
<div style="position: absolute;right: 10px;bottom:70px;"> <div style="position: absolute;left: 10px;bottom:0; margin-bottom: 90px">
<input class='btn' id='clear' type="button" value="清除地图" v-on:click="clearMap"/> <input type="button" value="导出地图" id="exportMap" v-on:click="exportMap"/>
<input class='btn' type="button" value="导出地图" id="exportM" v-on:click="exportMap"/> <input type="button" value="复制地图" id="copyMap" v-on:click="copyMap"/>
<input type="button" value="清除地图" id='clearMap' v-on:click="clearMap"/>
<input type="button" value="删除地图" id="deleteMap" v-on:click="deleteMap"/>
</div> </div>
</div> </div>
<div id="objDataEditor"> <div id="objDataEditor">
@ -42,7 +42,8 @@
<div class="leftTabContent"> <div class="leftTabContent">
<p> <p>
<input id="selectFileBtn" type="button" value="导入文件到画板"/> <input id="selectFileBtn" type="button" value="导入文件到画板"/>
<select id="selectAppend"></select><!-- ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48"] --> <select id="selectAppend"></select>
<!-- ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48"] -->
<input id="appendConfirm" type="button" value="追加"/> <input id="appendConfirm" type="button" value="追加"/>
</p> </p>
<div id="appendPicCanvas" style="position:relative;overflow: auto;height:470px;"> <div id="appendPicCanvas" style="position:relative;overflow: auto;height:470px;">
@ -57,21 +58,29 @@
<div class="appendSelection"><span style="top: 12px; left: 14px;">4</span></div> <div class="appendSelection"><span style="top: 12px; left: 14px;">4</span></div>
</div> </div>
</div> </div>
</div></div> </div>
</div>
<div id="left2" class='leftTab' style="z-index:-1;opacity: 0;"><!-- loc --> <div id="left2" class='leftTab' style="z-index:-1;opacity: 0;"><!-- loc -->
<h3 class="leftTabHeader">地图选点&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button></h3> <h3 class="leftTabHeader">地图选点&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button>
</h3>
<div class="leftTabContent"> <div class="leftTabContent">
<p id='pos_a6771a78_a099_417c_828f_0a24851ebfce' style="margin-left: 15px">0,0</p> <p id='pos_a6771a78_a099_417c_828f_0a24851ebfce' style="margin-left: 15px">0,0</p>
<div class='etable'> <div class='etable'>
<table> <table>
<tbody id='table_3d846fc4_7644_44d1_aa04_433d266a73df'> <tbody id='table_3d846fc4_7644_44d1_aa04_433d266a73df'>
<tr><td>条目</td><td>注释</td><td></td></tr> <tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div></div> </div>
</div>
<div id="left3" class='leftTab' style="z-index:-1;opacity: 0;"><!-- emenyitem --> <div id="left3" class='leftTab' style="z-index:-1;opacity: 0;"><!-- emenyitem -->
<h3 class="leftTabHeader">图块属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button></h3> <h3 class="leftTabHeader">图块属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button>
</h3>
<div class="leftTabContent"> <div class="leftTabContent">
<div id='newIdIdnum'><!-- id and idnum --> <div id='newIdIdnum'><!-- id and idnum -->
<input placeholder="输入新id唯一标识符"/> <input placeholder="输入新id唯一标识符"/>
@ -82,35 +91,53 @@
<div class='etable'> <div class='etable'>
<table> <table>
<tbody id='table_a3f03d4c_55b8_4ef6_b362_b345783acd72'> <tbody id='table_a3f03d4c_55b8_4ef6_b362_b345783acd72'>
<tr><td>条目</td><td>注释</td><td></td></tr> <tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div></div> </div>
</div>
<div id="left4" class='leftTab' style="z-index:-1;opacity: 0;"><!-- floor --> <div id="left4" class='leftTab' style="z-index:-1;opacity: 0;"><!-- floor -->
<h3 class="leftTabHeader">楼层属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button></h3> <h3 class="leftTabHeader">楼层属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button>
</h3>
<div class="leftTabContent"> <div class="leftTabContent">
<div class='etable'> <div class='etable'>
<table> <table>
<tbody id='table_4a3b1b09_b2fb_4bdf_b9ab_9f4cdac14c74'> <tbody id='table_4a3b1b09_b2fb_4bdf_b9ab_9f4cdac14c74'>
<tr><td>条目</td><td>注释</td><td></td></tr> <tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div></div> </div>
</div>
<div id="left5" class='leftTab' style="z-index:-1;opacity: 0;"><!-- tower --> <div id="left5" class='leftTab' style="z-index:-1;opacity: 0;"><!-- tower -->
<h3 class="leftTabHeader">全塔属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button></h3> <h3 class="leftTabHeader">全塔属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button>
</h3>
<div class="leftTabContent"> <div class="leftTabContent">
<div class='etable'> <div class='etable'>
<table> <table>
<tbody id='table_b6a03e4c_5968_4633_ac40_0dfdd2c9cde5'> <tbody id='table_b6a03e4c_5968_4633_ac40_0dfdd2c9cde5'>
<tr><td>条目</td><td>注释</td><td></td></tr> <tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div></div> </div>
<div id="left6" class='leftTab' style="z-index:-1;opacity: 0;"><div style="position: relative; height: 95%"><!-- eventsEditor --> </div>
<div id="left6" class='leftTab' style="z-index:-1;opacity: 0;">
<div style="position: relative; height: 95%"><!-- eventsEditor -->
<h3>事件编辑器 &nbsp;&nbsp; <h3>事件编辑器 &nbsp;&nbsp;
<button onclick="editor_blockly.showXML()">Show XML</button> <button onclick="editor_blockly.showXML()">Show XML</button>
<button onclick="editor_blockly.runCode()">console.log(obj=code)</button> <button onclick="editor_blockly.runCode()">console.log(obj=code)</button>
@ -135,28 +162,38 @@
</xml> </xml>
</h3> </h3>
<div style="position: relative;height: 100%"> <div style="position: relative;height: 100%">
<div id="blocklyArea"><div id="blocklyDiv"></div></div> <div id="blocklyArea">
<div id="blocklyDiv"></div>
</div>
<textarea id="codeArea" spellcheck="false"></textarea> <textarea id="codeArea" spellcheck="false"></textarea>
</div> </div>
</div></div> </div>
</div>
<div id="left7" style="z-index:-1;opacity: 0;"><!-- 多行文本编辑器 --> <div id="left7" style="z-index:-1;opacity: 0;"><!-- 多行文本编辑器 -->
<button onclick="editor_multi.confirm()">confirm</button> <button onclick="editor_multi.confirm()">confirm</button>
<button onclick="editor_multi.cancel()">cancel</button> <button onclick="editor_multi.cancel()">cancel</button>
<input type="checkbox" onclick="editor_multi.toggerLint()" id="lintCheckbox" style="vertical-align: bottom;margin-left:6px" /> <input type="checkbox" onclick="editor_multi.toggerLint()" id="lintCheckbox"
style="vertical-align: bottom;margin-left:6px"/>
<span style="vertical-align: bottom; margin-left: -3px">Lint</span> <span style="vertical-align: bottom; margin-left: -3px">Lint</span>
<textarea id="multiLineCode" name="multiLineCode"></textarea> <textarea id="multiLineCode" name="multiLineCode"></textarea>
</div> </div>
<div id="left8" class='leftTab' style="z-index:-1;opacity: 0;"><!-- functions --> <div id="left8" class='leftTab' style="z-index:-1;opacity: 0;"><!-- functions -->
<h3 class="leftTabHeader">脚本编辑&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button></h3> <h3 class="leftTabHeader">脚本编辑&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">save</button>
</h3>
<div class="leftTabContent"> <div class="leftTabContent">
<div class='etable'> <div class='etable'>
<table> <table>
<tbody id='table_e260a2be_5690_476a_b04e_dacddede78b3'> <tbody id='table_e260a2be_5690_476a_b04e_dacddede78b3'>
<tr><td>条目</td><td>注释</td><td></td></tr> <tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div></div> </div>
</div>
<div id="mid"> <div id="mid">
<table class="col" id='mapColMark'></table> <table class="col" id='mapColMark'></table>
<table class="row" id='mapRowMark'></table> <table class="row" id='mapRowMark'></table>
@ -167,14 +204,15 @@
<canvas class='egameCanvas' id='eui' width='416' height='416' style='z-index:100'></canvas> <canvas class='egameCanvas' id='eui' width='416' height='416' style='z-index:100'></canvas>
</div> </div>
<div class="tools"> <div class="tools">
<div id="tip" v-cloak > <div id="tip" v-cloak>
<div v-if="isSelectedBlock" > <div v-if="isSelectedBlock">
<p v-if="isClearBlock" class="infoText">当前选择为清除块,可擦除地图上块</p> <p v-if="isClearBlock" class="infoText">当前选择为清除块,可擦除地图上块</p>
<div v-else> <div v-else>
<p v-if="hasId">图块编号:<span class="infoText">{{ infos['idnum'] }}</span></p> <p v-if="hasId">图块编号:<span class="infoText">{{ infos['idnum'] }}</span></p>
<p v-if="hasId">图块ID<span class="infoText">{{ infos['id'] }}</span></p> <p v-if="hasId">图块ID<span class="infoText">{{ infos['id'] }}</span></p>
<p v-else class="warnText">该图块无对应的数字或ID存在请先前往icons.js和maps.js中进行定义</p> <p v-else class="warnText">该图块无对应的数字或ID存在请先前往icons.js和maps.js中进行定义</p>
<p>图块所在素材:<span class="infoText">{{ infos['images'] + (isAutotile ? '( '+infos['id']+' )' : '') }}</span></p> <p>图块所在素材:<span class="infoText">{{ infos['images'] + (isAutotile ? '( '+infos['id']+' )' : '') }}</span>
</p>
<p>图块索引:<span class="infoText">{{ infos['y'] }}</span></p> <p>图块索引:<span class="infoText">{{ infos['y'] }}</span></p>
</div> </div>
</div> </div>
@ -221,9 +259,9 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- <script>/* --> <!-- <script>/* -->
<div id='gameGroup' style='display:none'> <div id='gameGroup' style='display:none'>
<p id='mainTips'>请稍后...</p> <p id='mainTips'>请稍后...</p>
<div id='startPanel'> <div id='startPanel'>
<div id='startTop'> <div id='startTop'>
@ -320,26 +358,26 @@
<canvas class='gameCanvas' id='weather' width='416' height='416'></canvas> <canvas class='gameCanvas' id='weather' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='ui' width='416' height='416'></canvas> <canvas class='gameCanvas' id='ui' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='data' width='416' height='416'>此浏览器不支持HTML5</canvas> <canvas class='gameCanvas' id='data' width='416' height='416'>此浏览器不支持HTML5</canvas>
</div> </div>
<!-- */</script> --> <!-- */</script> -->
<script> <script>
// 生成定位编号 // 生成定位编号
(function(){ (function () {
var colNum = ' '; var colNum = ' ';
for(var i=0; i<13; i++){ for (var i = 0; i < 13; i++) {
var tpl = '<td>'+i+'<div class="colBlock" style="left:'+(i*32+1)+'px;"></div></td>'; var tpl = '<td>' + i + '<div class="colBlock" style="left:' + (i * 32 + 1) + 'px;"></div></td>';
colNum += tpl; colNum += tpl;
} }
arrColMark.innerHTML = '<tr>'+colNum+'</tr>'; arrColMark.innerHTML = '<tr>' + colNum + '</tr>';
mapColMark.innerHTML = '<tr>'+colNum+'</tr>'; mapColMark.innerHTML = '<tr>' + colNum + '</tr>';
var rowNum = ' '; var rowNum = ' ';
for(var i=0; i<13; i++){ for (var i = 0; i < 13; i++) {
var tpl = '<tr><td>'+i+'<div class="rowBlock" style="top:'+(i*32+1)+'px;"></div></td></tr>'; var tpl = '<tr><td>' + i + '<div class="rowBlock" style="top:' + (i * 32 + 1) + 'px;"></div></td></tr>';
rowNum += tpl; rowNum += tpl;
} }
arrRowMark.innerHTML = rowNum; arrRowMark.innerHTML = rowNum;
mapRowMark.innerHTML = rowNum; mapRowMark.innerHTML = rowNum;
})(); })();
</script> </script>
<!-- =========================================================== --> <!-- =========================================================== -->
@ -353,38 +391,38 @@
<script src='_server/vm.js'></script> <script src='_server/vm.js'></script>
<script id='mainScript' src='main.js'></script> <script id='mainScript' src='main.js'></script>
<script> <script>
//所有全局量 //所有全局量
__all__=['Vue','fs','editor_file','editor_mode','main','core','hasOwnProp','printf','printe','editor','converter','ActionParser','MotaActionFunctions','MotaActionBlocks']; __all__ = ['Vue', 'fs', 'editor_file', 'editor_mode', 'main', 'core', 'hasOwnProp', 'printf', 'printe', 'editor', 'converter', 'ActionParser', 'MotaActionFunctions', 'MotaActionBlocks'];
__id__=['editArea','arrRowMark','mapRowMark','data','bg','dataSelection','blocklyDiv','codeAreaHL','entryType']; __id__ = ['editArea', 'arrRowMark', 'mapRowMark', 'data', 'bg', 'dataSelection', 'blocklyDiv', 'codeAreaHL', 'entryType'];
__Vue__=['exportM','editArea','editTip','clear','tip','selectBox']; __Vue__ = ['editArea', 'exportMap', 'copyMap', 'clearMap', 'deleteMap', 'tip', 'selectBox'];
//var event = document.getElementById('event'); //var event = document.getElementById('event');
var hasOwnProperty = Object.prototype.hasOwnProperty; var hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwnProp (obj, key) {
function hasOwnProp(obj, key) {
return hasOwnProperty.call(obj, key) return hasOwnProperty.call(obj, key)
} }
</script> </script>
<script src='_server/editor.js'></script> <script src='_server/editor.js'></script>
<script> <script>
main.init('editor', function() { main.init('editor', function () {
editor.init(function(){ editor.init(function () {
editor.pos={x: 0, y: 0}; editor.pos = {x: 0, y: 0};
editor.mode.loc(); editor.mode.loc();
editor.info=editor.ids[editor.indexs[201]]; editor.info = editor.ids[editor.indexs[201]];
editor.mode.emenyitem(); editor.mode.emenyitem();
editor.mode.floor(); editor.mode.floor();
editor.mode.tower(); editor.mode.tower();
editor.mode.functions(); editor.mode.functions();
editor.mode.showMode('floor'); editor.mode.showMode('floor');
editor.mode.listen(); editor.mode.listen();
editor_multi=editor_multi(); editor_multi = editor_multi();
editor_blockly=editor_blockly(); editor_blockly = editor_blockly();
});
}); });
});
//main.listen();
//main.listen();
</script> </script>
<!-- hightlight textarea --> <!-- hightlight textarea -->

View File

@ -301,7 +301,7 @@ utils.prototype.readFile = function (success, error, readType) {
if (core.platform.fileInput==null) { if (core.platform.fileInput==null) {
core.platform.fileInput = document.createElement("input"); core.platform.fileInput = document.createElement("input");
core.platform.fileInput.style.display = 'none'; core.platform.fileInput.style.opacity = 0;
core.platform.fileInput.type = 'file'; core.platform.fileInput.type = 'file';
core.platform.fileInput.onchange = function () { core.platform.fileInput.onchange = function () {
var files = core.platform.fileInput.files; var files = core.platform.fileInput.files;

View File

@ -13,7 +13,7 @@ APP端也能下载录像
大数据魔塔的显示 √ 大数据魔塔的显示 √
修改999999999的上界问题 √ 修改999999999的上界问题 √
修复有时候无法输入ID的问题 修复有时候无法输入ID的问题
修复坐标等不能为负数的问题 修复坐标等不能为负数的问题
其他细节优化 其他细节优化
----------------------------------------------------------------------- -----------------------------------------------------------------------