Oni Central Forum

A forum for the Oni community

You are not logged in.

#126 01/25/08 14:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, I will work on this.  Oy vey, I think I need to start an Oni Projects To-Do list just to keep track of the things I volunteer for every day smile

It might be fairly simple to do, though (as if anything is simple in programming!).  rsync can be set to generate a list of files to sync instead of actually syncing them, so maybe I can use it to make things easier.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#127 01/25/08 16:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Neo has posted OniSplit 0.8.11 which should fix the problem.  Will let you know...

EDIT, OniSplit almost works, the image gets flipped vertically when imported to the game.  Neo should have a fix soon.  In the meantime, you could always flip the image vertically and then import.

Last edited by EdT (01/26/08 00:01)

Offline

#128 01/26/08 00:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Ignore this post, I think I found the answer to my question.

Last edited by EdT (01/26/08 01:01)

Offline

#129 01/26/08 12:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen and U479:

I need help in choosing a file and then moving it to a folder relative to the location of OniSplit.  All the shell scripts commands are relative to OniSplit.  I can duplicate the file and move it to an absolute location, but this not work on all machines since the path to the Oni folder can vary.

Any suggestions?

Offline

#130 01/26/08 14:01

Ultimatum479
Member
Registered: 08/29/07

Re: Mac programming

Wait, rephrase that. You want to move a file relative to the location of a certain program, that's all? Why not display a dialog that allows the user to find OniSplit? Let's hope people aren't _that_ incompetent that it proves difficult for them to do. ^_^


Work in progress...

Offline

#131 01/26/08 15:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Well I want to make it easy to create TXMP.oni files from textures created as .tga files. As foolproof as possible.
The command in OniSplit is:
mono onisplit.exe -create:txmp  destination_directory  -format:bgr32 -genmipmaps  source_image_file

So I need the source_image_file in a location relative to onisplit so I can run the command.

My idea is for the user to select the file they want to convert to TXMP.oni file. The program will copy it to a fixed location, then run the onisplit command to create.  Next move the .oni to the level0_Final folder, so that later they can recombine level0, so the new textures will appear in the game.  I want to simplify the process as much as possible so the user can focus on making the textures, not struggling how to import it to the game. 

Currently OUP does this seamlessly, the old OniTools could do the same. The user just selects which TXMP they want to replace and the file for it, then the programs does the rest.

So I'm working in xCode trying to make a similar program using OniSplit.

Here's an example of texture replacement:

attachment.php?item=209&download=1

Last edited by EdT (01/26/08 15:01)

Offline

#132 01/27/08 01:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Why won't this work?

tell application "Finder"
    get POSIX path of (container of (path to me) as text)
    set new_path to result
    
end tell

set myFile to choose file with prompt "Choose file"
tell application "Finder"
    duplicate myFile to new_path
end tell

Offline

#133 01/27/08 11:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

OK, I got the solution from an Applescript forum.

tell application "Finder"
           set myFile to (choose file with prompt "Choose file")
           set myName to name of myFile
           duplicate myFile to container of (path to me) with replacing
       end tell
   
       set cmd_string_create to "cd " & (safe_path as string) & "edition/install; mono onisplit.exe -create:txmp ../../ModTXMP -format:bgr32 -genmipmaps " & " ../../" & myName
       do shell script cmd_string_create

This allows the user to select the image file and the converts it to a TXMP.oni file and puts it in the ModTXMP folder.

Its getting there...

Offline

#134 01/27/08 17:01

Ultimatum479
Member
Registered: 08/29/07

Re: Mac programming

Yeah, you mixed it up. You tried to make AppleScript use the POSIX path in your version there; the whole point of the "POSIX path of" command is to make things work with the Terminal because AppleScript _doesn't_ use the POSIX path.


Work in progress...

Offline

#135 01/27/08 17:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

One question, how can I duplicate the file to a specific folder inside Oni?
ie: Oni/ModTXMP
My current script will only duplicate the file to the Oni folder.

