Skip to content

Commit

Permalink
TileLayer fix and restructuring
Browse files Browse the repository at this point in the history
Editor mostly implemented, RasterWindow is buggy
  • Loading branch information
ZILtoid1991 committed Oct 12, 2019
1 parent eb0d80d commit d28c3cf
Show file tree
Hide file tree
Showing 28 changed files with 836 additions and 214 deletions.
40 changes: 40 additions & 0 deletions ETML.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Purpose of the ETML (Embedded Text Markup Language):

* Provide some familiar way to format text
* Provide some basic compatibility with HTML

# Markup tags

## Tags with the same behavior as their HTML counterpart

* `<p></p>`
* `<u></u>`
* `</ br>`
* `<s></s>`

Note: `u` and `s` (and `o`) can be formatted with attributes
* `style` (possible values: `single`, `double`, `triple`, `quad`),
* `lines` (possible values: `normal`, `dotted`, `wavy`, `wavySoft`, `stripes`),
* and `perWord` (possible values: `true`, `false`).

## Tags special to ETML

* `<o></o>`

Turns the text overstriken (puts a line on top of the selected text).

* `<i></i>`

Marks the text as italic. The amount can be set with the attribute `amount`.

* `<font type="OpenSans-reg-14" color="15"></font>`

Sets the type of the font.

* `</ frontTab amount="10">`

Inserts a tabulator at the given position.

* `</ image src="jeffrey">`

