MCPcopy Create free account
hub / github.com/AlexNisnevich/untrusted / CodeEditor

Function CodeEditor

scripts/codeEditor.js:1–490  ·  view source on GitHub ↗
(textAreaDomID, width, height, game)

Source from the content-addressed store, hash-verified

1function CodeEditor(textAreaDomID, width, height, game) {
2 var symbols = {
3 'begin_line':'#BEGIN_EDITABLE#',
4 'end_line':'#END_EDITABLE#',
5 'begin_char':"#{#",
6 'end_char': "#}#",
7 'begin_properties':'#BEGIN_PROPERTIES#',
8 'end_properties':'#END_PROPERTIES#',
9 'start_start_level':'#START_OF_START_LEVEL#',
10 'end_start_level':'#END_OF_START_LEVEL#'
11 };
12
13 var charLimit = 80;
14
15 var properties = {};
16 var editableLines = [];
17 var editableSections = {};
18 var lastChange = {};
19 var startOfStartLevel = null;
20 var endOfStartLevel = null;
21
22 this.setEndOfStartLevel = function (eosl) {
23 endOfStartLevel = eosl;
24 }
25
26 this.setEditableLines = function (el) {
27 editableLines = el;
28 }
29
30 this.setEditableSections = function (es) {
31 editableSections = es;
32 }
33
34 // for debugging purposes
35 log = function (text) {
36 if (game._debugMode) {
37 console.log(text);
38 }
39 }
40
41 // preprocesses code,determines the location
42 // of editable lines and sections, loads properties
43 function preprocess(codeString) {
44 editableLines = [];
45 editableSections = {};
46 endOfStartLevel = null;
47 startOfStartLevel = null;
48 var propertiesString = '';
49
50 var lineArray = codeString.split("\n");
51 var inEditableBlock = false;
52 var inPropertiesBlock = false;
53
54 for (var i = 0; i < lineArray.length; i++) {
55 var currentLine = lineArray[i];
56
57 // process properties
58 if (currentLine.indexOf(symbols.begin_properties) === 0) {
59 lineArray.splice(i,1); // be aware that this *mutates* the list
60 i--;

Callers

nothing calls this directly

Calls 1

preprocessFunction · 0.85

Tested by

no test coverage detected