Skip to content

Commit

Permalink
updated wrendoc soo it can do multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
dollerama committed Sep 8, 2024
1 parent 444c83c commit f26f048
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 100 deletions.
Empty file added lilah_scripting.md
Empty file.
86 changes: 0 additions & 86 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,91 +2370,6 @@ impl Line {
}

impl Debug {
/*
pub fn draw_multi_line(points: Vec<Vec2>, thickness: f64, tint: Color) {
let line_mesh = crate::math::make_multi_line(&points, [thickness, 0.0]);
let mut vertex_buff = vec!();
for i in 0..line_mesh.0.len() {
vertex_buff.push(Vertex([line_mesh.0[i][0].x as f32, line_mesh.0[i][0].y as f32], [0.0, 0.0]));
vertex_buff.push(Vertex([line_mesh.0[i][1].x as f32, line_mesh.0[i][1].y as f32], [0.0, 0.0]));
vertex_buff.push(Vertex([line_mesh.0[i][2].x as f32, line_mesh.0[i][2].y as f32], [0.0, 0.0]));
}
let model = Mat4::IDENTITY;
let view = unsafe { *crate::math::VIEW_MATRIX };
let projection = unsafe { *crate::math::PROJECTION_MATRIX };
let mvp = projection * view * model;
unsafe {
crate::application::DEBUG_PROGRAM.as_mut().expect("program").apply();
let vao = VertexArray::new();
vao.bind();
let vbo = Buffer::new(gl::ARRAY_BUFFER);
vbo.set_data(vertex_buff.as_slice(), gl::DYNAMIC_DRAW);
let pos_attrib = crate::application::DEBUG_PROGRAM.as_ref().expect("program").get_attrib_location("position").expect("msg");
set_attribute!(vao, pos_attrib, Vertex::0, gl::FLOAT);
let mat_attr = gl::GetUniformLocation(
crate::application::DEBUG_PROGRAM.as_ref().expect("program").id,
CString::new("mvp").unwrap().as_ptr(),
);
gl::UniformMatrix4fv(mat_attr, 1, gl::FALSE as GLboolean, &mvp.to_cols_array()[0]);
let tint_attr = gl::GetUniformLocation(
crate::application::DEBUG_PROGRAM.as_ref().expect("program").id,
CString::new("tint").unwrap().as_ptr(),
);
gl::Uniform4f(
tint_attr,
tint.r,
tint.g,
tint.b,
tint.a,
);
let width_attr = gl::GetUniformLocation(
crate::application::DEBUG_PROGRAM.as_ref().expect("program").id,
CString::new("lineWidth").unwrap().as_ptr(),
);
gl::Uniform1d(width_attr, thickness);
let feather_attr = gl::GetUniformLocation(
crate::application::DEBUG_PROGRAM.as_ref().expect("program").id,
CString::new("feather").unwrap().as_ptr(),
);
gl::Uniform1d(feather_attr, 1.0);
let segments_attr = gl::GetUniformLocation(
crate::application::DEBUG_PROGRAM.as_ref().expect("program").id,
CString::new("segments").unwrap().as_ptr(),
);
let segments_len_attr = gl::GetUniformLocation(
crate::application::DEBUG_PROGRAM.as_ref().expect("program").id,
CString::new("segmentCount").unwrap().as_ptr(),
);
let flat_segments: Vec<GLfloat> = points.iter()
.flat_map(|v| vec![v.x as f32, v.y as f32])
.collect();
// Send the data to the shader
gl::Uniform2fv(segments_attr, points.len() as GLsizei, flat_segments.as_ptr());
gl::Uniform1i(segments_len_attr, points.len() as GLsizei);
gl::DrawArrays(gl::TRIANGLES, 0, line_mesh.1.len() as i32 * 3);
}
}
*/

pub fn draw_line(start: Vec2, end: Vec2, tint: Color) {
let model = Mat4::IDENTITY;
let view = unsafe { *crate::math::VIEW_MATRIX };
Expand Down Expand Up @@ -2757,7 +2672,6 @@ impl Component for Line {
impl Tickable<Sprite> for Rigidbody {
fn tick(&mut self, _: f64, d: &Sprite) {
let sprite_size = d.get_size();

self.bounds = Vec2::new(sprite_size.0 as f64, sprite_size.1 as f64);
}
}
Expand Down
67 changes: 55 additions & 12 deletions src/scripts/WrenDocs.pl
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#! /usr/bin/perl
use strict;
use File::Basename;
use warnings;
use Getopt::Long qw(GetOptions);
use Data::Dumper;

sub create_doc {
my $file = $_[0];
my $verbose = $_[1];

if($verbose) {
print " WrenDoc: starting ".basename($file)."\n";
}

my $source = do {
local $/ = undef;
open my $fh, "<", $file
or die "could not open $file: $!";
or die "WrenDoc: could not open $file: $!";
<$fh>;
};

Expand All @@ -22,7 +30,7 @@ sub create_doc {
my $prev_class = 0;
foreach(@new_source) {
my @ident_name = ($_ =~ /(?<=\{)(.*)(?=\})/g);

if(@ident_name) {
if($ident_name[0] eq "class") {
if(@all_in_class-0 == 0) {
Expand All @@ -46,9 +54,14 @@ sub create_doc {
push(@all_classes, "> - [$ident_sig](#$ident_sig_lc)");
@all_in_class = ();
$prev_class = 1;


if($verbose) {
print " ".basename($file).": class => ".$ident_sig."\n";
}
} elsif($ident_name[0] eq "module") {
my $ident_sig = ($_ =~ /(?<=(\}\s))(.*)/g)[1];
$module .= "# $ident_sig\n";
$module .= "$ident_sig";
$prev_class = 0;
} elsif($ident_name[0] eq "static setter" || $ident_name[0] eq "setter") {
my $ident_sig = ($_ =~ /(?<=(\}\s))(.*)/g)[1];
Expand All @@ -57,6 +70,11 @@ sub create_doc {

push(@all_in_class, "> - $ident_sig");
$prev_class = 0;


if($verbose) {
print " ".basename($file).": setter => ".$ident_sig."\n";
}
} else {
my $ident_sig = ($_ =~ /(?<=(\}\s))(.*)(?=(\s->))/g)[1];
my @words = ($ident_sig =~ /(\w+)/g);
Expand All @@ -76,32 +94,57 @@ sub create_doc {

push(@all_in_class, "> - $ident_sig");
$prev_class = 0;

if($verbose) {
print " ".basename($file).": ".$ident_name[0]." => ".$ident_sig."\n";
}
}
} else {
my @descr = ($_ =~ /[^\/].*/g);

$output .= "> $descr[0]\n";

$prev_class = 0;

if($verbose) {
print " ".basename($file).": description => ".@descr."\n";
}
}
}

my $result .= $module."### Classes\n".join("\n", @all_classes)."\n".$output_final;
my $result .= "# ".$module."\n### Classes\n".join("\n", @all_classes)."\n".$output_final;
if(@all_in_class-0 == 1) {
$result .= $output_header."@all_in_class"."\n".$output;
} elsif(@all_in_class-0 == 0) {
$result .= $output_header.$output;
} else {
$result .= $output_header.join("\n", @all_in_class)."\n".$output;
}
##print $result;
##close($fh);
return $result;
return ($module, $result);
}

my $filename = 'src/scripts/game.md';
unlink($filename);
open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!";
print $fh create_doc("src/scripts/game.wren");
my @inputs;
my $outputs;
my $verbose;
GetOptions('out|o=s' => \$outputs, 'in|i=s' => \@inputs, 'verbose|v' => \$verbose) or die 'Usage: $0 -in|o FILE.wren -out|o FILE.md -verbose|v\n';
@inputs = split(/,/,join(',',@inputs));

unlink($outputs);

my $file_header = "# ".basename($outputs, ".md")."\n"."### Modules\n";
my $file = "";

print "WrenDoc: building ".basename($outputs)."\n";

for my $i (0 .. $#inputs) {
my $in = $inputs[$i];
my @docu = create_doc($in, $verbose);
$file_header .= "> - [".$docu[0]."](#".$docu[0].")\n";
$file .= $docu[1];
print " WrenDoc: built doc => ".basename($in)."\n";
}

open(my $fh, '>>', $outputs) or die 'WrenDoc Err: Could not open file '.$outputs.' $!';
print $fh $file_header.$file;
close $fh;
print "done\n";
print "WrenDoc: Finished\n";
7 changes: 5 additions & 2 deletions src/scripts/io.wren
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import "meta" for Meta
import "random" for Random

///{module} io
///{class} Fs
foreign class Fs {
///{static method} read(file: String) -> null
foreign static read(file)
///{static method} write(file: String, content: String) -> null
foreign static write(file, content)
}

Expand Down Expand Up @@ -655,4 +658,4 @@ class JsonParser {

} //parse_map

} //JsonParser
} //JsonParser
14 changes: 14 additions & 0 deletions src/scripts/game.md → src/scripts/lilah_scripting.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# lilah_scripting
### Modules
> - [io](#io)
> - [Game](#Game)
# io
### Classes
> - [Fs](#fs)
## Fs
> - read(file: String)
> - write(file: String, content: String)
### ``read(file: String)``
static method with arity(1) and returns ``null``
### ``write(file: String, content: String)``
static method with arity(2) and returns ``null``
# Game
### Classes
> - [Behaviour](#behaviour)
Expand Down

0 comments on commit f26f048

Please sign in to comment.