EDIT:
Got the answer:
duplicate myFile to folder ((container of (path to me) as text) & "ModTXMP:")

Last edited by EdT (01/27/08 23:01)

Offline

#136 01/28/08 10:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Yep, that's it.

Over the weekend, I wrote about 50% of a script that looks at files in TXMPfiles/Modified, and if there's something there that's newer than the file with the same name in level0_Final, it moves the original file from level0_Final to TXMPfiles/Backup and copies the modded file into level0_Final.  It preserves the original Oni TXMP in Backup no matter how many times a new mod is copied into level0.  Does that sound like something that would be useful?  It would need to be integrated with your code that converts an image to .oni.  It could also support a "Reset TXMPs" option that replaces the modded .oni files in level0 with the originals from backup.  Your modded TXMPs would remain unharmed in Modified.

I am a little confused about formats, actually.  EdT, what file format are we using to import/export TXMPs?  I got .tgas when I used the Export TXMP button in AE Tools.  Is that not the format we should be using to convert back to Oni's format?


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#137 01/28/08 10:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

If you look in your levelO folder and search for TXMP you will find all those files are .oni files.  This is the format used by OniSplit.

On the Mac, OniSplit can export/import the TXMP.oni files as .tga image files.  Thus the files in TXMPfiles folder are the image files, that we can update in Photoshop, etc.  Thus the new/replacement textures has to be in the .tga image format to be correctly imported and converted back to the .oni files.

There is an issue with mono that causes problems if we try to import/export in other formats such as .bmp or .png

Be sure to get the latest version of OniSplit at Neo's page: http://wiki.oni2.net/User_talk:Neo

Regarding the AETools, so far, all I've done is the ability to choose a single .tga image file and convert it to a TXMP.oni file and a batch process to take a folder of .tga image files and convert all of them to TXMP.oni files.

Last edited by EdT (01/28/08 10:01)

Offline

#138 01/28/08 10:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Thanks for the clarification on formats.

EdT wrote:

Regarding the AETools, so far, all I've done is the ability to choose a single .tga image file and convert it to a TXMP.oni file and a batch process to take a folder of .tga image files and convert all of them to TXMP.oni files.

That code could be integrated with mine, which only manages the files (comparing modification dates and names to judge which TXMPs are to be replaced in level0).  It sounds like it would be useful, then.

On a separate note, Ed, I noticed that AE Tools' dialogs pop up in the background when the Terminal is called up to run something and then finishes.  You then have to click back to the AE Tools to find the dialog.  Was that intentional?  Originally there was code to switch back to the Installer before showing those messages.  All you need to do is add "tell application "[name here]" activate" before any display dialog lines and I think the Tools will come up properly.  I just don't think we should call up a new (and for some, scary) command line and then leave them in it when the process is done.

Last edited by Iritscen (01/28/08 10:01)


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#139 01/28/08 12:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritiscen: I'll be sure to add the line to get AE Tools working right.  I may have "lost" that code during all my trial and errors :-)

Here's what I have done so far, I still need to finetune them

1) Convert single image file to .oni file: (I still need to add code to make the "TempTXMP" folder, if it is not there already)

tell application "Finder"
            set myFile to (choose file with prompt "Choose file")
            set myName to name of myFile
            duplicate myFile to folder ((container of (path to me) as text) & "TempTXMP:") with replacing
        end tell
        
        display dialog "You will now create a single TXMP.oni file.  They will be placed in the folder ModTXMP"
        set cmd_string_create to "cd " & (safe_path as string) & "edition/install; mono onisplit.exe -create:txmp ../../ModTXMP -format:bgr32 -genmipmaps " & " ../../TempTXMP/" & myName
        do shell script cmd_string_create

Batch processing:

tell application "Finder"
            set myFolder to choose folder with prompt "Choose folder of .tga images"
            set newFolder to duplicate myFolder to container of (path to me) with replacing
            set myNameTemp to name of myFolder
            set myName to quoted form of myNameTemp
        end tell
        set cmd_string_create to "cd " & (safe_path as string) & "edition/install; mono onisplit.exe -create:txmp ../../ModTXMP -format:bgr32 -genmipmaps ../../" & myName & "/*.tga"
        do shell script cmd_string_create

