Grid Sage Forums

REXPaint => Everything REXPaint => Topic started by: gumix on February 29, 2016, 08:14:30 AM

Title: Import txt into RexPaint - paste from win clipboard / import command
Post by: gumix on February 29, 2016, 08:14:30 AM
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   (______)     (______)
                                                                   '  '

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





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


Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Kyzrati on February 29, 2016, 08:56:58 AM
Wow, what a coincidence. Someone wrote a script to do this just a couple days ago, and posted it here (http://pastebin.com/ci9bWx1u). 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?)
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: gumix on February 29, 2016, 09:59:16 AM
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.

Code: [Select]
#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;
}

Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Kyzrati on March 01, 2016, 02:46:52 AM
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.
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Kyzrati on May 01, 2016, 10:59:58 PM
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 (http://www.gridsagegames.com/forums/index.php?topic=463.0).
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: gumix on May 04, 2016, 06:19:22 AM
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.
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Kyzrati on May 04, 2016, 06:43:32 AM
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.
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Suudy on August 05, 2020, 12:59:27 PM
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.
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: 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?

In any case, thank you and I can add this to the Resources page as well :)
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Suudy on August 06, 2020, 09:16:46 AM
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.
Title: Re: Import txt into RexPaint - paste from win clipboard / import command
Post by: Kyzrati on August 06, 2020, 08:35:18 PM
Gotcha, thanks for the info :)