Inserts an image at the current position.
Binary file modified assets/_system/OpenSans-reg-14_0.tga
Binary file not shown.
Binary file added assets/_system/concreteGUIE0.tga
Binary file not shown.
Binary file added assets/_system/concreteGUIE1.tga
Binary file not shown.
Binary file added assets/_system/concreteGUIE2.tga
Binary file not shown.
Binary file added assets/_system/concreteGUIE3.tga
Binary file not shown.
Binary file modified assets/_system/scp-14-reg_0.tga
Binary file not shown.
Binary file removed assets/collisionTest.xmp
Binary file not shown.
Binary file added assets/d-man.tga
Binary file not shown.
Binary file added assets/sci-fi-tileset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/tiletest.xmp
Binary file not shown.
3 changes: 2 additions & 1 deletion dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ targetPath "./pixelperfectengine/lib/"
dependency "sdlang-d" version="*"
dependency "bindbc-sdl" version="*"
versions "SDL_205" "BindSDL_Mixer"
dependency "dimage" version="==0.2.0"
dependency "dimage" version="==0.2.2"
//dependency "datapak" version="==0.1.0-beta"
dependency "cpublit" version="*"
dependency "intel-intrinsics" version="*"
dependency "libpcm" version="==0.2.2"
dependency "bmfont" version="==0.1.0"
dependency "std-experimental-xml" version="*"
subPackage{
name "pixelperfecteditor"
targetType "executable"
Expand Down
8 changes: 5 additions & 3 deletions dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"fileVersion": 1,
"versions": {
"bindbc-loader": "0.2.1",
"bindbc-sdl": "0.9.0",
"bindbc-sdl": "0.13.0",
"bmfont": "0.1.0",
"cpublit": "0.3.2",
"derelict-fi": "2.0.3",
"derelict-sdl2": "2.1.4",
"derelict-util": "2.0.6",
"dimage": "0.2.0",
"intel-intrinsics": "1.1.1",
"dimage": "0.2.2",
"intel-intrinsics": "1.2.0",
"libinputvisitor": "1.2.2",
"libpcm": "0.2.2",
"sdlang-d": "0.10.5",
"std-experimental-xml": "0.1.7",
"stdx-allocator": "2.77.5",
"taggedalgebraic": "0.11.4",
"unit-threaded": "0.7.55",
"vfile": "0.1.2"
Expand Down
77 changes: 42 additions & 35 deletions pixelperfecteditor/src/PixelPerfectEditor/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public Editor prg;
int main(string[] args){
initialzeSDL();

/+if(args.length > 1){
if(args.length > 1){
if(args[1] == "--test"){
TileLayerTest prg = new TileLayerTest();
prg.whereTheMagicHappens;
writeln(prg.isRunning);
//writeln(prg.isRunning);
return 0;
}
}+/
}

prg = new Editor(args);
prg.whereTheMagicHappens;
Expand Down Expand Up @@ -80,9 +80,9 @@ class TileLayerTest : SystemEventListener, InputListener{
OutputScreen output;
Raster r;
TileLayer t;
TransformableTileLayer!(Bitmap16Bit,32,32) tt;
ABitmap[] tiles;
Bitmap16Bit dlangMan;
TransformableTileLayer!(Bitmap8Bit,16,16) tt;
Bitmap8Bit[] tiles;
Bitmap8Bit dlangMan;
SpriteLayer s;
//Bitmap16Bit[wchar] tiles;
InputHandler ih;
Expand All @@ -91,43 +91,44 @@ class TileLayerTest : SystemEventListener, InputListener{
this(){
theta = 0;
isRunning = true;
ExtendibleBitmap tileSource = new ExtendibleBitmap("../assets/tiletest.xmp");
ExtendibleBitmap spriteSource = new ExtendibleBitmap("../assets/collisionTest.xmp");
//t = new TileLayer(32,32, LayerRenderingMode.COPY);
tt = new TransformableTileLayer!(Bitmap16Bit,32,32)(LayerRenderingMode.COPY);
Image tileSource = loadImage(File("../assets/sci-fi-tileset.png"));
Image spriteSource = loadImage(File("../assets/d-man.tga"));
t = new TileLayer(16,16, LayerRenderingMode.COPY);
tt = new TransformableTileLayer!(Bitmap8Bit,16,16)(LayerRenderingMode.COPY);
s = new SpriteLayer(LayerRenderingMode.ALPHA_BLENDING);
//c = new CollisionDetector();
dlangMan = loadBitmapFromXMP!Bitmap16Bit(spriteSource,"DLangMan");
dlangMan = loadBitmapFromImage!Bitmap8Bit(spriteSource);
//CollisionModel cm = new CollisionModel(dlangMan.width, dlangMan.height, dlangMan.generateStandardCollisionModel());
dlangMan.offsetIndexes(256,false);
s.addSprite(dlangMan,0,0,0);
s.addSprite(dlangMan, 0, 0, 0, 1);
//s.scaleSpriteHoriz(0,-1024);
//s.scaleSpriteVert(0,-1024);
for(int i = 1 ; i < 2 ; i++){
s.addSprite(dlangMan,i,uniform(-31,320),uniform(-31,240));
for(int i = 1 ; i < 10 ; i++){
s.addSprite(dlangMan, i, uniform(-31,320), uniform(-31,240), 1);
}
//s.collisionDetector[1] = c;
//c.source = s;
//c.addCollisionModel(cm,0);
//c.addCollisionModel(cm,1);
//c.addCollisionListener(this);
tiles.length = tileSource.bitmapID.length;
for(int i; i < tileSource.bitmapID.length; i++){
string hex = tileSource.bitmapID[i];
//tiles.length = tileSource.bitmapID.length;
tiles = loadBitmapSheetFromImage!Bitmap8Bit(tileSource, 16, 16);//loadBitmapSheetFromFile!Bitmap8Bit("../assets/sci-fi-tileset.png",16,16);
for(int i; i < tiles.length; i++){
//string hex = tileSource.bitmapID[i];
//writeln(hex[hex.length-4..hex.length]);
ABitmap ab = loadBitmapFromXMP!Bitmap16Bit(tileSource, hex);
tiles[i] = ab;
tt.addTile(ab, to!wchar(parseHex(hex[hex.length-4..hex.length])));
//ABitmap ab = loadBitmapFromXMP!Bitmap16Bit(tileSource, hex);
//tiles[i] = ab;
t.addTile(tiles[i], cast(wchar)i);
}
//wchar[] mapping;
MappingElement[] mapping;
mapping.length = 16*16;
mapping.length = 64*64;
//attrMapping.length = 256*256;
for(int i; i < mapping.length; i++){
//mapping[i] = to!wchar(uniform(0x0000,0x00AA));
int rnd = uniform(0,1024);
const int rnd = uniform(0,1024);
//attrMapping[i] = BitmapAttrib(rnd & 1 ? true : false, rnd & 2 ? true : false);
mapping[i] = MappingElement(to!wchar(uniform(0x0000,0x00AA)), BitmapAttrib(rnd & 1 ? true : false, rnd & 2 ? true : false));
mapping[i] = MappingElement(cast(wchar)(rnd & 63), BitmapAttrib(rnd & 1024 ? true : false, rnd & 512 ? true : false));
}
ih = new InputHandler();
ih.sel ~= this;
Expand Down Expand Up @@ -161,26 +162,32 @@ class TileLayerTest : SystemEventListener, InputListener{
ih.kb ~= KeyBinding(0, ScanCode.Q,0, "HM", Devicetype.KEYBOARD, KeyModifier.ANY);
ih.kb ~= KeyBinding(0, ScanCode.W,0, "VM", Devicetype.KEYBOARD, KeyModifier.ANY);

tt.loadMapping(16,16,mapping);
tt.setWarpMode(true);
//tt.hBlankInterrupt = &ttlHBlankInterrupt;
t.loadMapping(64,64,mapping);
t.setWarpMode(false);

//t.setWrapMode(true);
//tt.D = -256;
output = new OutputScreen("TileLayer test", 1280,960);
r = new Raster(320,240,output);
output.setMainRaster(r);
loadPaletteFromXMP(tileSource, "default", r);
//loadPaletteFromXMP(tileSource, "default", r);

/*for(int y ; y < 240 ; y++){
for(int x ; x < 240 ; x++){
writeln('[',x,',',y,"] : ", t.transformFunc([x,y]));
}
}*/
r.addLayer(tt, 0);
r.addLayer(t, 0);
r.addLayer(s, 1);
r.palette ~= cast(Color[])spriteSource.getPalette("default");
r.palette[0].alpha = 255;
Color[] localPal = loadPaletteFromImage(tileSource);
localPal.length = 256;
r.palette ~= localPal;
localPal = loadPaletteFromImage(spriteSource);
localPal.length = 256;
r.palette ~= localPal;
//r.palette[0].alpha = 255;
r.palette[256].raw = 0;
writeln(tt);
//writeln(tt);
//r.palette[0] = 255;
//r.addRefreshListener(output, 0);

Expand All @@ -196,10 +203,10 @@ class TileLayerTest : SystemEventListener, InputListener{
if(down) s.relMoveSprite(0,0,1);
if(left) s.relMoveSprite(0,-1,0);
if(right) s.relMoveSprite(0,1,0);
if(scrup) tt.relScroll(0,-1);
if(scrdown) tt.relScroll(0,1);
if(scrleft) tt.relScroll(-1,0);
if(scrright) tt.relScroll(1,0);
if(scrup) t.relScroll(0,-1);
if(scrdown) t.relScroll(0,1);
if(scrleft) t.relScroll(-1,0);
if(scrright) t.relScroll(1,0);
//t.relScroll(1,0);
}
}
Expand Down
58 changes: 42 additions & 16 deletions pixelperfecteditor/src/PixelPerfectEditor/document.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public class MapDocument {
* Loads the document from disk.
*/
public this(string filename) @trusted {

events = new UndoableStack(20);
}
///New from scratch
public this(string docName, int resX, int resY) @trusted {
events = new UndoableStack(20);
mainDoc = new MapFormat(docName, resX, resY);
mode = EditMode.tilePlacement;
}
///Returns the next available layer number.
public int nextLayerNumber() @safe {
Expand Down Expand Up @@ -93,18 +94,20 @@ public class MapDocument {
}
break;
case EditMode.tilePlacement:

switch (button) {
case MouseButton.LEFT:
//Record the first cursor position upon mouse button press, then initialize either a single or zone write for the selected tile layer.
if (state == ButtonState.PRESSED) {
prevMouseX = x;
prevMouseY = y;
} else {

ITileLayer target = cast(ITileLayer)(mainDoc[selectedLayer]);
x = (x + mainDoc[selectedLayer].getSX) / target.getTX;
y = (y + mainDoc[selectedLayer].getSY) / target.getTY;
prevMouseX = (prevMouseX + mainDoc[selectedLayer].getSX) / target.getTX;
prevMouseY = (prevMouseY + mainDoc[selectedLayer].getSY) / target.getTY;
x = (x - mainDoc[selectedLayer].getSX) / target.getTileWidth;
y = (y - mainDoc[selectedLayer].getSY) / target.getTileHeight;
prevMouseX = (prevMouseX - mainDoc[selectedLayer].getSX) / target.getTileWidth;
prevMouseY = (prevMouseY - mainDoc[selectedLayer].getSY) / target.getTileHeight;
Coordinate c;
if (x > prevMouseX){
c.left = prevMouseX;
Expand All @@ -122,28 +125,32 @@ public class MapDocument {
}

if (voidfill) {
if (c.width == 1 && c.height == 1) {
if (c.width == 0 && c.height == 0) {
if (target.readMapping(c.left, c.top).tileID == 0xFFFF)
target.writeMapping(c.left, c.top, selectedMappingElement);
events.addToTop(new WriteToMapSingle(target, c.left, c.top, selectedMappingElement));
/+ target.writeMapping(c.left, c.top, selectedMappingElement);+/

} else {
for (int y0 = c.top ; y0 <= c.bottom ; y0++){
/+for (int y0 = c.top ; y0 <= c.bottom ; y0++){
for (int x0 = c.left ; x0 <= c.right ; x0++) {
if (target.readMapping(x0, y0).tileID == 0xFFFF)
target.writeMapping(x0, y0, selectedMappingElement);
}
}
}+/
events.addToTop(new WriteToMapVoidFill(target, c, selectedMappingElement));
}
} else {
if (c.width == 1 && c.height == 1) {
target.writeMapping(c.left, c.top, selectedMappingElement);
if (c.width == 0 && c.height == 0) {
events.addToTop(new WriteToMapSingle(target, c.left, c.top, selectedMappingElement));

} else {
for (int y0 = c.top ; y0 <= c.bottom ; y0++){
for (int x0 = c.left ; x0 <= c.right ; x0++) {
target.writeMapping(x0, y0, selectedMappingElement);
}
}
events.addToTop(new WriteToMapOverwrite(target, c, selectedMappingElement));
}
}
debug {
import std.stdio : writeln;
writeln(events.events);
}
}
break;
case MouseButton.MID:
Expand All @@ -161,6 +168,8 @@ public class MapDocument {
default:
break;
}
outputWindow.draw();
//outputWindow.updateRaster();
break;
case EditMode.spritePlacement:
break;
Expand Down Expand Up @@ -188,4 +197,21 @@ public class MapDocument {
updateLayerList;
updateMaterialList;
}
public void tileMaterial_FlipHorizontal() {
selectedMappingElement.attributes.horizMirror = !selectedMappingElement.attributes.horizMirror;
}
public void tileMaterial_FlipVertical() {
selectedMappingElement.attributes.vertMirror = !selectedMappingElement.attributes.vertMirror;
}
public void tileMaterial_Select(wchar id) {
selectedMappingElement.tileID = id;
mode = EditMode.tilePlacement;

}
public void tileMaterial_PaletteUp() {
selectedMappingElement.paletteSel++;
}
public void tileMaterial_PaletteDown() {
selectedMappingElement.paletteSel--;
}
}
Loading

0 comments on commit d28c3cf

Please sign in to comment.