So the updated TXMP.oni files will be placed in a folder called ModTXMP.  So that's the folder, you will be comparing with the original TXMP.oni files in the level0_Final folder.  Does that make sense?

Funny thing, the final code looks simple, but it took me hours to get the right Applescript syntax.  I had to ask for help numerous times on an Applescript forum.  But I'm learning... smile

Last edited by EdT (01/28/08 12:01)

Offline

#140 01/28/08 12:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Yes, AppleScript syntax is tricky because it pretends to be adaptable ("natural language") and then gets its panties in a wad because you didn't say the magic word in one place.  Sometimes I get an error because I didn't declare a variable in advance even though in general you don't have to declare.

And yes, I think your post makes sense.  Just to be sure:
- The TempTXMP folder is where the modder puts his .tga files to be converted to the TXMP format.
- The ModTXMP folder is where the script puts the .tgas when they are converted to TXMPs.

I will integrate that with my code to ensure that the conversion and replacement process is "smart" (doing only what it needs to, not overwriting original files, making sure folders are in existence first).


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#141 01/28/08 14:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

- The TempTXMP folder is where the modder puts his .tga files to be converted to the TXMP format.

The modder can keep their files wherever they want.  I just copy over the files to the TempTXMP folder so I can convert them to the .oni files.  I needed a known location to run the shell script.  Same with the batch process, I copy the folder of files, process them and then will delete the copied folder.  Otherwise, the Oni will get crowded with all sorts of folders.

Offline

#142 01/28/08 15:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, but there should remain somewhere the original copies of the modded TXMPs, right?  We don't want the only copies to be the .onis in level0, do we?

I just copy over the files to the TempTXMP folder

It sounds like right now you are expecting that the modder will put files into a folder that later gets deleted by the script.  Even if he's warned that will happen, it makes me a little uncomfortable.  I don't want to get railed at because we deleted a folder with the modder's only copy of the pre-.oni format modded TXMP.

If we follow my notion of permanently keeping the modded TXMPs in .tga format in a Modified folder (or ModTXMP or whatever you want to call it), then the modder never has to worry about losing any version of the TXMP -- the original, in .oni format, is held in Backup, the modded .tga is held in Modified, and the .tga-converted-to-.oni is held in level0.  The only file management that the modder will do is replacing a .tga in ModTXMP with a newer .tga if he needs to tweak a texture.

Just to be clear, I agree that the Oni game folder is getting crowded, but I am proposing to place the above folders inside /TXMPfiles.  So it's:

Oni
--Oni.app
--GameDataFolder
----level0_Final (holds only .oni files, with mods replacing originals)
--AE Tools
--etc.
--TXMPfiles
----Backup (keeps original .oni files)
----Modified (keeps latest copy of each modded .tga)


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#143 01/28/08 15:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

My concept was the modder keeps his modded TXMP wherever he/she wants and that AE Tools would only work on a copy in the Oni Folder.  This is how my scripts currently works. But if you think we should also keep a backup copy of them, that will be fine too.

Offline

#144 01/28/08 22:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen, U479 and any other Mac coder lurking out there :-)

Here is the latest xCode for AE Tools, I've added the create TXMP feature, but for now the TXMP.oni files are in the ModTXMP folder.
I have not figured out how to copy files from one folder to another so the feature to backup the modded .tga is not there.
So if either one of you can take care of it, that will be great.

Also, the UI is getting crowded, if you have any good ideas on improving please do so.

http://edt.oni2.net/AE/AETools_xCode.zip

Offline

#145 01/29/08 09:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, I won't have time tonight, but I will give it my full attention tomorrow night.  I also got nothing done the last two nights because of long-distance calls from friends.  C'est la vie.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#146 01/29/08 15:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

