diff --git a/src/data/statistics.cpp b/src/data/statistics.cpp index 11c6f2ef..742ff26f 100644 --- a/src/data/statistics.cpp +++ b/src/data/statistics.cpp @@ -21,14 +21,20 @@ StatsDimension::StatsDimension(const Field& field) , description (field.description) , icon_filename(field.icon_filename) { - // init script! + // initialize script, card.{field_name} + Script& s = script.getScript(); + s.addInstruction(I_GET_VAR, string_to_variable(_("card"))); + s.addInstruction(I_MEMBER_C, field.name); + s.addInstruction(I_RET); } IMPLEMENT_REFLECTION(StatsDimension) { - REFLECT(name); - REFLECT(description); - REFLECT_N("icon", icon_filename); - REFLECT(script); + if (!automatic) { + REFLECT(name); + REFLECT(description); + REFLECT_N("icon", icon_filename); + REFLECT(script); + } } // ----------------------------------------------------------------------------- : Statistics category @@ -53,9 +59,11 @@ IMPLEMENT_REFLECTION_ENUM(GraphType) { } IMPLEMENT_REFLECTION(StatsCategory) { - REFLECT(name); - REFLECT(description); - REFLECT_N("icon", icon_filename); - REFLECT(type); - REFLECT(dimensions); + if (!automatic) { + REFLECT(name); + REFLECT(description); + REFLECT_N("icon", icon_filename); + REFLECT(type); + REFLECT(dimensions); + } } diff --git a/src/data/symbol_font.cpp b/src/data/symbol_font.cpp index b0c4872a..eb82887a 100644 --- a/src/data/symbol_font.cpp +++ b/src/data/symbol_font.cpp @@ -210,19 +210,19 @@ void SymbolFont::drawWithText(RotatedDC& dc, Context& ctx, const RealRect& rect, if (def) { Bitmap bmp = def->getBitmap(ctx, *this, dc.trS(font_size)); // align symbol - sym_rect.size = dc.trInvS(RealSize(bmp.GetWidth(), bmp.GetHeight())); - sym_rect.position = align_in_rect(align, sym_rect.size, rect); + sym_rect.size() = dc.trInvS(RealSize(bmp.GetWidth(), bmp.GetHeight())); + sym_rect.position() = align_in_rect(align, sym_rect.size(), rect); // draw - dc.DrawBitmap(bmp, sym_rect.position); + dc.DrawBitmap(bmp, sym_rect.position()); } // 2. draw text if (!text_font) return; // subtract margins from size - sym_rect.position.x += text_margin_left; - sym_rect.position.y += text_margin_top; - sym_rect.size.width -= text_margin_left + text_margin_right; - sym_rect.size.height -= text_margin_top + text_margin_bottom; + sym_rect.x += text_margin_left; + sym_rect.y += text_margin_top; + sym_rect.width -= text_margin_left + text_margin_right; + sym_rect.height -= text_margin_top + text_margin_bottom; // setup text, shrink it double size = text_font->size; // TODO : incorporate shrink factor? RealSize ts; @@ -230,7 +230,7 @@ void SymbolFont::drawWithText(RotatedDC& dc, Context& ctx, const RealRect& rect, if (size <= 0) return; // text too small dc.SetFont(text_font->font, size); ts = dc.GetTextExtent(text); - if (ts.width <= sym_rect.size.width && ts.height <= sym_rect.size.height) { + if (ts.width <= sym_rect.width && ts.height <= sym_rect.height) { break; // text fits } else { // text doesn't fit diff --git a/src/gfx/gfx.hpp b/src/gfx/gfx.hpp index 6e69e9bf..7b1445c4 100644 --- a/src/gfx/gfx.hpp +++ b/src/gfx/gfx.hpp @@ -36,6 +36,16 @@ enum PreserveAspect /// Resample an image, but preserve the aspect ratio by adding a transparent border around the output if needed. void resample_preserve_aspect(const Image& img_in, Image& img_out); +/// Draw text by first drawing it using a larger font and then downsampling it +/** optionally rotated by an angle. + * rect = rectangle to draw in + * (wc,hc) = the corner where drawing should begin, (0,0) for top-left, (1,1) for bottom-right + */ +void draw_resampled_text(DC& dc, const RealRect& rect, int wc, int hc, int angle, const String& text); + +// scaling factor to use when drawing resampled text +extern const int text_scaling; + // ----------------------------------------------------------------------------- : Image rotation /// Rotates an image counter clockwise diff --git a/src/gfx/resample_text.cpp b/src/gfx/resample_text.cpp new file mode 100644 index 00000000..7ec9a915 --- /dev/null +++ b/src/gfx/resample_text.cpp @@ -0,0 +1,92 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include // clearDC_black + +// ----------------------------------------------------------------------------- : Resampled text + +// scaling factor to use when drawing resampled text +const int text_scaling = 4; + +// Fills an image with the specified color +void fill_image(Image& image, const Color& color) { + Byte* pos = image.GetData(); + Byte* end = image.GetData() + image.GetWidth() * image.GetHeight() * 3; + while (pos != end) { + pos[0] = color.Red(); + pos[1] = color.Green(); + pos[2] = color.Blue(); + pos += 3; + } +} + +// Downsamples the red channel of the input image to the alpha channel of the output image +// img_in must be text_scaling times as large as img_out +void downsample_to_alpha(Image& img_in, Image& img_out) { + assert(img_in.GetWidth() == img_out.GetWidth() * text_scaling); + assert(img_in.GetHeight() == img_out.GetHeight() * text_scaling); + + // scale in the x direction, this overwrites parts of the input image + Byte* in = img_in.GetData(); + Byte* out = img_in.GetData(); + int count = img_out.GetWidth() * img_in.GetHeight(); + for (int i = 0 ; i < count ; ++i) { + int total = 0; + for (int j = 0 ; j < text_scaling ; ++j) { + total += in[3 * (j + text_scaling * i)]; + } + out[i] = total / text_scaling; + } + + // now scale in the y direction, and write to the output alpha + img_out.InitAlpha(); + out = img_out.GetAlpha(); + int line_size = img_out.GetWidth(); + for (int y = 0 ; y < img_out.GetHeight() ; ++y) { + for (int x = 0 ; x < img_out.GetWidth() ; ++x) { + int total = 0; + for (int j = 0 ; j < text_scaling ; ++j) { + total += in[x + line_size * (j + text_scaling * y)]; + } + out[x + line_size * y] = total / text_scaling; + } + } +} + +// Draw text by first drawing it using a larger font and then downsampling it +// optionally rotated by an angle +// (w2,h2) = size of text +// (wc,hc) = the corner where drawing should begin, (0,0) for top-left, (1,1) for bottom-right +void draw_resampled_text(DC& dc, const RealRect& rect, int wc, int hc, int angle, const String& text) { + // enlarge slightly + int w = rect.width + 1, h = rect.height + 1; + // determine sub-pixel position + int xi = rect.x, yi = rect.y; + int xsub = text_scaling * (rect.x - xi), ysub = text_scaling * (rect.y - yi); + // draw text + Bitmap buffer(w * text_scaling, h * text_scaling, 24); // should be initialized to black + wxMemoryDC mdc; + mdc.SelectObject(buffer); + clearDC_black(mdc); + // now draw the text + mdc.SetFont(dc.GetFont()); + mdc.SetTextForeground(*wxWHITE); + mdc.DrawRotatedText(text, wc * w * text_scaling + xsub, hc * h * text_scaling + ysub, angle); + // get image + mdc.SelectObject(wxNullBitmap); + Image img_large = buffer.ConvertToImage(); + // step 2. sample down + Image img_small(w, h, false); + fill_image(img_small, dc.GetTextForeground()); + downsample_to_alpha(img_large, img_small); + // step 3. draw to dc + dc.DrawBitmap(img_small, xi + wc * (rect.width - w), yi + hc * (rect.height - h)); +} + diff --git a/src/gui/control/graph.cpp b/src/gui/control/graph.cpp index 486b62e7..0efdac41 100644 --- a/src/gui/control/graph.cpp +++ b/src/gui/control/graph.cpp @@ -7,6 +7,7 @@ // ----------------------------------------------------------------------------- : Includes #include +#include #include #include @@ -86,8 +87,11 @@ GraphData::GraphData(const GraphDataPre& d) // ----------------------------------------------------------------------------- : Graph1D -bool Graph1D::findItem(const RealPoint& pos, vector& out) const { - int i = findItem(pos); +void Graph1D::draw(RotatedDC& dc, const vector& current) const { + draw(dc, axis < current.size() ? current.at(axis) : -1); +} +bool Graph1D::findItem(const RealPoint& pos, const RealRect& rect, vector& out) const { + int i = findItem(pos, rect); if (i == -1) return false; else { out.clear(); @@ -99,11 +103,86 @@ bool Graph1D::findItem(const RealPoint& pos, vector& out) const { // ----------------------------------------------------------------------------- : Bar Graph -void BarGraph::draw(RotatedDC& dc) const { - // TODO +void BarGraph::draw(RotatedDC& dc, int current) const { + if (!data) return; + // Rectangle for bars + RealRect rect = dc.getInternalRect().move(15, 5, -20, -20); + // Bar sizes + GraphAxis& axis = axis_data(); + int count = int(axis.groups.size()); + double width_space = rect.width / count; // including spacing + double width = width_space / 5 * 4; + double space = width_space / 5; + double step_height = rect.height / axis.max; // multiplier for bar height + // Highlight current column + Color bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); + if (current >= 0) { + double x = rect.x + width_space * current; + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(lerp(bg, axis.groups[current].color, 0.25)); + dc.DrawRectangle(RealRect(x + space / 2 - 5, rect.bottom() + 1 + 15, + width + 10, -step_height * axis.groups[current].size - 1.999 - 20)); + dc.SetBrush(lerp(bg, axis.groups[current].color, 0.5)); + dc.DrawRectangle(RealRect(x + space / 2 - 2, rect.bottom() + 1 + 2, + width + 4, -step_height * axis.groups[current].size - 1.999 - 4)); + } + // How many labels and lines to draw? + dc.SetFont(*wxNORMAL_FONT); + UInt label_step = max(1.0, dc.GetCharHeight() / step_height); + // Draw backlines (horizontal) and value labels + dc.SetPen(lerp(bg, fg, 0.5)); + for (UInt i = 0 ; i <= axis.max ; ++i) { + if (i % label_step == 0) { + int y = rect.bottom() - i * step_height; + dc.DrawLine(RealPoint(rect.left() - 2, y), RealPoint(rect.right(), y)); + // draw label, aligned middle right + String label; label << i; + RealSize text_size = dc.GetTextExtent(label); + dc.DrawText(label, align_in_rect(ALIGN_MIDDLE_RIGHT, text_size, RealRect(rect.x - 4, y, 0, 0))); + } + } + // Draw axes + dc.SetPen(fg); + dc.DrawLine(rect.bottomLeft() - RealSize(2,0), rect.bottomRight()); + dc.DrawLine(rect.topLeft(), rect.bottomLeft()); + // Draw bars + double x = rect.x; + FOR_EACH_CONST(g, axis.groups) { + // draw bar + dc.SetBrush(g.color); + dc.DrawRectangle(RealRect(x + space / 2, rect.bottom() + 1, width, -step_height * g.size - 1.999)); + // draw label, aligned bottom center + RealSize text_size = dc.GetTextExtent(g.name); + dc.SetClippingRegion(RealRect(x + 2, rect.bottom(), width_space - 4, text_size.height)); + dc.DrawText(g.name, align_in_rect(ALIGN_TOP_CENTER, text_size, RealRect(x, rect.bottom() + 3, width_space, 0))); + dc.DestroyClippingRegion(); + x += width_space; + } } -int BarGraph::findItem(const RealPoint& pos) const { - return -1; // TODO +int BarGraph::findItem(const RealPoint& pos, const RealRect& rect1) const { + if (!data) return -1; + // Rectangle for bars + RealRect rect = rect1.move(15, 5, -20, -20); + // Bar sizes + GraphAxis& axis = axis_data(); + int count = int(axis.groups.size()); + double width_space = rect.width / count; // including spacing + double space = width_space / 5; + // Find column in which this point could be located + int col = (pos.x - rect.x) / width_space; + double in_col = (pos.x - rect.x) - col * width_space; + if (in_col < space / 2 || // left + in_col > width_space - space / 2 || // right + pos.y > rect.bottom() || // below + pos.y < rect.top()) { // above + return -1; + } + if (col < 0 || (size_t)col >= axis_data().groups.size()) { + return -1; + } else { + return col; + } } // ----------------------------------------------------------------------------- : Pie Graph @@ -136,7 +215,7 @@ void GraphControl::onPaint(wxPaintEvent&) { rdc.SetPen(*wxTRANSPARENT_PEN); rdc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); rdc.DrawRectangle(rdc.getInternalRect()); - if (graph) graph->draw(rdc); + if (graph) graph->draw(rdc, current_item); } void GraphControl::onSize(wxSizeEvent&) { @@ -146,7 +225,9 @@ void GraphControl::onSize(wxSizeEvent&) { void GraphControl::onMouseDown(wxMouseEvent& ev) { if (!graph) return; wxSize cs = GetClientSize(); - graph->findItem(RealPoint((double)ev.GetX()/cs.GetWidth(), (double)ev.GetY()/cs.GetHeight()), current_item); + if (graph->findItem(RealPoint(ev.GetX(), ev.GetY()), RealRect(RealPoint(0,0),cs), current_item)) { + Refresh(false); + } } BEGIN_EVENT_TABLE(GraphControl, wxControl) diff --git a/src/gui/control/graph.hpp b/src/gui/control/graph.hpp index 0bd9a5cf..f2a46067 100644 --- a/src/gui/control/graph.hpp +++ b/src/gui/control/graph.hpp @@ -83,9 +83,9 @@ class GraphData { class Graph { public: /// Draw this graph, filling the internalRect() of the dc. - virtual void draw(RotatedDC& dc) const = 0; - /// Find the item at the given position, position is normalized to [0..1) - virtual bool findItem(const RealPoint& pos, vector& out) const { return false; } + virtual void draw(RotatedDC& dc, const vector& current) const = 0; + /// Find the item at the given position, the rectangle gives the screen size + virtual bool findItem(const RealPoint& pos, const RealRect& rect, vector& out) const { return false; } /// Change the data virtual void setData(const GraphDataP& d) { data = d; } @@ -98,19 +98,22 @@ class Graph { class Graph1D : public Graph { public: inline Graph1D(size_t axis) : axis(axis) {} - virtual bool findItem(const RealPoint& pos, vector& out) const; + virtual void draw(RotatedDC& dc, const vector& current) const; + virtual bool findItem(const RealPoint& pos, const RealRect& rect, vector& out) const; protected: size_t axis; /// Find an item, return the position along the axis, or -1 if not found - virtual int findItem(const RealPoint& pos) const = 0; + virtual int findItem(const RealPoint& pos, const RealRect& rect) const = 0; + virtual void draw(RotatedDC& dc, int current) const = 0; + inline GraphAxis& axis_data() const { return *data->axes.at(axis); } }; /// A bar graph class BarGraph : public Graph1D { public: inline BarGraph(size_t axis) : Graph1D(axis) {} - virtual void draw(RotatedDC& dc) const; - virtual int findItem(const RealPoint& pos) const; + virtual void draw(RotatedDC& dc, int current) const; + virtual int findItem(const RealPoint& pos, const RealRect& rect) const; }; // TODO @@ -121,16 +124,16 @@ class BarGraph : public Graph1D { class PieGraph : public Graph1D { public: inline PieGraph(size_t axis) : Graph1D(axis) {} - virtual void draw(RotatedDC& dc) const; - virtual int findItem(const RealPoint& pos) const; + virtual void draw(RotatedDC& dc, int current) const; + virtual int findItem(const RealPoint& pos, const RealRect& rect) const; }; /// The legend, used for pie graphs class GraphLegend : public Graph1D { public: inline GraphLegend(size_t axis) : Graph1D(axis) {} - virtual void draw(RotatedDC& dc) const; - virtual int findItem(const RealPoint& pos) const; + virtual void draw(RotatedDC& dc, int current) const; + virtual int findItem(const RealPoint& pos, const RealRect& rect) const; }; //class GraphTable { diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 93b7b4e5..fae3e0a2 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -124,7 +124,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8"), _("Keywords"), _("Keywords"), _("Define extra keywords for this set")); addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 3, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set")); // addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10")) - selectPanel(ID_WINDOW_MIN + 0); // select cards panel + selectPanel(ID_WINDOW_MIN + 4); // select cards panel // loose ends tabBar->Realize(); @@ -141,6 +141,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); setSet(set); + current_panel->Layout(); } SetWindow::~SetWindow() { @@ -203,25 +204,6 @@ void SetWindow::selectPanel(int id) { // ----------------------------------------------------------------------------- : Set actions -void SetWindow::onBeforeChangeSet() { - // Make sure we don't own the set's scriptUpdater -// if (set->scriptUpdater != &scriptUpdater) { -// assert(!scriptUpdater.set); -// return; -// } - // We do own the set's scriptUpdater - // stop handling updates for the set - // do this first, so events get send, which stop worker threads -// scriptUpdater.setNullSet(); - // another window should take over the scriptUpdating -// FOR_EACH(wnd, SetWindows) { -// if (wnd != &this && wnd->getSet() == set) { -// wnd->scriptUpdater.setSet(set); -// break; -// } -// } -} - void SetWindow::onChangeSet() { // make sure there is always at least one card // some things need this diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index e7d31296..a70ecf47 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -76,8 +76,6 @@ class SetWindow : public wxFrame, public SetView { // --------------------------------------------------- : Action related protected: - /// We want to respond to set changes - virtual void onBeforeChangeSet(); /// We want to respond to set changes virtual void onChangeSet(); /// Actions that change the set diff --git a/src/gui/util.cpp b/src/gui/util.cpp index ebba915e..14af5599 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -40,6 +40,13 @@ void clearDC(DC& dc, const wxBrush& brush) { dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight()); } +void clearDC_black(DC& dc) { + #if !BITMAPS_DEFAULT_BLACK + // On windows 9x it seems that bitmaps are not black by default + clearDC(dc, *wxBLACK_BRUSH); + #endif +} + void draw_checker(RotatedDC& dc, const RealRect& rect) { dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(*wxWHITE_BRUSH); @@ -47,13 +54,13 @@ void draw_checker(RotatedDC& dc, const RealRect& rect) { dc.SetBrush(Color(235,235,235)); const double checker_size = 10; int odd = 0; - for (double y = 0 ; y < rect.size.height ; y += checker_size) { - for (double x = odd * checker_size ; x < rect.size.width ; x += checker_size * 2) { + for (double y = 0 ; y < rect.height ; y += checker_size) { + for (double x = odd * checker_size ; x < rect.width ; x += checker_size * 2) { dc.DrawRectangle(RealRect( - rect.position.x + x, - rect.position.y + y, - min(checker_size, rect.size.width - x), - min(checker_size, rect.size.height - y) + rect.x + x, + rect.y + y, + min(checker_size, rect.width - x), + min(checker_size, rect.height - y) )); } odd = 1 - odd; diff --git a/src/gui/util.hpp b/src/gui/util.hpp index d4bbc082..4ce9a806 100644 --- a/src/gui/util.hpp +++ b/src/gui/util.hpp @@ -26,7 +26,10 @@ int focused_control(const Window* window); // ----------------------------------------------------------------------------- : DC related /// Fill a DC with a single color -void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH); +void clearDC(DC& dc, const wxBrush& brush); + +/// Fill a newly allocated DC with black, if the platform doesn't do so automaticly +void clearDC_black(DC& dc); /// Draw a checkerboard pattern void draw_checker(RotatedDC& dc, const RealRect&); diff --git a/src/mse.vcproj b/src/mse.vcproj index d9dde891..9ca61f0f 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -110,7 +110,7 @@ Name="VCCustomBuildTool"/> +#include // clearDC_black DECLARE_TYPEOF_COLLECTION(SymbolPartP); @@ -29,12 +30,7 @@ MemoryDCP getTempDC(DC& dc) { Bitmap buffer(s.GetWidth(), s.GetHeight(), 1); MemoryDCP newDC(new wxMemoryDC); newDC->SelectObject(buffer); - // On windows 9x it seems that bitmaps are not black by default - #if !BITMAPS_DEFAULT_BLACK - newDC->SetPen(*wxTRANSPARENT_PEN); - newDC->SetBrush(*wxBLACK_BRUSH); - newDC->DrawRectangle(0, 0, s.GetWidth(), s.GetHeight()); - #endif + clearDC_black(*newDC); return newDC; } diff --git a/src/render/text/element.cpp b/src/render/text/element.cpp index eb00393a..310ff4df 100644 --- a/src/render/text/element.cpp +++ b/src/render/text/element.cpp @@ -20,8 +20,8 @@ void TextElements::draw(RotatedDC& dc, double scale, const RealRect& rect, const size_t end_ = min(end, e->end); if (start_ < end_) { e->draw(dc, scale, - RealRect(rect.position.x + xs[start_-start] - xs[0], rect.position.y, - xs[end_-start] - xs[start_-start], rect.size.height), + RealRect(rect.x + xs[start_-start] - xs[0], rect.y, + xs[end_-start] - xs[start_-start], rect.height), xs + start_ - start, what, start_, end_); } if (end <= e->end) return; // nothing can be after this diff --git a/src/render/text/font.cpp b/src/render/text/font.cpp index 7e3be07b..1af95b89 100644 --- a/src/render/text/font.cpp +++ b/src/render/text/font.cpp @@ -27,11 +27,11 @@ void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, co // draw shadow if (font->hasShadow()) { dc.SetTextForeground(font->shadow_color); - dc.DrawText(text.substr(start, end - start), rect.position + font->shadow_displacement); + dc.DrawText(text.substr(start, end - start), rect.position() + font->shadow_displacement); } // draw dc.SetTextForeground(font->color); - dc.DrawText(text.substr(start, end - start), rect.position); + dc.DrawText(text.substr(start, end - start), rect.position()); // } } diff --git a/src/script/context.cpp b/src/script/context.cpp index 1baadd02..56fdcd5d 100644 --- a/src/script/context.cpp +++ b/src/script/context.cpp @@ -285,14 +285,22 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP& a = toScript((String)*a + (String)*b); } else if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { a = toScript((double)*a + (double)*b); - } else { + } else if (at == SCRIPT_INT || bt == SCRIPT_INT) { a = toScript((int)*a + (int)*b); + } else { + a = toScript((String)*a + (String)*b); } break; case I_SUB: OPERATOR_DI(-); case I_MUL: OPERATOR_DI(*); case I_DIV: OPERATOR_DI(/); - case I_MOD: // fmod + case I_MOD: + if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { + a = toScript(fmod((double)*a, (double)*b)); + } else { + a = toScript((int)*a % (int)*b); + } + break; case I_AND: OPERATOR_I(&&); case I_OR: OPERATOR_I(||); case I_EQ: OPERATOR_SDI(==); diff --git a/src/script/scriptable.cpp b/src/script/scriptable.cpp index ffda5e9a..012eed54 100644 --- a/src/script/scriptable.cpp +++ b/src/script/scriptable.cpp @@ -52,6 +52,10 @@ void OptionalScript::initDependencies(Context& ctx, const Dependency& dep) const } } +Script& OptionalScript::getScript() { + if (!script) script = new_intrusive