Grid Sage Forums

Grid Sage Forums

  • April 27, 2017, 01:05:58 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Alpha Access LAUNCHED! Buy Now! (Trailer)

Author Topic: Import txt into RexPaint - paste from win clipboard / import command  (Read 1167 times)

gumix

  • Derelict
  • **
  • Posts: 64
    • View Profile

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   (______)     (______)
                                                                   '  '

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





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


Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 2307
    • View Profile
    • Cogmind
Re: Import txt into RexPaint - paste from win clipboard / import command
« Reply #1 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. 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?)
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames

gumix

  • Derelict
  • **
  • Posts: 64
    • View Profile
Re: Import txt into RexPaint - paste from win clipboard / import command
« Reply #2 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;
}

« Last Edit: February 29, 2016, 10:27:26 AM by gumix »
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 2307
    • View Profile
    • Cogmind
Re: Import txt into RexPaint - paste from win clipboard / import command
« Reply #3 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.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 2307
    • View Profile
    • Cogmind

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.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames

gumix

  • Derelict
  • **
  • Posts: 64
    • View Profile

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.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 2307
    • View Profile
    • Cogmind

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.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames