Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-03-07 00:25:15 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-03-07 00:25:15 +0300
commit08f306c81cb8015db59fe63ad1ef2c977751652e (patch)
tree94f656dbf98fba2bf3d47547d34c06131d0a88cf /source/blender/blenloader
parent3796abf092c9de4d43131dbce05102b126e14896 (diff)
Made python scripts save and load in the blend file so you can have the same scripts running when you open a blend file.
Also scripts will re-run on undo rather then closing. This is done by saving and loading the name of the script or textblock of the 'Script' datablock, connected to the ScriptSpace. This way when there is a name but the script dosnt run. Blender runs the script or text block if available.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/readfile.c33
-rw-r--r--source/blender/blenloader/intern/writefile.c13
2 files changed, 41 insertions, 5 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ecc11d080b5..a48ca83c381 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1422,6 +1422,17 @@ static void direct_link_brush(FileData *fd, Brush *brush)
brush->mtex[a]= newdataadr(fd, brush->mtex[a]);
}
+static void direct_link_script(FileData *fd, Script *script)
+{
+ script->id.us = 1;
+ script->py_draw =
+ script->py_event =
+ script->py_button =
+ script->py_browsercallback =
+ script->py_globaldict =
+ script->flags = NULL;
+}
+
/* ************ READ CurveMapping *************** */
/* cuma itself has been read! */
@@ -3726,9 +3737,13 @@ static void lib_link_screen(FileData *fd, Main *main)
}
else if(sl->spacetype==SPACE_SCRIPT) {
- SpaceScript *sc= (SpaceScript *)sl;
- sc->script = NULL;
+ SpaceScript *scpt= (SpaceScript *)sl;
+ /*sc->script = NULL; - 2.45 set to null, better re-run the script */
+ if (scpt->script) {
+ scpt->script = newlibadr(fd, sc->id.lib, scpt->script);
+ SCRIPT_SET_NULL(scpt->script);
+ }
}
else if(sl->spacetype==SPACE_OOPS) {
SpaceOops *so= (SpaceOops *)sl;
@@ -3899,9 +3914,14 @@ void lib_link_screen_restore(Main *newmain, Scene *curscene)
if(st->text==NULL) st->text= newmain->text.first;
}
else if(sl->spacetype==SPACE_SCRIPT) {
- SpaceScript *sc= (SpaceScript *)sl;
-
- sc->script = NULL;
+ SpaceScript *scpt= (SpaceScript *)sl;
+
+ scpt->script= restore_pointer_by_name(newmain, (ID *)scpt->script, 1);
+
+ /*sc->script = NULL; - 2.45 set to null, better re-run the script */
+ if (scpt->script) {
+ SCRIPT_SET_NULL(scpt->script);
+ }
}
else if(sl->spacetype==SPACE_OOPS) {
SpaceOops *so= (SpaceOops *)sl;
@@ -4359,6 +4379,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
case ID_PA:
direct_link_particlesettings(fd, (ParticleSettings*)id);
break;
+ case ID_SCRIPT:
+ direct_link_script(fd, (Script*)id);
+ break;
}
/*link direct data of ID properties*/
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 6fcb5312da8..a4c91d77f5e 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1955,6 +1955,18 @@ static void write_brushes(WriteData *wd, ListBase *idbase)
}
}
+static void write_scripts(WriteData *wd, ListBase *idbase)
+{
+ Script *script;
+
+ for(script=idbase->first; script; script= script->id.next) {
+ if(script->id.us>0 || wd->current) {
+ writestruct(wd, ID_SCRIPT, "Script", 1, script);
+ if (script->id.properties) IDP_WriteProperty(script->id.properties, wd);
+ }
+ }
+}
+
static void write_global(WriteData *wd)
{
FileGlobal fg;
@@ -2020,6 +2032,7 @@ static int write_file_handle(int handle, MemFile *compare, MemFile *current, int
write_particlesettings(wd, &G.main->particle);
write_nodetrees(wd, &G.main->nodetree);
write_brushes (wd, &G.main->brush);
+ write_scripts (wd, &G.main->script);
if(current==NULL)
write_libraries(wd, G.main->next); /* no library save in undo */