-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
158 lines (130 loc) · 3.75 KB
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
function Map(size) {
this.size = size;
this.map = FixedArray([size, size], ".");
this.SetChar = function(position, char){
var index = this.GetIndex(position);
this.map[index[0]][index[1]] = char;
}
this.GetChar = function(position) {
var index = this.GetIndex(position);
return this.map[index[0]][index[1]];
}
this.GetPosition = function(i, j){
return new Position(j, i);
}
this.GetIndex = function(position){
return [position.y, position.x];
}
}
var MapEmbedded = function(embed){
this.AddProperty("Symbol", "char");
this.skipped = new Property("skipped", "bool", false); this.AddKey("skipped");
this.positions = new Container("positions", Position); this.AddKey("positions");
this.parent = embed;
this.NumPositions = function(){
return this.positions.Size();
}
this.GetPosition = function(i){
return this.positions.GetElement(i);
}
this.AddPosition = function(x, y){
this.positions.Add(new Position(x, y));
}
this.IsInitialized = function(){
return (this.skipped.GetValue() || this.positions.Size());
}
this.PositionSetter = function(){
var new_box = new Box(this.GetName());
new_box.interactions = [new Interaction("Save", this, "Save"), new Interaction("Skip", this, "Skip")];
develop_manager.box_manager.DisplayBox(new_box);
develop_manager.map_manager.OnClickSession("AddPosition", this);
}
this.Skip = function(){
this.skipped.SetValue(true);
this.View();
}
this.Save = function(){
//alert(JSON.stringify(develop_manager.world.GetDict()));
develop_manager.SaveWorld();
this.View();
}
this.GetInteraction = function(){
return new Interaction(this.GetName(), this, "View");
}
this.View = function(){
if (!this.IsInitialized()){
this.PositionSetter();
}
else{
this.Open();
}
}
}
var Mapable = function(){
this.AddProperty("Size", "int");
this.GetSize = function(){
return this.GetPropertyValue("Size");
}
this.GetMap = function() {
var new_map = new Map(this.GetSize());
var container_list = this.GetContainerList();
for (var i = 0; i < container_list.Size(); ++i){
var container = container_list.GetContainer(i);
for (var j = 0; j < container.Size(); ++j){
var element = container.GetElement(j);
if (element.hasOwnProperty("parent") && element.parent.GetName() == this.GetName()){
for (var k = 0; k < element.NumPositions(); ++k){
new_map.SetChar(element.GetPosition(k), element.GetPropertyValue("Symbol"));
}
}
}
}
return new_map;
}
this.DisplayMap = function(){
develop_manager.DisplayMap(this);
}
this.DisplayBoth = function(){
develop_manager.DisplayBoth(this);
}
}
FixedArray = function(dims, element){
var new_array = [];
var object_pushed = element;
for (var i = 0; i < dims.length; ++i){
for (var j = 0; j < dims[i]; ++j){
if (object_pushed == element){
new_array.push(object_pushed);
}
else {
var new_object = object_pushed.slice();
new_array.push(new_object);
}
}
object_pushed = new_array;
new_array = [];
}
return object_pushed;
}
// Reloads Screen with updated variables
function PrintMap(){
new_map = TempReplMap(character, "@");
// Print Screen
document.getElementById("map").innerHTML = new_map;
GenerateBox();
}
function TempReplMap(position, ch) {
var new_map = map.replaceAt(GetElement(position.x, position.y), ch);
return new_map;
}
function ReplaceMap(position, ch){
map = map.replaceAt(GetElement(position.x, position.y), ch);
}
function GetElement(x, y){
return 4 + 27 + 27 * y + (x + 1);
// <tt>, top line, lines above, sideways characters
}
function GetMapElement(position){
return map.charAt(GetElement(position.x, position.y));
// <tt>, top line, lines above, sideways characters
}