FYI, I think I figured out the copy files to folder command. smile

Offline

#147 01/29/08 17:01

Ultimatum479
Member
Registered: 08/29/07

Re: Mac programming

You could do it with the Terminal if you really needed to do so, anyway.


Work in progress...

Offline

#148 01/30/08 12:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen: I got the workflow pretty much figured out.  Where do you want the modded TXMP.oni files to go? Then you can tie in that folder with your code.

I went with your suggestion about organizing the folders.
--TXMPfiles
----Backup
----Modified
----Temp (currently where the modded TXMP.oni files are located, but it can be anywhere and any name you want)
----Work (This is the folder where the image files are converted to TXMP.oni files, then they are moved to the right folder. I realized that if I put the images directly into the Modified folder, OniSplit will generate TXMP.oni files on ALL the images in the Modified folder.  But by putting them first in the Work folder, only those images are converted.)

Question: Does Applescript have something similar to functions, routines?  For example, that bit of code to bring AETools to the front, would work nice as a function.

Last edited by EdT (01/30/08 12:01)

Offline

#149 01/30/08 12:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

EdT wrote:

Iritscen: I got the workflow pretty much figured out.  Where do you want the modded TXMP.oni files to go? Then you can tie in that folder with your code.

I went with your suggestion about organizing the folders.
--TXMPfiles
----Backup
----Modified
----Temp (currently where the modded TXMP.oni files are located, but it can be anywhere and any name you want)
----Work (This is the folder where the image files are converted to TXMP.oni files, then they are moved to the right folder. I realized that if I put the images directly into the Modified folder, OniSplit will generate TXMP.oni files on ALL the images in the Modified folder.  But by putting them first in the Work folder, only those images are converted.)

If we incorporate my code, we won't even need a Temp folder.  See, my code (which already works, btw, it's just that I never finished the rest of the framework -- it looks like you've handled everything else now, though, so I should just post what I have) looks at each file in Modified and checks to see if it's newer than the same file that ends in .oni in level0.  So, you as the modder only have to maintain the Modified folder with the latest versions of the TXMPs, replacing whatever you feel like if you're still refining some of them, and then you just tell the Tools "Okay, run the replacement function again", and it only converts/copies what is changed.

The conversions that OniSplit makes can also go directly to level0, but perhaps for debugging purposes it's safer to use a folder like Temp for that.

So the workflow for the script would be:
1. Check files in Modified against level0.
2. Make list of newly changed files.
3. Convert these files, sending them to Temp.
4. Move files with those names from level0 to Backup unless they already exist there (we want to keep the first backup, as that will be the original Oni file). Otherwise delete them, as they are newer than the backed up versions and therefore not the original data.
5. Move all .oni files in Temp to level0 now that there won't be any naming conflicts.

That's very similar to what you're suggesting.  Does it agree with you?

Also, I strongly suggest building a dialog that shows the user what actions will be taken before taking them, at least until we are totally confident with the code.  I can post code for that tomorrow too, it's partly written already.  It's just a matter of maintaining lists.

Question: Does Applescript have something similar to functions, routines?  For example, that bit of code to bring AETools to the front, would work nice as a function.

When you see "my make_path_UNIX_safe", that's calling the function "make_path_UNIX_safe".  By the way, I rewrote that function too, so it is actually useful now.  Instead of only escaping spaces, it now handles the entire process of converting a Mac-format path to a Unix path, making POSIX path obsolete, and handles much more than spaces.  Must post it tomorrow.

But the code to bring up AE Tools is only one line, or can be written as one line, so I don't think it's worth making a function for it.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#150 01/30/08 12:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

So the workflow for the script would be:
1. Check files in Modified against level0.
2. Make list of newly changed files.
3. Convert these files, sending them to Temp.

Well, my workflow, already ends up at Step 3. so we may be able to skip 1&2, since only the latest modified TXMP.oni files are in the Temp folder.

Then the rest of the steps is up to your code.

Offline

Board footer

Powered by FluxBB