Graal Pastebin

New Paste
Pasted on March 27, 2012.
View the raw file

//join("emerafuncdebug");
 
function onActionServerSide() {
  switch (params[0]) {
  case "placetiles":
    PlaceTiles(params[1], params[2], params[3]);
    break;
  }
}
 
function PlaceTiles(mx, my, ti) {
  temp.tilesel = ti;
  for (temp.i = 0; temp.i < temp.tilesel.size(); temp.i++) {
    for (temp.o = 0; temp.o < temp.tilesel[temp.i].size(); temp.o++) {
      tiles[mx + temp.o, my + temp.i] = temp.tilesel[temp.i][temp.o];
    }
  }
  updateboard2(mx, my, temp.tilesel[0].size(), temp.tilesel.size());
}
 
//#CLIENTSIDE
function onCreated() {
  DrawEditor();
}
 
function onKeyPressed(code, Key) {
  if (code == 220 || Key == "z") {
    Editor();
  }
}
 
function DrawEditor() {
  new GuiControl("EditorWindow") {
    useownprofile = true;
    clientrelative = true;
    width = 750;
    height = 150;
    clientextent = {
      width, height
    };
    x = screenwidth / 2 - width / 2;
    y = 10;
    visible = false;
    profile.border = 2;
    new GuiScrollCtrl("EditorScroll") {
      profile = GuiBlueScrollProfile;
      width = 750;
      height = 150;
      x = y = 0;
      thiso.catchevent(this, "onMouseDragged", "onTilesetSelection");
      thiso.catchevent(this, "onMouseUp", "onTilesetSelect");
      new GuiDrawingPanel("EditorTiles") {
        width = 2048;
        height = 512;
        x = y = 0;
        clearall();
        drawimage(0, 0, gettileset());
        thiso.catchevent(this, "onMouseDragged", "onTilesetSelection");
        thiso.catchevent(this, "onMouseUp", "onTilesetSelect");
        new GuiControl("EditorSelection") {
          useownprofile = true;
          width = 32;
          height = 32;
          x = thiso.endsel[0];
          y = thiso.startsel[1];
          profile.opaque = true;
          profile.fillcolor = {
            255, 255, 255, 100
          };
        }
      }
    }
  }
}
 
function ChatBar.onAction() {
  args = ChatBar.text.tokenize(" ");
  switch (args[0]) {
  case "/ul":
    ChatBar.text = "update level";
    break;
  }
}
 
function Editor() {
  if (EditorWindow.visible == false) {
    EditorWindow.visible = true;
  } else {
    EditorWindow.visible = false;
  }
}
 
function PlaceTiles(mx, my) {
  triggerserver("weapon", this.name, "PlaceTiles", mx, my, this.tilesel);
}
 
function onTilesetSelection(obj, keymod, mx, my) {
  DrawSelection(mx, my);
}
 
function EditorTiles.onMouseDown(keymod, mx, my) {
  EditorSelection.visible = true;
  EditorSelection.width = EditorSelection.height = 16;
  temp.osel = EditorTiles.globaltolocalcoord({
    mx, my
  });
  this.startsel = {
    shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16)
  };
  this.endsel = {
    NULL, NULL
  };
  player.chat = this.startsel;
  MoveSelection(this.startsel[0], this.startsel[1]);
}
 
function MoveSelection(locx, locy) {
  EditorSelection.x = locx;
  EditorSelection.y = locy;
}
 
function DrawSelection(mx, my) {
  temp.osel = EditorTiles.globaltolocalcoord({
    mx, my
  });
  this.endsel = {
    shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16)
  };
  EditorSelection.x = thiso.startsel[0];
  EditorSelection.y = thiso.startsel[1];
  EditorSelection.width = thiso.endsel[0] - thiso.startsel[0];
  EditorSelection.height = thiso.endsel[1] - thiso.startsel[1];
}
 
function onTilesetSelect(obj, keymod, mx, my) {
  SelectMouseTiles(mx, my);
}
 
function SelectMouseTiles(mx, my) {
  temp.osel = EditorTiles.globaltolocalcoord({
    mx, my
  });
  this.endsel = {
    shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16)
  };
  EditorSelection.visible = false;
  GrabTileSelection();
}
 
function GraalControl.onMouseUp() {
  temp.osel = EditorTiles.globaltolocalcoord({
    mx, my
  });
  this.endsel = {
    shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16)
  };
  EditorSelection.visible = false;
  GrabTileSelection();
}
 
function GrabTileSelection() {
  temp.tilew = (this.endsel[0] - this.startsel[0]) / 16;
  temp.tileh = (this.endsel[1] - this.startsel[1]) / 16;
  this.tilesel = {};
  temp.tilear = {};
  for (temp.i = 0; temp.i < temp.tileh; temp.i++) {
    for (temp.o = 0; temp.o < temp.tilew; temp.o++) {
      temp.tilear.add(ImageToTile(this.startsel[0] + (temp.o * 16), this.startsel[1] + (temp.i * 16)));
    }
    this.tilesel.add(temp.tilear);
    player.chat = temp.tilear;
    temp.tilear = {};
  }
  this.tileedit = true;
}
 
function onMouseDown(mode) {
  if (EditorWindow.visible != true) {
    return;
  }
  if (mode == "right" && this.tileedit == true) {
    if (this.tilesel.size() > 0) {
      PlaceTiles(int(mousex), int(mousey));
      player.chat = this.tilesel;
    }
  }
}
 
function GraalControl.onMouseDown() {
  if (EditorWindow.visible != true) {
    return;
  }
  if (!this.start_drag) {
    this.place_tiles = false;
    this.start_drag = true;
    this.drag_type = "level";
    this.start_loc = {
      shared.roundto(mousex, 1), shared.roundto(mousey, 1)
    };
    this.end_loc = {};
  }
}
//Thanks dusty <3
 
function ImageToTile(tx, ty) {
  return this.tile = ((int(tx / 16) % 16) + (int(tx / 256) * 512)) + ((int(ty / 16) * 16) % 512);
}
  • 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
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207