Main Menu

Import txt into RexPaint - paste from win clipboard / import command

Started by gumix, February 29, 2016, 08:14:30 AM

Previous topic - Next topic

gumix

I have started some time ago bit odd project, pure console moon patrolish game.
So I have a lot of assets made (in notepad++) now I'd like to tune'em up using RexPaint.
(Mostly I'd like to add a bit of ansi colors)

How can I feed rex with my cookies?
Any chance for adding such feature?

gUmIx.



  Score:  1000000 Cars: 3                        Level: Champion [O-P]                                  Time: 44:47.98
                                                       __
                                                     _/__\_       _\__/_           *
                                                Y   (______)     (______)
                                                                   '  '

                                                          _\__/_        *
                *                                        (______)
                                                           '  '
                                            *              *                                              *
                                                                                           *
*           _                                               _            *
\           / \                               _             / \__
\__       /   \           _                 / \__         /     \                           _
. .\     /.   .\         / \__            _/     \       /       \                         / \
  . .\___/.     .\_      /     \         _/.      .\     /.       .\__         _           /   \             _
.. . ... . . ......\____/.     .\     __/.         .\   /..          .\  *   _/.\         /.   .\           / \
. . . ... . ..... ..\ . . .    ..\   /. . _________/.\_/_ ..        . .\____/.. .\     __/..     \      ___/   \_
. . . . .   .   . . \ . . . . . .\_/____/:. .       . .:\___. . . . . . . . . . .\___/. . . .   .\____/.  . . ..\______
_ . . . . . . . . . ./\ . . ______/:. .                  . .:\_____ . . . . . . . .._/..... . . . . ._/\. . . . ... . .
:\__ . . . . . . . ________/:. .                               . .:\____ . . . . . /.\________ . . . . .\_ . . . . . . .
. .:\_____________/:. . .                                           . .:\_________/.    . . .:\____ . . . . . . . . . .
        . . . . .                                                           . . .              . .:\_____. . . . . . . _
           . .                                                               . .                     . .:\____________/:
                                                                                                             . . .





        _____           __.______
~  ~~ >\  \_\         / _____ \_\_ \_\___/_/  _
  ~~  ~>/____/         \__  __   __\{:..    } (_)
                       /__\/\ \_/ /\ \_.. _/   _        _     _ . .       ..__                              __
   _    .       ,   _  \__/\_\/ \/_/__/   \__,/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\  _    _           /%\ __  _/%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\_       _/%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\_  _ /%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\/%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Kyzrati

Wow, what a coincidence. Someone wrote a script to do this just a couple days ago, and posted it here. Using it would require python, however. (And according to the comments there it's not perfect, but it's what they were using so maybe it got fixed and the comment wasn't updated? I don't know python, but my guess is they just read it in y-major order rather than .xp's x-major order, which is honestly kind of an odd thing on my part but that's how the engine works.)

Import-wise because REXPaint uses its own file browser, it would be rather complex to internally enable multiple import types in an accessible way, so the best approach here is to use an external program or script to convert to .xp. I don't have one myself, but maybe I could look into providing one if the python script won't work for you. I did plan to do this eventually, anyway, but I'm quite busy right now.

(Does anyone else have a program or script for this?)
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

gumix

THanks for posting this pyton script!

I feel more secure using c/c++ tool chains, below is a C func I've made.
Resulting file still needs to be gzipped by hand or some batch :)
Works at least for me.


#pragma pack(push,1)

struct Hdr
{
int ver;
int layers;
int width;
int height;
};

struct Cel
{
int code;
unsigned char fg[3];
unsigned char bg[3];
};

#pragma pack(pop)

int MakeXP(const char* txt_path, const char* xp_path)
{
FILE* f_txt=0;
fopen_s(&f_txt,txt_path,"rt");
if (!f_txt)
return -1;

char buf[1024];
int width = 0;
int height = 0;
int len = 0;
while (fgets(buf,1024,f_txt))
{
char* eol = strchr(buf,'\n');
height++;
if (!eol)
{
width = max(width, (int)strlen(buf));
// last line or line too long
// assume eof
break;
}
width = max(width, eol-buf);
}

fseek(f_txt,0,SEEK_SET);


FILE* f_xp=0;
fopen_s(&f_xp,xp_path,"wb");
if (!f_xp)
{
fclose(f_txt);
return -2;
}

Hdr hdr=
{
-1,
1,
width,
height
};

fwrite(&hdr,sizeof(Hdr),1,f_xp);

int cells = width*height;
Cel* image = (Cel*)malloc(cells*sizeof(Cel));
for (int i=0; i<cells; i++)
{
image[i].code=' ';
image[i].fg[0]=0;
image[i].fg[1]=0;
image[i].fg[2]=0;
image[i].bg[0]=255;
image[i].bg[1]=255;
image[i].bg[2]=255;
}

int y=0;
while (fgets(buf,1024,f_txt))
{
char* eol = strchr(buf,'\n');
int w = eol ? eol-buf : (int)strlen(buf);
for (int x=0; x<w; x++)
{
int i = x*height + y;
image[i].code=buf[x];
}

y++;

if (!eol)
break;
}

fwrite(image,sizeof(Cel)*cells,1,f_xp);

free(image);

fclose(f_xp);
fclose(f_txt);

return 0;
}



Kyzrati

Oh awesome, I'm glad you got something working then. I was thinking about it last night and I will at least add command line support to REXPaint itself for converting text files.
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Kyzrati

You've already probably got your own workflow based around your solution (or are done converting everything you needed converted, anyway :P), but I just added command line support for importing .txt images to REXPaint 1.02.
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

gumix

There are no txt files in my workflow since initial move, hurray! ... but I'm sure it is great for new users when they move to xp files too.

Kyzrati

I figured you'd already batch-processed yours since you came up with your own solution :). But thanks for spurring me to make the addition.
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Suudy

Sorry for the necro-thread.  But I found Kyzrati's Gist and noted when I used it the image was rotated.  I fixed the rotation issue, and went a little farther to directly export a compressed file and to accept command line arguments.

https://gist.github.com/Suudy/fca725e2c8529b3e2e498b9ef11c40eb

Hopefully this will be useful to some.

Kyzrati

Ah thanks, Suudy, not sure which Gist you mean, since I don't have any, but perhaps you mean gumix's here since this is the thread you dropped it in? Or did you mean mtvee's from the Resources page since theirs was in Python as well?

In any case, thank you and I can add this to the Resources page as well :)
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Suudy

Quote from: Kyzrati on August 05, 2020, 02:56:20 PM
Ah thanks, Suudy, not sure which Gist you mean, since I don't have any, but perhaps you mean gumix's here since this is the thread you dropped it in? Or did you mean mtvee's from the Resources page since theirs was in Python as well?
Doh!  Sorry.  I misread that.  Yes, mtvee's, from which I forked.

Kyzrati

Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon